|
1 | 1 | package net.javadiscord.javabot; |
2 | 2 |
|
3 | 3 | import java.nio.file.Path; |
| 4 | +import java.util.Collection; |
4 | 5 | import java.util.concurrent.Executors; |
5 | 6 | import java.util.concurrent.ScheduledExecutorService; |
6 | 7 |
|
7 | 8 | import javax.security.auth.login.LoginException; |
8 | 9 | import javax.sql.DataSource; |
9 | 10 |
|
| 11 | +import org.springframework.context.ApplicationContext; |
10 | 12 | import org.springframework.context.annotation.Bean; |
11 | 13 | import org.springframework.context.annotation.Configuration; |
12 | 14 |
|
|
24 | 26 | import net.dv8tion.jda.api.utils.ChunkingFilter; |
25 | 27 | import net.dv8tion.jda.api.utils.MemberCachePolicy; |
26 | 28 | import net.dv8tion.jda.api.utils.cache.CacheFlag; |
| 29 | +import net.javadiscord.javabot.annotations.PreRegisteredListener; |
27 | 30 | import net.javadiscord.javabot.data.config.BotConfig; |
28 | 31 | import net.javadiscord.javabot.data.config.SystemsConfig; |
29 | 32 | import net.javadiscord.javabot.data.h2db.DbHelper; |
30 | | -import net.javadiscord.javabot.listener.StateListener; |
31 | 33 | import net.javadiscord.javabot.tasks.PresenceUpdater; |
32 | 34 |
|
33 | 35 | /** |
@@ -64,19 +66,20 @@ public SystemsConfig systemsConfig(BotConfig botConfig) { |
64 | 66 | /** |
65 | 67 | * Initializes the {@link JDA} instances. |
66 | 68 | * @param botConfig the main configuration of the bot |
67 | | - * @param stateListener The {@link StateListener} which is listening for JDA lifecycle events and needs to be added before JDA is fully initialized |
| 69 | + * @param ctx the Spring application context used for obtaining all listeners |
68 | 70 | * @return the initialized {@link JDA} object |
69 | 71 | * @throws LoginException if the token is invalid |
70 | 72 | */ |
71 | 73 | @Bean |
72 | | - public JDA jda(BotConfig botConfig, StateListener stateListener) throws LoginException { |
| 74 | + public JDA jda(BotConfig botConfig, ApplicationContext ctx) throws LoginException { |
| 75 | + Collection<Object> listeners = ctx.getBeansWithAnnotation(PreRegisteredListener.class).values(); |
73 | 76 | return JDABuilder.createDefault(botConfig.getSystems().getJdaBotToken()) |
74 | 77 | .setStatus(OnlineStatus.DO_NOT_DISTURB) |
75 | 78 | .setChunkingFilter(ChunkingFilter.ALL) |
76 | 79 | .setMemberCachePolicy(MemberCachePolicy.ALL) |
77 | 80 | .enableCache(CacheFlag.ACTIVITY) |
78 | 81 | .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES, GatewayIntent.MESSAGE_CONTENT) |
79 | | - .addEventListeners(stateListener) |
| 82 | + .addEventListeners(listeners.toArray()) |
80 | 83 | .build(); |
81 | 84 | } |
82 | 85 |
|
|
0 commit comments