diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index 80f9693..2c12c47 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -20,7 +20,7 @@ import wtf.beatrice.hidekobot.runnables.HeartBeatTask; import wtf.beatrice.hidekobot.runnables.RandomOrgSeedTask; import wtf.beatrice.hidekobot.runnables.StatusUpdateTask; import wtf.beatrice.hidekobot.services.DatabaseService; -import wtf.beatrice.hidekobot.util.CommandUtil; +import wtf.beatrice.hidekobot.services.CommandService; import wtf.beatrice.hidekobot.util.FormatUtil; import wtf.beatrice.hidekobot.util.RandomUtil; import wtf.beatrice.hidekobot.util.Services; @@ -70,10 +70,10 @@ public class HidekoBot ConfigurableApplicationContext context = SpringApplication.run(HidekoBot.class, args); - CommandUtil commandUtil = context.getBean(CommandUtil.class); + CommandService commandService = context.getBean(CommandService.class); DatabaseService databaseService = context.getBean(DatabaseService.class); Services services = new wtf.beatrice.hidekobot.util.Services( - commandUtil, + commandService, databaseService ); Cache.setServices(services); @@ -206,7 +206,7 @@ public class HidekoBot final boolean finalForceUpdateCommands = forceUpdateCommands; try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) { - executor.schedule(() -> commandUtil.updateSlashCommands(finalForceUpdateCommands), + executor.schedule(() -> commandService.updateSlashCommands(finalForceUpdateCommands), 1, TimeUnit.SECONDS); } @@ -215,7 +215,7 @@ public class HidekoBot // start scheduled runnables ScheduledExecutorService scheduler = Cache.getTaskScheduler(); - ExpiredMessageTask expiredMessageTask = new ExpiredMessageTask(services.databaseService(), services.commandUtil()); + ExpiredMessageTask expiredMessageTask = new ExpiredMessageTask(services.databaseService(), services.commandService()); scheduler.scheduleAtFixedRate(expiredMessageTask, 5L, 5L, TimeUnit.SECONDS); //every 5 seconds HeartBeatTask heartBeatTask = new HeartBeatTask(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java index bbd8fd4..bcc7857 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java @@ -259,7 +259,7 @@ public class Trivia } // todo: we shouldn't use this method, since it messes with the database... look at coin reflip - Cache.getServices().commandUtil().disableExpired(event.getMessageId()); + Cache.getServices().commandService().disableExpired(event.getMessageId()); SelectOption pickedOption = event.getInteraction().getSelectedOptions().get(0); String categoryName = pickedOption.getLabel(); @@ -293,7 +293,7 @@ public class Trivia TriviaTask triviaTask = new TriviaTask(author, channel, category, - Cache.getServices().databaseService(), Cache.getServices().commandUtil()); + Cache.getServices().databaseService(), Cache.getServices().commandService()); ScheduledFuture future = Cache.getTaskScheduler().scheduleAtFixedRate(triviaTask, 0, diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java index 37343ec..0f2e97a 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java @@ -8,18 +8,18 @@ import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.CoinFlip; import wtf.beatrice.hidekobot.commands.base.Trivia; import wtf.beatrice.hidekobot.commands.base.UrbanDictionary; -import wtf.beatrice.hidekobot.util.CommandUtil; +import wtf.beatrice.hidekobot.services.CommandService; @Component public class ButtonInteractionListener extends ListenerAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(ButtonInteractionListener.class); - private final CommandUtil commandUtil; + private final CommandService commandService; - public ButtonInteractionListener(CommandUtil commandUtil) + public ButtonInteractionListener(CommandService commandService) { - this.commandUtil = commandUtil; + this.commandService = commandService; } @Override @@ -33,7 +33,7 @@ public class ButtonInteractionListener extends ListenerAdapter case "coinflip_reflip" -> CoinFlip.buttonReFlip(event); // generic dismiss button - case "generic_dismiss" -> commandUtil.delete(event); + case "generic_dismiss" -> commandService.deleteUserLinkedMessage(event); // urban dictionary navigation case "urban_nextpage" -> UrbanDictionary.changePage(event, UrbanDictionary.ChangeType.NEXT); diff --git a/src/main/java/wtf/beatrice/hidekobot/runnables/ExpiredMessageTask.java b/src/main/java/wtf/beatrice/hidekobot/runnables/ExpiredMessageTask.java index 0fd8275..f933773 100644 --- a/src/main/java/wtf/beatrice/hidekobot/runnables/ExpiredMessageTask.java +++ b/src/main/java/wtf/beatrice/hidekobot/runnables/ExpiredMessageTask.java @@ -4,7 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.services.DatabaseService; -import wtf.beatrice.hidekobot.util.CommandUtil; +import wtf.beatrice.hidekobot.services.CommandService; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -14,17 +14,17 @@ public class ExpiredMessageTask implements Runnable { private final DatabaseService databaseService; - private final CommandUtil commandUtil; + private final CommandService commandService; private final DateTimeFormatter formatter; private static final Logger LOGGER = LoggerFactory.getLogger(ExpiredMessageTask.class); public ExpiredMessageTask(DatabaseService databaseService, - CommandUtil commandUtil) + CommandService commandService) { this.databaseService = databaseService; - this.commandUtil = commandUtil; + this.commandService = commandService; String format = Cache.getExpiryTimestampFormat(); formatter = DateTimeFormatter.ofPattern(format); } @@ -58,7 +58,7 @@ public class ExpiredMessageTask implements Runnable if (now.isAfter(expiryDate)) { if (Cache.isVerbose()) LOGGER.info("expired: {}", messageId); - commandUtil.disableExpired(messageId); + commandService.disableExpired(messageId); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java b/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java index 00d67f6..20aa790 100644 --- a/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java +++ b/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java @@ -14,7 +14,7 @@ import wtf.beatrice.hidekobot.objects.fun.TriviaCategory; import wtf.beatrice.hidekobot.objects.fun.TriviaQuestion; import wtf.beatrice.hidekobot.objects.fun.TriviaScore; import wtf.beatrice.hidekobot.services.DatabaseService; -import wtf.beatrice.hidekobot.util.CommandUtil; +import wtf.beatrice.hidekobot.services.CommandService; import java.util.*; import java.util.concurrent.ScheduledFuture; @@ -23,7 +23,7 @@ public class TriviaTask implements Runnable { private final DatabaseService databaseService; - private final CommandUtil commandUtil; + private final CommandService commandService; private final User author; private final MessageChannel channel; @@ -42,13 +42,13 @@ public class TriviaTask implements Runnable MessageChannel channel, TriviaCategory category, DatabaseService databaseService, - CommandUtil commandUtil) + CommandService commandService) { this.author = author; this.channel = channel; this.category = category; this.databaseService = databaseService; - this.commandUtil = commandUtil; + this.commandService = commandService; triviaJson = Trivia.fetchJson(Trivia.getTriviaLink(category.categoryId())); questions = Trivia.parseQuestions(triviaJson); //todo: null check, rate limiting... @@ -66,7 +66,7 @@ public class TriviaTask implements Runnable if (previousMessage != null) { // todo: we shouldn't use this method, since it messes with the database... look at coin reflip - commandUtil.disableExpired(previousMessage.getId()); + commandService.disableExpired(previousMessage.getId()); String previousCorrectAnswer = questions.get(iteration - 1).correctAnswer(); diff --git a/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java b/src/main/java/wtf/beatrice/hidekobot/services/CommandService.java similarity index 97% rename from src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java rename to src/main/java/wtf/beatrice/hidekobot/services/CommandService.java index 9cd66f3..d0f8735 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/services/CommandService.java @@ -1,4 +1,4 @@ -package wtf.beatrice.hidekobot.util; +package wtf.beatrice.hidekobot.services; import net.dv8tion.jda.api.JDA; @@ -19,20 +19,19 @@ import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.objects.commands.SlashCommand; -import wtf.beatrice.hidekobot.services.DatabaseService; import java.util.ArrayList; import java.util.List; @Component -public class CommandUtil +public class CommandService { - private static final Logger LOGGER = LoggerFactory.getLogger(CommandUtil.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CommandService.class); private final DatabaseService databaseService; - public CommandUtil(@Autowired DatabaseService databaseService) + public CommandService(@Autowired DatabaseService databaseService) { this.databaseService = databaseService; } @@ -43,7 +42,7 @@ public class CommandUtil * * @param event the button interaction event. */ - public void delete(ButtonInteractionEvent event) + public void deleteUserLinkedMessage(ButtonInteractionEvent event) { // check if the user interacting is the same one who ran the command if (!databaseService.isUserTrackedFor(event.getUser().getId(), event.getMessageId())) diff --git a/src/main/java/wtf/beatrice/hidekobot/util/Services.java b/src/main/java/wtf/beatrice/hidekobot/util/Services.java index d5cd0f7..484a496 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/Services.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/Services.java @@ -1,7 +1,8 @@ package wtf.beatrice.hidekobot.util; +import wtf.beatrice.hidekobot.services.CommandService; import wtf.beatrice.hidekobot.services.DatabaseService; -public record Services(CommandUtil commandUtil, DatabaseService databaseService) +public record Services(CommandService commandService, DatabaseService databaseService) { }