diff --git a/application/src/main/java/org/togetherjava/tjbot/config/CoolMessagesBoardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/CoolMessagesBoardConfig.java index 22f7157641..bf2d1b57be 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/CoolMessagesBoardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/CoolMessagesBoardConfig.java @@ -12,13 +12,15 @@ @JsonRootName("coolMessagesConfig") public record CoolMessagesBoardConfig( @JsonProperty(value = "minimumReactions", required = true) int minimumReactions, - @JsonProperty(value = "boardChannelPattern", required = true) String boardChannelPattern) { + @JsonProperty(value = "boardChannelPattern", required = true) String boardChannelPattern, + @JsonProperty(value = "reactionEmoji", required = true) String reactionEmoji) { /** * Creates a CoolMessagesBoardConfig. * * @param minimumReactions the minimum amount of reactions * @param boardChannelPattern the pattern for the board channel + * @param reactionEmoji the emoji with which users should react to */ public CoolMessagesBoardConfig { Objects.requireNonNull(boardChannelPattern); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/CoolMessagesBoardManager.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/CoolMessagesBoardManager.java index 949ad838c7..90c0f17dce 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/CoolMessagesBoardManager.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/CoolMessagesBoardManager.java @@ -29,12 +29,13 @@ public final class CoolMessagesBoardManager extends MessageReceiverAdapter { private static final Logger logger = LoggerFactory.getLogger(CoolMessagesBoardManager.class); - private static final Emoji REACT_EMOJI = Emoji.fromUnicode("🌟"); + private Emoji coolEmoji; private final Predicate boardChannelNamePredicate; private final CoolMessagesBoardConfig config; public CoolMessagesBoardManager(Config config) { this.config = config.getCoolMessagesConfig(); + this.coolEmoji = Emoji.fromUnicode(this.config.reactionEmoji()); boardChannelNamePredicate = Pattern.compile(this.config.boardChannelPattern()).asMatchPredicate(); @@ -44,7 +45,7 @@ public CoolMessagesBoardManager(Config config) { public void onMessageReactionAdd(MessageReactionAddEvent event) { final MessageReaction messageReaction = event.getReaction(); int originalReactionsCount = messageReaction.hasCount() ? messageReaction.getCount() : 0; - boolean isCoolEmoji = messageReaction.getEmoji().getName().equals(REACT_EMOJI.getName()); + boolean isCoolEmoji = messageReaction.getEmoji().equals(coolEmoji); long guildId = event.getGuild().getIdLong(); Optional boardChannel = getBoardChannel(event.getJDA(), guildId); @@ -64,7 +65,7 @@ public void onMessageReactionAdd(MessageReactionAddEvent event) { final int newReactionsCount = originalReactionsCount + 1; if (isCoolEmoji && newReactionsCount >= config.minimumReactions()) { event.retrieveMessage().queue(message -> { - message.addReaction(REACT_EMOJI).queue(); + message.addReaction(coolEmoji).queue(); insertCoolMessage(boardChannel.get(), message); }, e -> logger.warn("Tried to retrieve cool message but got: {}", e.getMessage())); @@ -123,8 +124,8 @@ private static MessageEmbed createQuoteEmbed(Message message) { /** * Checks a {@link MessageReaction} to see if the bot has reacted to it. */ - private static boolean hasBotReacted(JDA jda, MessageReaction messageReaction) { - if (!REACT_EMOJI.equals(messageReaction.getEmoji())) { + private boolean hasBotReacted(JDA jda, MessageReaction messageReaction) { + if (!coolEmoji.equals(messageReaction.getEmoji())) { return false; }