Skip to content

Commit cbfffdc

Browse files
committed
feat(cool-messages): add configuration files
1 parent 0cbe7b2 commit cbfffdc

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
@@ -175,5 +175,10 @@
175175
"fallbackChannelPattern": "java-news-and-changes",
176176
"pollIntervalInMinutes": 10
177177
},
178+
"coolMessagesConfig": {
179+
"minimumReactions": 5,
180+
"boardChannelPattern": "quotes",
181+
"reactionEmoji": "U+2B50"
182+
},
178183
"memberCountCategoryPattern": "Info"
179184
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class Config {
4848
private final RSSFeedsConfig rssFeedsConfig;
4949
private final String selectRolesChannelPattern;
5050
private final String memberCountCategoryPattern;
51+
private final CoolMessagesBoardConfig coolMessagesConfig;
5152

5253
@SuppressWarnings("ConstructorWithTooManyParameters")
5354
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@@ -100,7 +101,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
100101
required = true) FeatureBlacklistConfig featureBlacklistConfig,
101102
@JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig,
102103
@JsonProperty(value = "selectRolesChannelPattern",
103-
required = true) String selectRolesChannelPattern) {
104+
required = true) String selectRolesChannelPattern,
105+
@JsonProperty(value = "coolMessagesConfig",
106+
required = true) CoolMessagesBoardConfig coolMessagesConfig) {
104107
this.token = Objects.requireNonNull(token);
105108
this.githubApiKey = Objects.requireNonNull(githubApiKey);
106109
this.databasePath = Objects.requireNonNull(databasePath);
@@ -135,6 +138,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
135138
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
136139
this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig);
137140
this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern);
141+
this.coolMessagesConfig = Objects.requireNonNull(coolMessagesConfig);
138142
}
139143

140144
/**
@@ -428,6 +432,15 @@ public String getSelectRolesChannelPattern() {
428432
return selectRolesChannelPattern;
429433
}
430434

435+
/**
436+
* The configuration of the cool messages config.
437+
*
438+
* @return configuration of cool messages config
439+
*/
440+
public CoolMessagesBoardConfig getCoolMessagesConfig() {
441+
return coolMessagesConfig;
442+
}
443+
431444
/**
432445
* Gets the pattern matching the category that is used to display the total member count.
433446
*
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)