Skip to content

Commit 9e16276

Browse files
committed
feat(cool-messages): add configuration files
1 parent 817e044 commit 9e16276

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

application/config.json.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,10 @@
115115
"fallbackChannelPattern": "java-news-and-changes",
116116
"pollIntervalInMinutes": 10
117117
},
118+
"coolMessagesConfig": {
119+
"minimumReactions": 5,
120+
"boardChannelPattern": "quotes",
121+
"reactionEmoji": "U+2B50"
122+
},
118123
"memberCountCategoryPattern": "Info"
119124
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public final class Config {
4646
private final RSSFeedsConfig rssFeedsConfig;
4747
private final String selectRolesChannelPattern;
4848
private final String memberCountCategoryPattern;
49+
private final CoolMessagesBoardConfig coolMessagesConfig;
4950

5051
@SuppressWarnings("ConstructorWithTooManyParameters")
5152
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@@ -94,7 +95,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
9495
required = true) FeatureBlacklistConfig featureBlacklistConfig,
9596
@JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig,
9697
@JsonProperty(value = "selectRolesChannelPattern",
97-
required = true) String selectRolesChannelPattern) {
98+
required = true) String selectRolesChannelPattern,
99+
@JsonProperty(value = "coolMessagesConfig",
100+
required = true) CoolMessagesBoardConfig coolMessagesConfig) {
98101
this.token = Objects.requireNonNull(token);
99102
this.githubApiKey = Objects.requireNonNull(githubApiKey);
100103
this.databasePath = Objects.requireNonNull(databasePath);
@@ -127,6 +130,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
127130
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
128131
this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig);
129132
this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern);
133+
this.coolMessagesConfig = Objects.requireNonNull(coolMessagesConfig);
130134
}
131135

132136
/**
@@ -401,6 +405,15 @@ public String getSelectRolesChannelPattern() {
401405
return selectRolesChannelPattern;
402406
}
403407

408+
/**
409+
* The configuration of the cool messages config.
410+
*
411+
* @return configuration of cool messages config
412+
*/
413+
public CoolMessagesBoardConfig getCoolMessagesConfig() {
414+
return coolMessagesConfig;
415+
}
416+
404417
/**
405418
* Gets the pattern matching the category that is used to display the total member count.
406419
*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.annotation.JsonRootName;
5+
6+
import java.util.Objects;
7+
8+
/**
9+
* Configuration for the cool messages board feature, see
10+
* {@link org.togetherjava.tjbot.features.basic.CoolMessagesBoardManager}.
11+
*/
12+
@JsonRootName("coolMessagesConfig")
13+
public record CoolMessagesBoardConfig(
14+
@JsonProperty(value = "minimumReactions", required = true) int minimumReactions,
15+
@JsonProperty(value = "boardChannelPattern", required = true) String boardChannelPattern,
16+
@JsonProperty(value = "reactionEmoji", required = true) String reactionEmoji) {
17+
18+
/**
19+
* Creates a CoolMessagesBoardConfig.
20+
*
21+
* @param minimumReactions the minimum amount of reactions
22+
* @param boardChannelPattern the pattern for the board channel
23+
* @param reactionEmoji the emoji with which users should react to
24+
*/
25+
public CoolMessagesBoardConfig {
26+
Objects.requireNonNull(boardChannelPattern);
27+
}
28+
}

application/src/main/java/org/togetherjava/tjbot/features/MessageReceiver.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
44
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
55
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
6+
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
67

78
import java.util.regex.Pattern;
89

@@ -56,4 +57,13 @@ public interface MessageReceiver extends Feature {
5657
* message that was deleted
5758
*/
5859
void onMessageDeleted(MessageDeleteEvent event);
60+
61+
/**
62+
* Triggered by the core system whenever a new reaction was added to a message in a text channel
63+
* of a guild the bot has been added to.
64+
*
65+
* @param event the event that triggered this, containing information about the corresponding
66+
* reaction that was added
67+
*/
68+
void onMessageReactionAdd(MessageReactionAddEvent event);
5969
}

application/src/main/java/org/togetherjava/tjbot/features/MessageReceiverAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
44
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
55
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
6+
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
67

78
import java.util.regex.Pattern;
89

@@ -57,4 +58,10 @@ public void onMessageUpdated(MessageUpdateEvent event) {
5758
public void onMessageDeleted(MessageDeleteEvent event) {
5859
// Adapter does not react by default, subclasses may change this behavior
5960
}
61+
62+
@SuppressWarnings("NoopMethodInAbstractClass")
63+
@Override
64+
public void onMessageReactionAdd(MessageReactionAddEvent event) {
65+
// Adapter does not react by default, subclasses may change this behavior
66+
}
6067
}

application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
1414
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
1515
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
16+
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
1617
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1718
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
1819
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
@@ -238,6 +239,14 @@ public void onMessageDelete(final MessageDeleteEvent event) {
238239
}
239240
}
240241

242+
@Override
243+
public void onMessageReactionAdd(final MessageReactionAddEvent event) {
244+
if (event.isFromGuild()) {
245+
getMessageReceiversSubscribedTo(event.getChannel())
246+
.forEach(messageReceiver -> messageReceiver.onMessageReactionAdd(event));
247+
}
248+
}
249+
241250
private Stream<MessageReceiver> getMessageReceiversSubscribedTo(Channel channel) {
242251
String channelName = channel.getName();
243252
return channelNameToMessageReceiver.entrySet()

0 commit comments

Comments
 (0)