diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index d5a36424f2..56dc33ce09 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -48,7 +48,7 @@ public final class Config { private final RSSFeedsConfig rssFeedsConfig; private final String selectRolesChannelPattern; private final String memberCountCategoryPattern; - private final QuoteBoardConfig coolMessagesConfig; + private final QuoteBoardConfig quoteMessagesConfig; @SuppressWarnings("ConstructorWithTooManyParameters") @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) @@ -102,8 +102,8 @@ private Config(@JsonProperty(value = "token", required = true) String token, @JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig, @JsonProperty(value = "selectRolesChannelPattern", required = true) String selectRolesChannelPattern, - @JsonProperty(value = "coolMessagesConfig", - required = true) QuoteBoardConfig coolMessagesConfig) { + @JsonProperty(value = "quoteMessagesConfig", + required = true) QuoteBoardConfig quoteMessagesConfig) { this.token = Objects.requireNonNull(token); this.githubApiKey = Objects.requireNonNull(githubApiKey); this.databasePath = Objects.requireNonNull(databasePath); @@ -138,7 +138,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig); this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig); this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern); - this.coolMessagesConfig = Objects.requireNonNull(coolMessagesConfig); + this.quoteMessagesConfig = Objects.requireNonNull(quoteMessagesConfig); } /** @@ -433,12 +433,13 @@ public String getSelectRolesChannelPattern() { } /** - * The configuration of the cool messages config. + * The configuration of the cool messages config. The configuration of the quote board feature. + * Quotes user selected messages * * @return configuration of cool messages config */ public QuoteBoardConfig getCoolMessagesConfig() { - return coolMessagesConfig; + return quoteMessagesConfig; } /** diff --git a/application/src/main/java/org/togetherjava/tjbot/config/QuoteBoardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/QuoteBoardConfig.java index d88420c8c1..4a3ada6aa1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/QuoteBoardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/QuoteBoardConfig.java @@ -3,10 +3,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import org.togetherjava.tjbot.features.basic.QuoteBoardForwarder; + import java.util.Objects; /** - * Configuration for the cool messages board feature, see {@link ``QuoteBoardForwarder``}. + * Configuration for the quote board feature, see {@link QuoteBoardForwarder}. */ @JsonRootName("coolMessagesConfig") public record QuoteBoardConfig( @@ -23,5 +25,6 @@ public record QuoteBoardConfig( */ public QuoteBoardConfig { Objects.requireNonNull(boardChannelPattern); + Objects.requireNonNull(reactionEmoji); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/QuoteBoardForwarder.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/QuoteBoardForwarder.java index 708a79bf72..fdd677cb72 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/QuoteBoardForwarder.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/QuoteBoardForwarder.java @@ -19,7 +19,7 @@ import java.util.regex.Pattern; /** - * Listens for reaction-add events and turns popular messages into “quotes”. + * Listens for reaction-add events and turns popular messages into "quotes". *
* When someone reacts to a message with the configured emoji, the listener counts how many users
* have used that same emoji. If the total meets or exceeds the minimum threshold and the bot has
@@ -55,30 +55,38 @@ public QuoteBoardForwarder(Config config) {
@Override
public void onMessageReactionAdd(MessageReactionAddEvent event) {
final MessageReaction messageReaction = event.getReaction();
- boolean isCoolEmoji = messageReaction.getEmoji().equals(triggerReaction);
+ boolean isTriggerEmoji = messageReaction.getEmoji().equals(triggerReaction);
long guildId = event.getGuild().getIdLong();
+ if (!isTriggerEmoji) {
+ return;
+ }
+
if (hasAlreadyForwardedMessage(event.getJDA(), messageReaction)) {
return;
}
final int reactionsCount = (int) messageReaction.retrieveUsers().stream().count();
- if (isCoolEmoji && reactionsCount >= config.minimumReactions()) {
- Optional