Skip to content

Commit 021cad3

Browse files
authored
feat: explicit allow list of channels for quotes board (#1488)
* feat: add `allowChannels` to quote board config * feat: prevent quotes trigger on non-whitelisted channels
1 parent 9c234d7 commit 021cad3

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

application/config.json.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@
222222
"⭐": 1.0,
223223

224224
"youtube:1464573182206804010": 0.0
225-
}
225+
},
226+
"allowChannels": [
227+
"chit-chat",
228+
"career-talk",
229+
"geek-speek",
230+
"expert-java-talk",
231+
"ai-talk"
232+
]
226233
},
227234
"roleApplicationSystem": {
228235
"submissionsChannelPattern": "staff-applications",

application/src/main/java/org/togetherjava/tjbot/config/QuoteBoardConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.togetherjava.tjbot.features.basic.QuoteBoardForwarder;
88

9+
import java.util.List;
910
import java.util.Map;
1011
import java.util.Objects;
1112

@@ -18,7 +19,8 @@ public record QuoteBoardConfig(
1819
@JsonProperty(value = "channel", required = true) String channel,
1920
@JsonProperty(value = "botEmoji", required = true) String botEmoji,
2021
@JsonProperty(value = "defaultEmojiScore", required = true) float defaultEmojiScore,
21-
@JsonProperty(value = "emojiScores", required = true) Map<String, Float> emojiScores) {
22+
@JsonProperty(value = "emojiScores", required = true) Map<String, Float> emojiScores,
23+
@JsonProperty(value = "allowChannels", required = true) List<String> allowChannels) {
2224

2325
/**
2426
* Creates a QuoteBoardConfig.

application/src/main/java/org/togetherjava/tjbot/features/basic/QuoteBoardForwarder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public void onMessageReactionAdd(MessageReactionAddEvent event) {
5959
logger.debug("Received MessageReactionAddEvent: messageId={}, channelId={}, userId={}",
6060
event.getMessageId(), event.getChannel().getId(), event.getUserId());
6161

62+
if (!config.allowChannels().contains(event.getChannel().getName())) {
63+
logger.debug("Skipping as reaction occurred in non-whitelisted channel");
64+
return;
65+
}
66+
6267
final long guildId = event.getGuild().getIdLong();
6368

6469
Optional<TextChannel> boardChannelOptional = findQuoteBoardChannel(event.getJDA(), guildId);

0 commit comments

Comments
 (0)