Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit eaa9107

Browse files
committed
big refacto
1 parent 6bbefed commit eaa9107

File tree

10 files changed

+75
-43
lines changed

10 files changed

+75
-43
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package fr.funixgaming.funixbot.core.config;
2+
3+
import feign.okhttp.OkHttpClient;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
public class FeignConfiguration {
9+
@Bean
10+
public OkHttpClient client() {
11+
return new OkHttpClient();
12+
}
13+
}

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/FunixBot.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.funixgaming.funixbot.discord;
22

3-
import fr.funixgaming.api.client.external_api_impl.twitch.reference.dtos.responses.channel.stream.TwitchStreamDTO;
43
import fr.funixgaming.funixbot.core.exceptions.FunixBotException;
54
import fr.funixgaming.funixbot.discord.configs.BotConfig;
65
import fr.funixgaming.funixbot.discord.modules.BotEmotes;
@@ -14,7 +13,6 @@
1413
import net.dv8tion.jda.api.entities.MessageEmbed;
1514
import org.springframework.stereotype.Service;
1615

17-
1816
@Slf4j
1917
@Getter
2018
@Service
@@ -25,8 +23,6 @@ public class FunixBot {
2523
private final BotRoles botRoles;
2624
private final Guild botGuild;
2725

28-
private TwitchStreamDTO funixStreamStatus = null;
29-
3026
public FunixBot(BotConfig botConfig, JDA jda) throws Exception {
3127
try {
3228
this.jda = jda;

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/configs/BotConfig.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package fr.funixgaming.funixbot.discord.configs;
22

3-
import fr.funixgaming.funixbot.discord.events.BotGuildEvents;
4-
import fr.funixgaming.funixbot.discord.events.BotMessagesEvents;
5-
import fr.funixgaming.funixbot.discord.events.BotSlashCommandsEvents;
63
import lombok.Getter;
74
import lombok.Setter;
85
import net.dv8tion.jda.api.JDA;
@@ -46,20 +43,12 @@ public class BotConfig {
4643
private String tiktokNotifRoleId;
4744

4845
@Bean(destroyMethod = "shutdown")
49-
public JDA discordInstance(BotMessagesEvents botMessagesEvents,
50-
BotSlashCommandsEvents slashCommandsEvents,
51-
BotGuildEvents botGuildEvents) {
46+
public JDA discordInstance() {
5247
try {
5348
final JDABuilder jdaBuilder = JDABuilder.createDefault(botToken);
5449

5550
jdaBuilder.enableIntents(GatewayIntent.GUILD_MEMBERS);
5651

57-
jdaBuilder.addEventListeners(
58-
botMessagesEvents,
59-
slashCommandsEvents,
60-
botGuildEvents
61-
);
62-
6352
jdaBuilder.setActivity(Activity.of(
6453
Activity.ActivityType.WATCHING,
6554
String.format("twitch.tv/%s", streamerUsername),
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package fr.funixgaming.funixbot.discord.configs;
2+
3+
import fr.funixgaming.funixbot.discord.FunixBot;
4+
import fr.funixgaming.funixbot.discord.events.BotGuildEvents;
5+
import fr.funixgaming.funixbot.discord.events.BotMessagesEvents;
6+
import fr.funixgaming.funixbot.discord.events.BotSlashCommandsEvents;
7+
import fr.funixgaming.funixbot.discord.modules.RoleMessageHandler;
8+
import net.dv8tion.jda.api.JDA;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
@Configuration
13+
public class JdaEventsConfig {
14+
15+
@Bean
16+
public RoleMessageHandler roleMessageHandler(BotConfigGenerated botConfigGenerated,
17+
FunixBot funixBot,
18+
JDA jda) {
19+
return new RoleMessageHandler(botConfigGenerated, funixBot, jda);
20+
}
21+
22+
@Bean
23+
public BotMessagesEvents botMessagesEvents(RoleMessageHandler roleMessageHandler,
24+
JDA jda) {
25+
final BotMessagesEvents messagesEvents = new BotMessagesEvents(roleMessageHandler);
26+
27+
jda.addEventListener(messagesEvents);
28+
return messagesEvents;
29+
}
30+
31+
@Bean
32+
public BotGuildEvents botGuildEvents(FunixBot funixBot,
33+
BotConfig botConfig,
34+
JDA jda) {
35+
final BotGuildEvents botGuildEvents = new BotGuildEvents(botConfig, funixBot);
36+
37+
jda.addEventListener(botGuildEvents);
38+
return botGuildEvents;
39+
}
40+
41+
@Bean
42+
public BotSlashCommandsEvents botSlashCommandsEvents(FunixBot funixBot,
43+
JDA jda) {
44+
final BotSlashCommandsEvents botSlashCommandsEvents = new BotSlashCommandsEvents(funixBot);
45+
46+
jda.addEventListener(botSlashCommandsEvents);
47+
return botSlashCommandsEvents;
48+
}
49+
50+
}

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/events/BotGuildEvents.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
1515
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1616
import org.jetbrains.annotations.NotNull;
17-
import org.springframework.stereotype.Component;
1817

1918
import java.awt.*;
2019
import java.time.format.DateTimeFormatter;
2120

2221
@Slf4j
23-
@Component
2422
@AllArgsConstructor
2523
public class BotGuildEvents extends ListenerAdapter {
2624

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/events/BotMessagesEvents.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent;
1414
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1515
import org.jetbrains.annotations.NotNull;
16-
import org.springframework.stereotype.Component;
1716

1817
@Slf4j
19-
@Component
2018
@RequiredArgsConstructor
2119
public class BotMessagesEvents extends ListenerAdapter {
2220

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/events/BotSlashCommandsEvents.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package fr.funixgaming.funixbot.discord.events;
22

3+
import fr.funixgaming.funixbot.discord.FunixBot;
4+
import lombok.RequiredArgsConstructor;
35
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
46
import net.dv8tion.jda.api.hooks.ListenerAdapter;
57
import org.jetbrains.annotations.NotNull;
6-
import org.springframework.stereotype.Component;
78

8-
@Component
9+
@RequiredArgsConstructor
910
public class BotSlashCommandsEvents extends ListenerAdapter {
1011

12+
private final FunixBot funixBot;
13+
1114
@Override
1215
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
1316
}

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/modules/RoleMessageHandler.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,27 @@
33
import fr.funixgaming.funixbot.core.exceptions.FunixBotException;
44
import fr.funixgaming.funixbot.core.utils.BotColors;
55
import fr.funixgaming.funixbot.discord.FunixBot;
6-
import fr.funixgaming.funixbot.discord.configs.BotConfig;
76
import fr.funixgaming.funixbot.discord.configs.BotConfigGenerated;
87
import lombok.extern.slf4j.Slf4j;
98
import net.dv8tion.jda.api.EmbedBuilder;
109
import net.dv8tion.jda.api.JDA;
1110
import net.dv8tion.jda.api.entities.*;
1211
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
1312
import net.dv8tion.jda.api.requests.ErrorResponse;
14-
import org.springframework.stereotype.Component;
1513

1614
@Slf4j
17-
@Component
1815
public class RoleMessageHandler {
1916

2017
private final BotConfigGenerated botConfigGenerated;
21-
private final BotConfig botConfig;
22-
private final JDA jda;
2318
private final FunixBot funixBot;
19+
private final JDA jda;
2420

2521
public RoleMessageHandler(BotConfigGenerated botConfigGenerated,
26-
BotConfig botConfig,
27-
JDA jda,
28-
FunixBot funixBot) {
22+
FunixBot funixBot,
23+
JDA jda) {
2924
this.botConfigGenerated = botConfigGenerated;
30-
this.botConfig = botConfig;
31-
this.jda = jda;
3225
this.funixBot = funixBot;
26+
this.jda = jda;
3327

3428
try {
3529
setMessageRoleChoice();
@@ -39,7 +33,7 @@ public RoleMessageHandler(BotConfigGenerated botConfigGenerated,
3933
}
4034

4135
private void setMessageRoleChoice() throws FunixBotException {
42-
final TextChannel rolesChannel = jda.getTextChannelById(botConfig.getRolesChannelId());
36+
final TextChannel rolesChannel = jda.getTextChannelById(funixBot.getBotConfig().getRolesChannelId());
4337

4438
if (rolesChannel == null) {
4539
throw new FunixBotException("Le channel pour le choix des rôles n'existe pas.");

FunixBot-Discord/src/main/java/fr/funixgaming/funixbot/discord/modules/TwitchStreamNotifications.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ private void sendNotification(@NonNull final TwitchStreamDTO stream) {
5959
String gameBoxArtUrl = null;
6060

6161
if (game != null) {
62-
gameBoxArtUrl = game.getBoxArtUrl();
63-
gameBoxArtUrl = gameBoxArtUrl.replace("{width}", "600");
64-
gameBoxArtUrl = gameBoxArtUrl.replace("{height}", "840");
62+
gameBoxArtUrl = game.getBoxArtUrl(600, 840);
6563
}
6664

6765
final EmbedBuilder embedBuilder = new EmbedBuilder()

FunixBot-Twitch/src/test/java/fr/funixgaming/funixbot/twitch/modules/AutoMessageTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package fr.funixgaming.funixbot.twitch.modules;
22

3-
import org.junit.jupiter.api.Test;
4-
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.boot.test.context.SpringBootTest;
6-
73
import static org.junit.jupiter.api.Assertions.assertEquals;
84

9-
@SpringBootTest
105
public class AutoMessageTest {
116

12-
@Autowired
137
private AutoMessages autoMessages;
148

15-
@Test
169
public void testGettingJson() {
1710
System.out.println(autoMessages.getMessages().length + " messages");
1811
assertEquals(4, autoMessages.getMessages().length);

0 commit comments

Comments
 (0)