File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
main/kotlin/io/github/freya022/botcommands
test/kotlin/io/github/freya022/botcommands/test/services Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.hooks.IEventManager
1212import net.dv8tion.jda.api.requests.GatewayIntent
1313import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder
1414import net.dv8tion.jda.api.sharding.ShardManager
15+ import net.dv8tion.jda.api.utils.cache.CacheFlag
1516import java.util.*
1617
1718/* *
@@ -51,6 +52,15 @@ abstract class JDAService {
5152 */
5253 abstract val intents: Set <GatewayIntent >
5354
55+ /* *
56+ * The cache flags used by your bot,
57+ * must at least be a subset of the cache flags your bot will use.
58+ *
59+ * To make sure JDA uses these flags,
60+ * you can pass these to [JDABuilder.enableCache] / [DefaultShardManagerBuilder.enableCache].
61+ */
62+ abstract val cacheFlags: Set <CacheFlag >
63+
5464 /* *
5565 * Creates a [JDA] or [ShardManager] instance.
5666 *
Original file line number Diff line number Diff line change @@ -28,6 +28,19 @@ internal object JDAServiceMismatchChecker {
2828 """ .trimIndent()
2929 }
3030 }
31+
32+ val jdaCacheFlags = event.jda.cacheFlags
33+ val jdaServiceCacheFlags = jdaService.cacheFlags
34+ if (jdaCacheFlags.containsAll(jdaServiceCacheFlags)) {
35+ logger.warn {
36+ """
37+ The cache flags given in JDAService should at least be a subset of the JDA cache flags!
38+ JDA intents: $jdaIntents
39+ JDAService intents: $jdaServiceIntents
40+ Hint: you should pass ${JDAService ::cacheFlags.reference} to your builder
41+ """ .trimIndent()
42+ }
43+ }
3144 }
3245 }
3346}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package io.github.freya022.botcommands.test.services
33import io.github.freya022.botcommands.api.core.JDAService
44import io.github.freya022.botcommands.api.core.events.BReadyEvent
55import io.github.freya022.botcommands.api.core.service.annotations.BService
6+ import io.github.freya022.botcommands.api.core.utils.enumSetOf
67import io.github.freya022.botcommands.test.config.Config
78import net.dv8tion.jda.api.entities.Activity
89import net.dv8tion.jda.api.hooks.IEventManager
@@ -16,9 +17,12 @@ class Bot(private val config: Config) : JDAService() {
1617 override val intents: Set <GatewayIntent > =
1718 defaultIntents + GatewayIntent .GUILD_MEMBERS + GatewayIntent .MESSAGE_CONTENT
1819
20+ override val cacheFlags: Set <CacheFlag >
21+ get() = enumSetOf(CacheFlag .FORUM_TAGS , CacheFlag .VOICE_STATE )
22+
1923 override fun createJDA (event : BReadyEvent , eventManager : IEventManager ) {
2024 DefaultShardManagerBuilder .createLight(config.token, intents).apply {
21- enableCache(CacheFlag . FORUM_TAGS , CacheFlag . VOICE_STATE )
25+ enableCache(cacheFlags )
2226 setMemberCachePolicy(MemberCachePolicy .VOICE )
2327 setActivityProvider { Activity .playing(" coroutines go brrr #$it " ) }
2428 setEventManagerProvider { eventManager }
You can’t perform that action at this time.
0 commit comments