|
3 | 3 | import io.samdev.boostsync.bot.boost.BoostManager; |
4 | 4 | import io.samdev.boostsync.bot.command.CommandListener; |
5 | 5 | import io.samdev.boostsync.common.database.BoostSyncDatabase; |
6 | | -import net.dv8tion.jda.api.AccountType; |
7 | 6 | import net.dv8tion.jda.api.JDA; |
8 | 7 | import net.dv8tion.jda.api.JDABuilder; |
9 | 8 | import net.dv8tion.jda.api.entities.Guild; |
| 9 | +import net.dv8tion.jda.api.requests.GatewayIntent; |
| 10 | +import net.dv8tion.jda.api.utils.cache.CacheFlag; |
10 | 11 |
|
11 | 12 | import static io.samdev.boostsync.bot.util.Logging.info; |
12 | 13 | import static io.samdev.boostsync.bot.util.Logging.severe; |
13 | 14 |
|
14 | | -public class BoostSync |
15 | | -{ |
16 | | - public static void main(String[] args) |
17 | | - { |
18 | | - new BoostSync(); |
19 | | - } |
20 | | - |
21 | | - private BoostSync() |
22 | | - { |
23 | | - if (!loadConfig()) |
24 | | - { |
25 | | - severe("Unable to load config"); |
26 | | - return; |
27 | | - } |
28 | | - |
29 | | - if (!connectToDatabase()) |
30 | | - { |
31 | | - severe("Unable to connect to database"); |
32 | | - return; |
33 | | - } |
34 | | - |
35 | | - if (!connectToDiscord()) |
36 | | - { |
37 | | - severe("Unable to connect to Discord"); |
38 | | - } |
39 | | - |
40 | | - new CommandListener(this); |
41 | | - boostManager = new BoostManager(this); |
42 | | - } |
43 | | - |
44 | | - private BoostManager boostManager; |
45 | | - |
46 | | - public BoostManager getBoostManager() |
47 | | - { |
48 | | - return boostManager; |
49 | | - } |
50 | | - |
51 | | - private BotConfig config; |
52 | | - |
53 | | - public BotConfig getConfig() |
54 | | - { |
55 | | - return config; |
56 | | - } |
57 | | - |
58 | | - private boolean loadConfig() |
59 | | - { |
60 | | - config = new BotConfig(this); |
61 | | - return config.init(); |
62 | | - } |
63 | | - |
64 | | - private BoostSyncDatabase database; |
65 | | - |
66 | | - public BoostSyncDatabase getDatabase() |
67 | | - { |
68 | | - return database; |
69 | | - } |
70 | | - |
71 | | - private boolean connectToDatabase() |
72 | | - { |
73 | | - try |
74 | | - { |
75 | | - database = new BoostSyncDatabase(config.getDatabaseCredentials()); |
76 | | - return true; |
77 | | - } |
78 | | - catch (Exception ex) |
79 | | - { |
80 | | - ex.printStackTrace(); |
81 | | - return false; |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - private JDA jda; |
86 | | - |
87 | | - public JDA getJda() |
88 | | - { |
89 | | - return jda; |
90 | | - } |
91 | | - |
92 | | - private Guild guild; |
93 | | - |
94 | | - public Guild getGuild() |
95 | | - { |
96 | | - return guild; |
97 | | - } |
98 | | - |
99 | | - private boolean ready = false; |
100 | | - |
101 | | - private boolean connectToDiscord() |
102 | | - { |
103 | | - try |
104 | | - { |
105 | | - jda = new JDABuilder(AccountType.BOT) |
106 | | - .setToken(config.getBotToken()) |
107 | | - .build(); |
108 | | - |
109 | | - jda.awaitReady(); |
110 | | - |
111 | | - info("Connected to bot " + jda.getSelfUser().getAsTag()); |
112 | | - guild = jda.getGuildById(config.getGuildId()); |
113 | | - |
114 | | - return true; |
115 | | - } |
116 | | - catch (Exception ex) |
117 | | - { |
118 | | - ex.printStackTrace(); |
119 | | - return false; |
120 | | - } |
121 | | - } |
| 15 | +public class BoostSync { |
| 16 | + public static void main(String[] args) { |
| 17 | + new BoostSync(); |
| 18 | + } |
| 19 | + |
| 20 | + private BoostSync() { |
| 21 | + if (!loadConfig()) { |
| 22 | + severe("Unable to load config"); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + if (!connectToDatabase()) { |
| 27 | + severe("Unable to connect to database"); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + if (!connectToDiscord()) { |
| 32 | + severe("Unable to connect to Discord"); |
| 33 | + } |
| 34 | + |
| 35 | + new CommandListener(this); |
| 36 | + boostManager = new BoostManager(this); |
| 37 | + } |
| 38 | + |
| 39 | + private BoostManager boostManager; |
| 40 | + |
| 41 | + public BoostManager getBoostManager() { |
| 42 | + return boostManager; |
| 43 | + } |
| 44 | + |
| 45 | + private BotConfig config; |
| 46 | + |
| 47 | + public BotConfig getConfig() { |
| 48 | + return config; |
| 49 | + } |
| 50 | + |
| 51 | + private boolean loadConfig() { |
| 52 | + config = new BotConfig(this); |
| 53 | + return config.init(); |
| 54 | + } |
| 55 | + |
| 56 | + private BoostSyncDatabase database; |
| 57 | + |
| 58 | + public BoostSyncDatabase getDatabase() { |
| 59 | + return database; |
| 60 | + } |
| 61 | + |
| 62 | + private boolean connectToDatabase() { |
| 63 | + try { |
| 64 | + database = new BoostSyncDatabase(config.getDatabaseCredentials()); |
| 65 | + return true; |
| 66 | + } catch (Exception ex) { |
| 67 | + ex.printStackTrace(); |
| 68 | + return false; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private JDA jda; |
| 73 | + |
| 74 | + public JDA getJda() { |
| 75 | + return jda; |
| 76 | + } |
| 77 | + |
| 78 | + private Guild guild; |
| 79 | + |
| 80 | + public Guild getGuild() { |
| 81 | + return guild; |
| 82 | + } |
| 83 | + |
| 84 | + private boolean ready = false; |
| 85 | + |
| 86 | + private boolean connectToDiscord() { |
| 87 | + try { |
| 88 | + jda = JDABuilder.create( |
| 89 | + GatewayIntent.GUILD_MEMBERS, |
| 90 | + GatewayIntent.GUILD_MESSAGES, |
| 91 | + GatewayIntent.MESSAGE_CONTENT |
| 92 | + ) |
| 93 | + .disableCache(CacheFlag.ACTIVITY, CacheFlag.EMOJI, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS, CacheFlag.STICKER, CacheFlag.VOICE_STATE) |
| 94 | + .setToken(config.getBotToken()) |
| 95 | + .build(); |
| 96 | + |
| 97 | + jda.awaitReady(); |
| 98 | + |
| 99 | + info("Connected to bot " + jda.getSelfUser().getAsTag()); |
| 100 | + guild = jda.getGuildById(config.getGuildId()); |
| 101 | + |
| 102 | + return true; |
| 103 | + } catch (Exception ex) { |
| 104 | + ex.printStackTrace(); |
| 105 | + return false; |
| 106 | + } |
| 107 | + } |
| 108 | + |
122 | 109 | } |
0 commit comments