From 537492434351568f7482658a21535fce897b6958 Mon Sep 17 00:00:00 2001 From: mego_RU Date: Fri, 23 Aug 2024 13:09:59 +0300 Subject: [PATCH] New Update 1. Fix --- .../main/controller/UpdateController.java | 33 ++++---- .../{CheckBot.java => CheckPermissions.java} | 2 +- .../java/main/core/events/HelpCommand.java | 42 +++------- src/main/java/main/core/events/JoinEvent.java | 82 ++++++------------- .../java/main/core/events/LeaveEvent.java | 5 +- .../main/core/events/ParticipantsCommand.java | 58 ++++++------- .../java/main/core/events/StartCommand.java | 10 +-- .../java/main/core/events/StopCommand.java | 4 +- src/main/java/main/giveaway/Exceptions.java | 10 +-- src/main/java/main/giveaway/Giveaway.java | 28 ++++--- src/main/java/main/giveaway/GiveawayEnds.java | 12 +-- .../main/giveaway/GiveawayUserHandler.java | 5 +- 12 files changed, 124 insertions(+), 167 deletions(-) rename src/main/java/main/core/events/{CheckBot.java => CheckPermissions.java} (98%) diff --git a/src/main/java/main/controller/UpdateController.java b/src/main/java/main/controller/UpdateController.java index a26ea73..75131d0 100644 --- a/src/main/java/main/controller/UpdateController.java +++ b/src/main/java/main/controller/UpdateController.java @@ -15,12 +15,13 @@ import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; import java.util.Objects; -import java.util.logging.Logger; @Getter @Component @@ -35,7 +36,7 @@ public class UpdateController { private final GiveawayRepositoryService giveawayRepositoryService; //LOGGER - private final static Logger LOGGER = Logger.getLogger(UpdateController.class.getName()); + private final static Logger LOGGER = LoggerFactory.getLogger(UpdateController.class.getName()); //CORE private CoreBot coreBot; @@ -64,16 +65,20 @@ public void processEvent(Object event) { } private void distributeEventsByType(Object event) { - if (event instanceof SlashCommandInteractionEvent) { - slashEvent((SlashCommandInteractionEvent) event); - } else if (event instanceof ButtonInteractionEvent) { - buttonEvent((ButtonInteractionEvent) event); - } else if (event instanceof GuildJoinEvent) { - joinEvent((GuildJoinEvent) event); - } else if (event instanceof MessageReactionAddEvent) { - reactionEvent((MessageReactionAddEvent) event); - } else if (event instanceof GuildLeaveEvent) { - leaveEvent((GuildLeaveEvent) event); + if (event instanceof SlashCommandInteractionEvent slashCommandInteractionEvent) { + LOGGER.info(slashCommandInteractionEvent.getName()); + slashEvent(slashCommandInteractionEvent); + } else if (event instanceof ButtonInteractionEvent buttonInteractionEvent) { + LOGGER.info(buttonInteractionEvent.getInteraction().getButton().getLabel()); + buttonEvent(buttonInteractionEvent); + } else if (event instanceof GuildJoinEvent guildJoinEvent) { + joinEvent(guildJoinEvent); + } else if (event instanceof MessageReactionAddEvent messageReactionAddEvent) { + LOGGER.info(messageReactionAddEvent.getMessageAuthorId()); + reactionEvent(messageReactionAddEvent); + } else if (event instanceof GuildLeaveEvent guildLeaveEvent) { + LOGGER.info(guildLeaveEvent.getGuild().getId()); + leaveEvent(guildLeaveEvent); } } @@ -136,8 +141,8 @@ private void slashEvent(@NotNull SlashCommandInteractionEvent event) { cancelCommand.cancel(event); } case "check-bot-permission" -> { - CheckBot checkBot = new CheckBot(); - checkBot.check(event); + CheckPermissions checkPermissions = new CheckPermissions(); + checkPermissions.check(event); } } } diff --git a/src/main/java/main/core/events/CheckBot.java b/src/main/java/main/core/events/CheckPermissions.java similarity index 98% rename from src/main/java/main/core/events/CheckBot.java rename to src/main/java/main/core/events/CheckPermissions.java index 4362968..ec78372 100644 --- a/src/main/java/main/core/events/CheckBot.java +++ b/src/main/java/main/core/events/CheckPermissions.java @@ -13,7 +13,7 @@ import java.util.Objects; @Service -public class CheckBot { +public class CheckPermissions { private static final JSONParsers jsonParsers = new JSONParsers(); diff --git a/src/main/java/main/core/events/HelpCommand.java b/src/main/java/main/core/events/HelpCommand.java index 919a46d..9f9cb90 100644 --- a/src/main/java/main/core/events/HelpCommand.java +++ b/src/main/java/main/core/events/HelpCommand.java @@ -1,10 +1,7 @@ package main.core.events; -import main.config.BotStart; import main.jsonparser.JSONParsers; -import main.model.entity.Settings; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; @@ -40,18 +37,18 @@ public void help(@NotNull SlashCommandInteractionEvent event) { info.setTitle("Giveaway"); info.addField("Slash Commands", String.format(""" - - %s - - %s - - %s - - %s - - %s - - %s - - %s - - %s - - %s - - %s - - %s - """, + - %s + - %s + - %s + - %s + - %s + - %s + - %s + - %s + - %s + - %s + - %s + """, helpStart, helpStop, helpScheduling, @@ -72,21 +69,6 @@ public void help(@NotNull SlashCommandInteractionEvent event) { List