Skip to content

Commit 0fb1da7

Browse files
use channel pattern instead of name
1 parent 7447e75 commit 0fb1da7

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public JShellConfig getJshell() {
357357

358358
/**
359359
* Gets the config for the Starboard. The starboard displays certain messages in a special
360-
* channel {@link StarboardConfig#channelName()} if a user reacts with one of the recognized
360+
* channel {@link StarboardConfig#channelPattern()} if a user reacts with one of the recognized
361361
* emojis{@link StarboardConfig#emojiNames()}
362362
*
363363
* @return the config of the Starboard

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55

66
import java.util.List;
77
import java.util.Objects;
8+
import java.util.regex.Pattern;
89

910
/**
1011
* Starboard Config
1112
*
1213
* @param emojiNames the List of emojis which are recognized by the starboard
13-
* @param channelName the name of the channel with the starboard
14+
* @param channelPattern the pattern of the channel with the starboard
1415
*/
1516
@JsonRootName("starboard")
16-
public record StarboardConfig(List<String> emojiNames, String channelName) {
17+
public record StarboardConfig(List<String> emojiNames, Pattern channelPattern) {
1718
/**
1819
* Creates a Starboard config.
1920
*
2021
* @param emojiNames the List of emojis which are recognized by the starboard
21-
* @param channelName the name of the channel with the starboard
22+
* @param channelPattern the pattern of the channel with the starboard
2223
*/
2324
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
2425
public StarboardConfig {
2526
Objects.requireNonNull(emojiNames);
26-
Objects.requireNonNull(channelName);
27+
Objects.requireNonNull(channelPattern);
2728
}
2829

2930
/**
3031
* Gets the list of emotes that are recognized by the starboard feature. A message that is
3132
* reacted on with an emote in this list will be reposted in a special channel
32-
* {@link #channelName()}.
33+
* {@link #channelPattern()}.
3334
* <p>
3435
* Empty to deactivate the feature.
3536
*
@@ -41,13 +42,12 @@ public List<String> emojiNames() {
4142
}
4243

4344
/**
44-
* Gets the name of the channel with the starboard. Deactivate by using a non-existent channel
45-
* name.
45+
* Gets the pattern of the channel with the starboard. Deactivate by using a non-existent
46+
* channel name.
4647
*
47-
* @return the name of the channel with the starboard
48+
* @return the pattern of the channel with the starboard
4849
*/
49-
@Override
50-
public String channelName() {
51-
return channelName;
50+
public Pattern channelPattern() {
51+
return channelPattern;
5252
}
5353
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) {
4545
Optional<TextChannel> starboardChannel = getStarboardChannel(guild);
4646
if (starboardChannel.isEmpty()) {
4747
logger.warn("There is no channel for the starboard in the guild with the name {}",
48-
config.channelName());
48+
config.channelPattern());
4949
return;
5050
}
5151
database.write(context -> context.newRecord(STARBOARD_MESSAGES)
@@ -66,7 +66,10 @@ private boolean shouldIgnoreMessage(String emojiName, Guild guild, GuildChannel
6666
}
6767

6868
private Optional<TextChannel> getStarboardChannel(Guild guild) {
69-
return guild.getTextChannelsByName(config.channelName(), false).stream().findFirst();
69+
return guild.getTextChannels()
70+
.stream()
71+
.filter(channel -> config.channelPattern().matcher(channel.getName()).find())
72+
.findFirst();
7073
}
7174

7275
private static MessageEmbed formEmbed(Message message) {

0 commit comments

Comments
 (0)