5
5
*/
6
6
package dev.qixils.quasicord
7
7
8
+ import dev.minn.jda.ktx.events.listener
9
+ import dev.minn.jda.ktx.jdabuilder.default
8
10
import dev.qixils.quasicord.commands.GuildConfigCommand
9
11
import dev.qixils.quasicord.commands.UserConfigCommand
10
12
import dev.qixils.quasicord.db.DatabaseManager
@@ -13,11 +15,9 @@ import dev.qixils.quasicord.locale.LocaleProvider
13
15
import dev.qixils.quasicord.locale.TranslationProvider
14
16
import dev.qixils.quasicord.registry.core.RegistryRegistry
15
17
import net.dv8tion.jda.api.JDA
16
- import net.dv8tion.jda.api.JDABuilder
17
18
import net.dv8tion.jda.api.entities.Activity
18
19
import net.dv8tion.jda.api.events.Event
19
20
import net.dv8tion.jda.api.hooks.AnnotatedEventManager
20
- import net.dv8tion.jda.api.hooks.SubscribeEvent
21
21
import net.dv8tion.jda.api.requests.GatewayIntent
22
22
import net.dv8tion.jda.api.utils.MemberCachePolicy
23
23
import net.dv8tion.jda.api.utils.cache.CacheFlag
@@ -147,7 +147,7 @@ open class Quasicord(
147
147
148
148
// load database and locale provider
149
149
databaseManager = DatabaseManager (namespace, config.environment)
150
- localeProvider = LocaleProvider (defaultLocale, databaseManager)
150
+ localeProvider = LocaleProvider .create (defaultLocale, databaseManager)
151
151
LocaleProvider .instance = localeProvider
152
152
153
153
// initialize JDA and relevant data
@@ -164,39 +164,35 @@ open class Quasicord(
164
164
}
165
165
166
166
protected open fun initJDA (activity : Activity ? ): JDA {
167
- val builder = JDABuilder .createDefault(config.token)
168
- .disableIntents(
169
- GatewayIntent .DIRECT_MESSAGE_TYPING ,
170
- GatewayIntent .GUILD_MESSAGE_TYPING , // GatewayIntent.GUILD_INTEGRATIONS, // unused, apparently
171
- GatewayIntent .GUILD_WEBHOOKS ,
172
- GatewayIntent .GUILD_INVITES ,
173
- GatewayIntent .GUILD_VOICE_STATES
174
- )
175
- .enableIntents(GatewayIntent .GUILD_MEMBERS ) // TODO:
176
- // 1. register cogs before initJDA() is called
177
- // 2. implement getRequiredIntents() in Cog
178
- // 3. use that result here to compute minimum required intents
179
- // 4. late-loaded cogs, if any/ever, can decline when their required intents weren't met at startup
180
- // 5. except wait, cogs need jda to be constructed (and probably should), that's a problem
181
- .enableIntents(GatewayIntent .GUILD_MESSAGES )
182
- .enableIntents(GatewayIntent .MESSAGE_CONTENT )
183
- .setMemberCachePolicy(MemberCachePolicy .ALL )
184
- .setEventManager(AnnotatedEventManager ())
185
- .disableCache(CacheFlag .ACTIVITY , CacheFlag .VOICE_STATE )
186
- if (activity != null ) builder.setActivity(activity)
187
- MessageRequest .setDefaultMentions(emptySet())
188
- val jda = builder.build()
167
+ val jda = default(config.token, enableCoroutines = true ) {
168
+ disableIntents(
169
+ GatewayIntent .DIRECT_MESSAGE_TYPING ,
170
+ GatewayIntent .GUILD_MESSAGE_TYPING , // GatewayIntent.GUILD_INTEGRATIONS, // unused, apparently
171
+ GatewayIntent .GUILD_WEBHOOKS ,
172
+ GatewayIntent .GUILD_INVITES ,
173
+ GatewayIntent .GUILD_VOICE_STATES
174
+ )
175
+ // TODO:
176
+ // 1. register cogs before initJDA() is called
177
+ // 2. implement getRequiredIntents() in Cog
178
+ // 3. use that result here to compute minimum required intents
179
+ // 4. late-loaded cogs, if any/ever, can decline when their required intents weren't met at startup
180
+ // 5. except wait, cogs need jda to be constructed (and probably should), that's a problem
181
+ enableIntents(GatewayIntent .GUILD_MEMBERS )
182
+ enableIntents(GatewayIntent .GUILD_MESSAGES )
183
+ enableIntents(GatewayIntent .MESSAGE_CONTENT )
184
+ setMemberCachePolicy(MemberCachePolicy .ALL )
185
+ setEventManager(AnnotatedEventManager ())
186
+ disableCache(CacheFlag .ACTIVITY , CacheFlag .VOICE_STATE )
187
+ if (activity != null ) setActivity(activity)
188
+ MessageRequest .setDefaultMentions(emptySet())
189
+ }
189
190
jda.setRequiredScopes(" applications.commands" )
190
191
jda.addEventListener(tempListenerExecutor)
191
- jda.addEventListener(object : Any () {
192
- @SubscribeEvent
193
- fun on (event : Event ? ) {
194
- eventDispatcher.dispatch(event!! )
195
- }
196
- })
192
+ jda.listener<Event > { eventDispatcher.dispatch(it) }
197
193
try {
198
194
jda.awaitReady()
199
- } catch (ignored : InterruptedException ) {
195
+ } catch (_ : InterruptedException ) {
200
196
}
201
197
return jda
202
198
}
@@ -208,7 +204,7 @@ open class Quasicord(
208
204
*/
209
205
// we don't expose the raw executor in a getter because objects could abuse the #onEvent method
210
206
fun register (listener : TemporaryListener <* >) {
211
- tempListenerExecutor.register(Objects .requireNonNull( listener, " listener cannot be null " ) )
207
+ tempListenerExecutor.register(listener)
212
208
}
213
209
214
210
/* *
0 commit comments