Skip to content

Commit e98b6d0

Browse files
Changed StarboardConfig to record
1 parent 9d26bec commit e98b6d0

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ public JShellConfig getJshell() {
364364
public StarboardConfig getStarboard() {
365365
return starboard;
366366
}
367-
/**
367+
368+
/**
368369
* Gets the config for automatic pruning of helper roles.
369370
*
370371
* @return the configuration

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import java.util.Objects;
99

1010
@JsonRootName("starboard")
11-
public final class StarboardConfig {
12-
private final List<String> emojiNames;
13-
private final String channelName;
14-
11+
public record StarboardConfig(List<String> emojiNames, String channelName) {
1512
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
1613
public StarboardConfig(
1714
@JsonProperty(value = "emojiNames", required = true) List<String> emojiNames,
@@ -23,22 +20,24 @@ public StarboardConfig(
2320
/**
2421
* Gets the list of emotes that are recognized by the starboard feature. A message that is
2522
* reacted on with an emote in this list will be reposted in a special channel.
26-
*
23+
* <p>
2724
* Empty to deactivate the feature.
2825
*
2926
* @return The List of emojis recognized by the starboard
3027
*/
31-
public List<String> getEmojiNames() {
28+
@Override
29+
public List<String> emojiNames() {
3230
return emojiNames;
3331
}
3432

3533
/**
3634
* Gets the name of the channel with the starboard Deactivate by using a non-existent channel
3735
* name
38-
*
36+
*
3937
* @return the name of the channel with the starboard
4038
*/
41-
public String getChannelName() {
39+
@Override
40+
public String channelName() {
4241
return channelName;
4342
}
4443
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) {
4444
Optional<TextChannel> starboardChannel = getStarboardChannel(guild);
4545
if (starboardChannel.isEmpty()) {
4646
logger.warn("There is no channel for the starboard in the guild with the name {}",
47-
config.getChannelName());
47+
config.channelName());
4848
return;
4949
}
5050
if (database.read(context -> context.fetchExists(context.selectFrom(STARBOARD_MESSAGES)
@@ -59,12 +59,12 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) {
5959
}
6060

6161
private boolean ignoreMessage(String emojiName, Guild guild, GuildChannel channel) {
62-
return !config.getEmojiNames().contains(emojiName)
62+
return !config.emojiNames().contains(emojiName)
6363
|| !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL);
6464
}
6565

6666
private Optional<TextChannel> getStarboardChannel(Guild guild) {
67-
return guild.getTextChannelsByName(config.getChannelName(), false).stream().findFirst();
67+
return guild.getTextChannelsByName(config.channelName(), false).stream().findFirst();
6868
}
6969

7070
private static MessageEmbed formEmbed(Message message) {

0 commit comments

Comments
 (0)