From bbee8b207d5c02884fc313482767945516c298e9 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 7 Mar 2023 16:03:29 +0530 Subject: [PATCH 01/19] Set up config and create reaction listener --- application/config.json.template | 5 ++++ .../org/togetherjava/tjbot/config/Config.java | 10 ++++++- .../tjbot/config/OofsAndLmaosConfig.java | 30 +++++++++++++++++++ .../features/basic/OofsAndLmaosStarboard.java | 27 +++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java diff --git a/application/config.json.template b/application/config.json.template index 84ac087cb0..9581462782 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -88,5 +88,10 @@ ], "logInfoChannelWebhook": "", "logErrorChannelWebhook": "" + "oofsAndLmaos": { + "oofEmojiName": ":oof:" + "lmaoEmojiName": ":lmao" + "starboardChannelId": + } "openaiApiKey": "" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index e5933ca262..2dbdb09329 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -38,6 +38,8 @@ public final class Config { private final String logErrorChannelWebhook; private final String openaiApiKey; + private final OofsAndLmaosConfig oofsAndLmaos; + @SuppressWarnings("ConstructorWithTooManyParameters") @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) private Config(@JsonProperty(value = "token", required = true) String token, @@ -72,7 +74,8 @@ private Config(@JsonProperty(value = "token", required = true) String token, required = true) String logInfoChannelWebhook, @JsonProperty(value = "logErrorChannelWebhook", required = true) String logErrorChannelWebhook, - @JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey) { + @JsonProperty(value = "oofsAndLmaos", + required = true) OofsAndLmaosConfig oofsAndLmaos) { this.token = Objects.requireNonNull(token); this.gistApiKey = Objects.requireNonNull(gistApiKey); this.databasePath = Objects.requireNonNull(databasePath); @@ -96,6 +99,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, this.logInfoChannelWebhook = Objects.requireNonNull(logInfoChannelWebhook); this.logErrorChannelWebhook = Objects.requireNonNull(logErrorChannelWebhook); this.openaiApiKey = Objects.requireNonNull(openaiApiKey); + this.oofsAndLmaos = Objects.requireNonNull(oofsAndLmaos); } /** @@ -316,4 +320,8 @@ public String getLogErrorChannelWebhook() { public String getOpenaiApiKey() { return openaiApiKey; } + + public OofsAndLmaosConfig getOofsAndLmaos() { + return oofsAndLmaos; + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java new file mode 100644 index 0000000000..cc00ec3970 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java @@ -0,0 +1,30 @@ +package org.togetherjava.tjbot.config; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName("oofsAndLmaos") +public final class OofsAndLmaosConfig { + private final String oofEmojiName; + private final String lmaoEmojiName; + private final long starboardChannelId; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public OofsAndLmaosConfig(String oofEmojiName, String lmaoEmojiName, long starboardChannelId) { + this.oofEmojiName = oofEmojiName; + this.lmaoEmojiName = lmaoEmojiName; + this.starboardChannelId = starboardChannelId; + } + + public String getOofEmojiName() { + return oofEmojiName; + } + + public String getLmaoEmojiName() { + return lmaoEmojiName; + } + + public long getStarboardChannelId() { + return starboardChannelId; + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java new file mode 100644 index 0000000000..c08638f150 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java @@ -0,0 +1,27 @@ +package org.togetherjava.tjbot.features.basic; + +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +import org.togetherjava.tjbot.config.Config; +import org.togetherjava.tjbot.config.OofsAndLmaosConfig; +import org.togetherjava.tjbot.features.EventReceiver; + +public class OofsAndLmaosStarboard extends ListenerAdapter implements EventReceiver { + + private final OofsAndLmaosConfig config; + + public OofsAndLmaosStarboard(Config config) { + this.config = config.getOofsAndLmaos(); + } + + @Override + public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { + String emojiName = event.getReaction().getEmoji().asCustom().getName(); + MessageChannel channel = event.getChannel(); + // TODO + + } +} From 199484a717ca835ac7131cc46fb9c2bccbd938ce Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 7 Mar 2023 19:43:27 +0530 Subject: [PATCH 02/19] Refactor class names --- application/config.json.template | 2 +- .../java/org/togetherjava/tjbot/config/Config.java | 12 ++++++------ ...{OofsAndLmaosConfig.java => StarboardConfig.java} | 6 +++--- .../{OofsAndLmaosStarboard.java => Starboard.java} | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) rename application/src/main/java/org/togetherjava/tjbot/config/{OofsAndLmaosConfig.java => StarboardConfig.java} (80%) rename application/src/main/java/org/togetherjava/tjbot/features/basic/{OofsAndLmaosStarboard.java => Starboard.java} (69%) diff --git a/application/config.json.template b/application/config.json.template index 9581462782..310215f680 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -88,7 +88,7 @@ ], "logInfoChannelWebhook": "", "logErrorChannelWebhook": "" - "oofsAndLmaos": { + "starboard": { "oofEmojiName": ":oof:" "lmaoEmojiName": ":lmao" "starboardChannelId": diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 2dbdb09329..ee9d74576d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -38,7 +38,7 @@ public final class Config { private final String logErrorChannelWebhook; private final String openaiApiKey; - private final OofsAndLmaosConfig oofsAndLmaos; + private final StarboardConfig starboard; @SuppressWarnings("ConstructorWithTooManyParameters") @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) @@ -74,8 +74,8 @@ private Config(@JsonProperty(value = "token", required = true) String token, required = true) String logInfoChannelWebhook, @JsonProperty(value = "logErrorChannelWebhook", required = true) String logErrorChannelWebhook, - @JsonProperty(value = "oofsAndLmaos", - required = true) OofsAndLmaosConfig oofsAndLmaos) { + @JsonProperty(value = "starboard", + required = true) StarboardConfig starboard) { this.token = Objects.requireNonNull(token); this.gistApiKey = Objects.requireNonNull(gistApiKey); this.databasePath = Objects.requireNonNull(databasePath); @@ -99,7 +99,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, this.logInfoChannelWebhook = Objects.requireNonNull(logInfoChannelWebhook); this.logErrorChannelWebhook = Objects.requireNonNull(logErrorChannelWebhook); this.openaiApiKey = Objects.requireNonNull(openaiApiKey); - this.oofsAndLmaos = Objects.requireNonNull(oofsAndLmaos); + this.starboard = Objects.requireNonNull(starboard); } /** @@ -321,7 +321,7 @@ public String getOpenaiApiKey() { return openaiApiKey; } - public OofsAndLmaosConfig getOofsAndLmaos() { - return oofsAndLmaos; + public StarboardConfig getStarboard() { + return starboard; } } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java similarity index 80% rename from application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java rename to application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index cc00ec3970..89615a523c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/OofsAndLmaosConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -3,14 +3,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonRootName; -@JsonRootName("oofsAndLmaos") -public final class OofsAndLmaosConfig { +@JsonRootName("starboard") +public final class StarboardConfig { private final String oofEmojiName; private final String lmaoEmojiName; private final long starboardChannelId; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public OofsAndLmaosConfig(String oofEmojiName, String lmaoEmojiName, long starboardChannelId) { + public StarboardConfig(String oofEmojiName, String lmaoEmojiName, long starboardChannelId) { this.oofEmojiName = oofEmojiName; this.lmaoEmojiName = lmaoEmojiName; this.starboardChannelId = starboardChannelId; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java similarity index 69% rename from application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java rename to application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index c08638f150..159aeb7990 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/OofsAndLmaosStarboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -6,15 +6,15 @@ import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.config.Config; -import org.togetherjava.tjbot.config.OofsAndLmaosConfig; +import org.togetherjava.tjbot.config.StarboardConfig; import org.togetherjava.tjbot.features.EventReceiver; -public class OofsAndLmaosStarboard extends ListenerAdapter implements EventReceiver { +public class Starboard extends ListenerAdapter implements EventReceiver { - private final OofsAndLmaosConfig config; + private final StarboardConfig config; - public OofsAndLmaosStarboard(Config config) { - this.config = config.getOofsAndLmaos(); + public Starboard(Config config) { + this.config = config.getStarboard(); } @Override From b34b0743f560724ac8f8d57b6c050fc592dd12d1 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 7 Mar 2023 19:48:16 +0530 Subject: [PATCH 03/19] Add \@JsonProperty --- .../src/main/java/org/togetherjava/tjbot/config/Config.java | 3 +-- .../java/org/togetherjava/tjbot/config/StarboardConfig.java | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index ee9d74576d..413b1b5d34 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -74,8 +74,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, required = true) String logInfoChannelWebhook, @JsonProperty(value = "logErrorChannelWebhook", required = true) String logErrorChannelWebhook, - @JsonProperty(value = "starboard", - required = true) StarboardConfig starboard) { + @JsonProperty(value = "starboard", required = true) StarboardConfig starboard) { this.token = Objects.requireNonNull(token); this.gistApiKey = Objects.requireNonNull(gistApiKey); this.databasePath = Objects.requireNonNull(databasePath); diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 89615a523c..2592664f30 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.config; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; @JsonRootName("starboard") @@ -10,7 +11,10 @@ public final class StarboardConfig { private final long starboardChannelId; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public StarboardConfig(String oofEmojiName, String lmaoEmojiName, long starboardChannelId) { + public StarboardConfig( + @JsonProperty(value = "oofEmojiName", required = true) String oofEmojiName, + @JsonProperty(value = "lmaoEmojiName", required = true) String lmaoEmojiName, + @JsonProperty(value = "starboardChannelId", required = true) long starboardChannelId) { this.oofEmojiName = oofEmojiName; this.lmaoEmojiName = lmaoEmojiName; this.starboardChannelId = starboardChannelId; From 0e369c7c34538147037c8e4a29292998e5079ac8 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 7 Mar 2023 19:52:07 +0530 Subject: [PATCH 04/19] Remove : --- application/config.json.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 310215f680..eec024cd4b 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -89,8 +89,8 @@ "logInfoChannelWebhook": "", "logErrorChannelWebhook": "" "starboard": { - "oofEmojiName": ":oof:" - "lmaoEmojiName": ":lmao" + "oofEmojiName": "oof" + "lmaoEmojiName": "lmao" "starboardChannelId": } "openaiApiKey": "" From ce456626ceba7ea59f996bb94eb555c2343787ac Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Fri, 10 Mar 2023 16:31:58 +0530 Subject: [PATCH 05/19] config changes --- application/config.json.template | 5 ++-- .../tjbot/config/StarboardConfig.java | 30 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index eec024cd4b..d23602c38c 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -89,9 +89,8 @@ "logInfoChannelWebhook": "", "logErrorChannelWebhook": "" "starboard": { - "oofEmojiName": "oof" - "lmaoEmojiName": "lmao" - "starboardChannelId": + "starboardEmojiNames" : ["oof", "lmao"] + "starboardChannelName": "oofs_and_lmaos" } "openaiApiKey": "" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 2592664f30..1390619f78 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -4,31 +4,25 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import java.util.List; + @JsonRootName("starboard") public final class StarboardConfig { - private final String oofEmojiName; - private final String lmaoEmojiName; - private final long starboardChannelId; + private final List emojiNames; + private final String starboardChannelName; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public StarboardConfig( - @JsonProperty(value = "oofEmojiName", required = true) String oofEmojiName, - @JsonProperty(value = "lmaoEmojiName", required = true) String lmaoEmojiName, - @JsonProperty(value = "starboardChannelId", required = true) long starboardChannelId) { - this.oofEmojiName = oofEmojiName; - this.lmaoEmojiName = lmaoEmojiName; - this.starboardChannelId = starboardChannelId; - } - - public String getOofEmojiName() { - return oofEmojiName; + public StarboardConfig(@JsonProperty(value = "starboardEmojiNames", required = true) List emojiNames, + @JsonProperty(value = "starboardChannelName", required = true) String starboardChannelName) { + this.emojiNames = emojiNames; + this.starboardChannelName = starboardChannelName; } - public String getLmaoEmojiName() { - return lmaoEmojiName; + public List getEmojiNames() { + return emojiNames; } - public long getStarboardChannelId() { - return starboardChannelId; + public String getStarboardChannelName() { + return starboardChannelName; } } From b4cae2102a1d017a6aa8cc74263b4afa80c6f376 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Fri, 10 Mar 2023 16:51:11 +0530 Subject: [PATCH 06/19] Some stuff --- .../tjbot/features/basic/Starboard.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 159aeb7990..18c510c7a3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -1,14 +1,24 @@ package org.togetherjava.tjbot.features.basic; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.internal.utils.PermissionUtil; import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.config.StarboardConfig; import org.togetherjava.tjbot.features.EventReceiver; +import java.awt.*; +import java.util.Optional; + public class Starboard extends ListenerAdapter implements EventReceiver { private final StarboardConfig config; @@ -20,8 +30,17 @@ public Starboard(Config config) { @Override public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { String emojiName = event.getReaction().getEmoji().asCustom().getName(); - MessageChannel channel = event.getChannel(); - // TODO - + Guild guild = event.getGuild(); + GuildChannel channel = event.getGuildChannel(); + if (!config.getEmojiNames().contains(emojiName) || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL)) { + return; + } + Optional starboardChannel = guild.getTextChannelsByName(config.getStarboardChannelName(), false).stream().findFirst(); + if (starboardChannel.isEmpty()) { + //TODO log? + return; + } + MessageEmbed embed = new EmbedBuilder().build(); //TODO build embed + starboardChannel.get().sendMessageEmbeds(embed).queue(); } } From 5079521d9212b8deae3eabbda12a5bd2bb7e1548 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Mon, 13 Mar 2023 14:47:02 +0530 Subject: [PATCH 07/19] config fix --- application/config.json.template | 4 ++-- .../java/org/togetherjava/tjbot/config/StarboardConfig.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index d23602c38c..1fe437de77 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -89,8 +89,8 @@ "logInfoChannelWebhook": "", "logErrorChannelWebhook": "" "starboard": { - "starboardEmojiNames" : ["oof", "lmao"] - "starboardChannelName": "oofs_and_lmaos" + "emojiNames" : ["oof", "lmao"] + "channelName": "oofs_and_lmaos" } "openaiApiKey": "" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 1390619f78..02ef761bc9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -12,8 +12,8 @@ public final class StarboardConfig { private final String starboardChannelName; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public StarboardConfig(@JsonProperty(value = "starboardEmojiNames", required = true) List emojiNames, - @JsonProperty(value = "starboardChannelName", required = true) String starboardChannelName) { + public StarboardConfig(@JsonProperty(value = "emojiNames", required = true) List emojiNames, + @JsonProperty(value = "channelName", required = true) String starboardChannelName) { this.emojiNames = emojiNames; this.starboardChannelName = starboardChannelName; } From dc1ba36322d3edb729b74224f49a4cbe7f7350b8 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Mon, 13 Mar 2023 15:25:11 +0530 Subject: [PATCH 08/19] log --- .../org/togetherjava/tjbot/features/basic/Starboard.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 18c510c7a3..164ba0ee2a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -6,21 +6,21 @@ import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.internal.utils.PermissionUtil; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.config.StarboardConfig; import org.togetherjava.tjbot.features.EventReceiver; -import java.awt.*; import java.util.Optional; public class Starboard extends ListenerAdapter implements EventReceiver { + private static final Logger logger = LoggerFactory.getLogger(Starboard.class); private final StarboardConfig config; public Starboard(Config config) { @@ -37,7 +37,7 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { } Optional starboardChannel = guild.getTextChannelsByName(config.getStarboardChannelName(), false).stream().findFirst(); if (starboardChannel.isEmpty()) { - //TODO log? + logger.warn("There is no channel for the starboard in the guild with the name {}", config.getStarboardChannelName()); return; } MessageEmbed embed = new EmbedBuilder().build(); //TODO build embed From a2ec12fdf5f7991c46a9105c550d5b61ff97c20d Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Mon, 13 Mar 2023 15:25:24 +0530 Subject: [PATCH 09/19] added docs --- .../java/org/togetherjava/tjbot/config/Config.java | 5 +++++ .../org/togetherjava/tjbot/config/StarboardConfig.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 413b1b5d34..6863e82266 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -320,6 +320,11 @@ public String getOpenaiApiKey() { return openaiApiKey; } + /** + * Gets the config for the Starboard + * + * @return the config of the Starboard + * */ public StarboardConfig getStarboard() { return starboard; } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 02ef761bc9..9249a1d5cd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -18,9 +18,19 @@ public StarboardConfig(@JsonProperty(value = "emojiNames", required = true) List this.starboardChannelName = starboardChannelName; } + /** + * Gets the names of the emojis whose users react with for it to be put on the starboard + * + * @return The names of the emojis whose users react with for it to be put on the starboard + * */ public List getEmojiNames() { return emojiNames; } + /** + * Gets the name of the channel with the starboard + * + * @return the name of the channel with the starboard + * */ public String getStarboardChannelName() { return starboardChannelName; From 0ec514d595a94dc5998f8228c25962d5cfcaea1b Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 14 Mar 2023 14:37:21 +0530 Subject: [PATCH 10/19] Make embed --- .../togetherjava/tjbot/features/basic/Starboard.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 164ba0ee2a..ce3e3f390f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -3,7 +3,9 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; @@ -40,7 +42,11 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { logger.warn("There is no channel for the starboard in the guild with the name {}", config.getStarboardChannelName()); return; } - MessageEmbed embed = new EmbedBuilder().build(); //TODO build embed - starboardChannel.get().sendMessageEmbeds(embed).queue(); + event.getChannel().retrieveMessageById(event.getMessageId()).flatMap(message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))).queue(); + } + + private static MessageEmbed formEmbed(Message message) { + User author = message.getAuthor(); + return new EmbedBuilder().setAuthor(author.getName(), null, author.getAvatarUrl()).setDescription(message.getContentDisplay()).build(); //Maybe set footer as reacted emoji? } } From cb10c88a99f5489f28128f56ee1980fdd97eb3bd Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 14 Mar 2023 14:40:43 +0530 Subject: [PATCH 11/19] Add feature --- .../src/main/java/org/togetherjava/tjbot/features/Features.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/Features.java b/application/src/main/java/org/togetherjava/tjbot/features/Features.java index 7f1f3af046..ece3020bc8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/Features.java @@ -111,6 +111,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new GuildLeaveCloseThreadListener(config)); features.add(new LeftoverBookmarksListener(bookmarksSystem)); features.add(new HelpThreadCreatedListener(helpSystemHelper)); + features.add(new Starboard(config)); // Message context commands From fe835104d6f4ecf61158ddffb96a7688b7564a93 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 14 Mar 2023 15:14:12 +0530 Subject: [PATCH 12/19] json fix --- application/config.json.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 1fe437de77..f353dfd290 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -87,9 +87,9 @@ "wsh" ], "logInfoChannelWebhook": "", - "logErrorChannelWebhook": "" + "logErrorChannelWebhook": "", "starboard": { - "emojiNames" : ["oof", "lmao"] + "emojiNames" : ["oof", "lmao"], "channelName": "oofs_and_lmaos" } "openaiApiKey": "" From edd9b50b3f4d5063cfee82daeb72c6bfa133a3c9 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 14 Mar 2023 18:06:47 +0530 Subject: [PATCH 13/19] config changes --- application/config.json.template | 2 +- .../main/java/org/togetherjava/tjbot/config/Config.java | 2 +- .../org/togetherjava/tjbot/config/StarboardConfig.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index f353dfd290..79d7707043 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -89,7 +89,7 @@ "logInfoChannelWebhook": "", "logErrorChannelWebhook": "", "starboard": { - "emojiNames" : ["oof", "lmao"], + "emojiNames" : ["star"], "channelName": "oofs_and_lmaos" } "openaiApiKey": "" diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 6863e82266..f5d3bf9fe8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -322,7 +322,7 @@ public String getOpenaiApiKey() { /** * Gets the config for the Starboard - * + * Contains the List of emoji names recognized by the starboard as well as the name of the channel with the starboard. * @return the config of the Starboard * */ public StarboardConfig getStarboard() { diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 9249a1d5cd..ef1d638300 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -19,16 +19,18 @@ public StarboardConfig(@JsonProperty(value = "emojiNames", required = true) List } /** - * Gets the names of the emojis whose users react with for it to be put on the starboard + * Gets the list of emotes that are recognized by the starboard feature. A message that is reacted on with an emote in this list will be reposted in a special channel. + + * Empty to deactivate the feature. * - * @return The names of the emojis whose users react with for it to be put on the starboard + * @return The List of emojis recognized by the starboard * */ public List getEmojiNames() { return emojiNames; } /** * Gets the name of the channel with the starboard - * + * Deactivate by using a non-existent channel name * @return the name of the channel with the starboard * */ From 49222429c5e7df5f9502d1828300a04fa319352d Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Wed, 15 Mar 2023 13:25:41 +0530 Subject: [PATCH 14/19] Replace channel name with Starboard --- application/config.json.template | 2 +- .../org/togetherjava/tjbot/config/StarboardConfig.java | 10 +++++----- .../togetherjava/tjbot/features/basic/Starboard.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 79d7707043..0c31cf0bbe 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -90,7 +90,7 @@ "logErrorChannelWebhook": "", "starboard": { "emojiNames" : ["star"], - "channelName": "oofs_and_lmaos" + "starboard": "oofs_and_lmaos" } "openaiApiKey": "" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index ef1d638300..17e49c2293 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -9,13 +9,13 @@ @JsonRootName("starboard") public final class StarboardConfig { private final List emojiNames; - private final String starboardChannelName; + private final String starboard; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public StarboardConfig(@JsonProperty(value = "emojiNames", required = true) List emojiNames, - @JsonProperty(value = "channelName", required = true) String starboardChannelName) { + @JsonProperty(value = "channelName", required = true) String starboard) { this.emojiNames = emojiNames; - this.starboardChannelName = starboardChannelName; + this.starboard = starboard; } /** @@ -34,7 +34,7 @@ public List getEmojiNames() { * @return the name of the channel with the starboard * */ - public String getStarboardChannelName() { - return starboardChannelName; + public String getStarboard() { + return starboard; } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index ce3e3f390f..446bb99aa2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -37,9 +37,9 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { if (!config.getEmojiNames().contains(emojiName) || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL)) { return; } - Optional starboardChannel = guild.getTextChannelsByName(config.getStarboardChannelName(), false).stream().findFirst(); + Optional starboardChannel = guild.getTextChannelsByName(config.getStarboard(), false).stream().findFirst(); if (starboardChannel.isEmpty()) { - logger.warn("There is no channel for the starboard in the guild with the name {}", config.getStarboardChannelName()); + logger.warn("There is no channel for the starboard in the guild with the name {}", config.getStarboard()); return; } event.getChannel().retrieveMessageById(event.getMessageId()).flatMap(message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))).queue(); From 9564d4cacc034468feb6068c0abeee84ae99d185 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Wed, 15 Mar 2023 15:20:25 +0530 Subject: [PATCH 15/19] forgot sptoless --- .../org/togetherjava/tjbot/config/Config.java | 8 +++---- .../tjbot/config/StarboardConfig.java | 20 +++++++++++------- .../tjbot/features/basic/Starboard.java | 21 +++++++++++++------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index f5d3bf9fe8..4717444594 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -320,11 +320,11 @@ public String getOpenaiApiKey() { return openaiApiKey; } - /** - * Gets the config for the Starboard - * Contains the List of emoji names recognized by the starboard as well as the name of the channel with the starboard. + * Gets the config for the Starboard Contains the List of emoji names recognized by the + * starboard as well as the name of the channel with the starboard. + * * @return the config of the Starboard - * */ + */ public StarboardConfig getStarboard() { return starboard; } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 17e49c2293..28a496c155 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -12,27 +12,31 @@ public final class StarboardConfig { private final String starboard; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public StarboardConfig(@JsonProperty(value = "emojiNames", required = true) List emojiNames, - @JsonProperty(value = "channelName", required = true) String starboard) { + public StarboardConfig( + @JsonProperty(value = "emojiNames", required = true) List emojiNames, + @JsonProperty(value = "channelName", required = true) String starboard) { this.emojiNames = emojiNames; this.starboard = starboard; } /** - * Gets the list of emotes that are recognized by the starboard feature. A message that is reacted on with an emote in this list will be reposted in a special channel. - + * Gets the list of emotes that are recognized by the starboard feature. A message that is + * reacted on with an emote in this list will be reposted in a special channel. + * * Empty to deactivate the feature. * * @return The List of emojis recognized by the starboard - * */ + */ public List getEmojiNames() { return emojiNames; } + /** - * Gets the name of the channel with the starboard - * Deactivate by using a non-existent channel name + * Gets the name of the channel with the starboard Deactivate by using a non-existent channel + * name + * * @return the name of the channel with the starboard - * */ + */ public String getStarboard() { return starboard; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 446bb99aa2..6092bcc726 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -11,9 +11,9 @@ import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.config.StarboardConfig; import org.togetherjava.tjbot.features.EventReceiver; @@ -34,19 +34,28 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { String emojiName = event.getReaction().getEmoji().asCustom().getName(); Guild guild = event.getGuild(); GuildChannel channel = event.getGuildChannel(); - if (!config.getEmojiNames().contains(emojiName) || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL)) { + if (!config.getEmojiNames().contains(emojiName) + || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL)) { return; } - Optional starboardChannel = guild.getTextChannelsByName(config.getStarboard(), false).stream().findFirst(); + Optional starboardChannel = + guild.getTextChannelsByName(config.getStarboard(), false).stream().findFirst(); if (starboardChannel.isEmpty()) { - logger.warn("There is no channel for the starboard in the guild with the name {}", config.getStarboard()); + logger.warn("There is no channel for the starboard in the guild with the name {}", + config.getStarboard()); return; } - event.getChannel().retrieveMessageById(event.getMessageId()).flatMap(message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))).queue(); + event.getChannel() + .retrieveMessageById(event.getMessageId()) + .flatMap( + message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))) + .queue(); } private static MessageEmbed formEmbed(Message message) { User author = message.getAuthor(); - return new EmbedBuilder().setAuthor(author.getName(), null, author.getAvatarUrl()).setDescription(message.getContentDisplay()).build(); //Maybe set footer as reacted emoji? + return new EmbedBuilder().setAuthor(author.getName(), null, author.getAvatarUrl()) + .setDescription(message.getContentDisplay()) + .build(); // Maybe set footer as reacted emoji? } } From ad41f3eaa74da443a0fefcc8d28d70ec090ecade Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Tue, 21 Mar 2023 14:23:40 +0530 Subject: [PATCH 16/19] Changes from CR --- application/config.json.template | 2 +- .../org/togetherjava/tjbot/config/StarboardConfig.java | 10 +++++----- .../togetherjava/tjbot/features/basic/Starboard.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/config.json.template b/application/config.json.template index 0c31cf0bbe..d05574f1a4 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -90,7 +90,7 @@ "logErrorChannelWebhook": "", "starboard": { "emojiNames" : ["star"], - "starboard": "oofs_and_lmaos" + "channelName": "starboard" } "openaiApiKey": "" } diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 28a496c155..dbd1ab7750 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -9,14 +9,14 @@ @JsonRootName("starboard") public final class StarboardConfig { private final List emojiNames; - private final String starboard; + private final String channelName; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public StarboardConfig( @JsonProperty(value = "emojiNames", required = true) List emojiNames, - @JsonProperty(value = "channelName", required = true) String starboard) { + @JsonProperty(value = "channelName", required = true) String channelName) { this.emojiNames = emojiNames; - this.starboard = starboard; + this.channelName = channelName; } /** @@ -38,7 +38,7 @@ public List getEmojiNames() { * @return the name of the channel with the starboard */ - public String getStarboard() { - return starboard; + public String getChannelName() { + return channelName; } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 6092bcc726..295a2a6fd5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -39,10 +39,10 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { return; } Optional starboardChannel = - guild.getTextChannelsByName(config.getStarboard(), false).stream().findFirst(); + guild.getTextChannelsByName(config.getChannelName(), false).stream().findFirst(); if (starboardChannel.isEmpty()) { logger.warn("There is no channel for the starboard in the guild with the name {}", - config.getStarboard()); + config.getChannelName()); return; } event.getChannel() From e2b7ee6d6cd0be0a08f74d9549103f92989fd588 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Thu, 23 Mar 2023 20:20:18 +0530 Subject: [PATCH 17/19] Null check --- .../java/org/togetherjava/tjbot/config/StarboardConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index dbd1ab7750..0b093ebe8f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonRootName; import java.util.List; +import java.util.Objects; @JsonRootName("starboard") public final class StarboardConfig { @@ -15,8 +16,8 @@ public final class StarboardConfig { public StarboardConfig( @JsonProperty(value = "emojiNames", required = true) List emojiNames, @JsonProperty(value = "channelName", required = true) String channelName) { - this.emojiNames = emojiNames; - this.channelName = channelName; + this.emojiNames = Objects.requireNonNull(emojiNames); + this.channelName = Objects.requireNonNull(channelName); } /** From 1ae7a61bbd091e19c3dcb7a1b3af1331c3218389 Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Mon, 1 May 2023 15:35:16 +0530 Subject: [PATCH 18/19] Spotless + Fix merge conflict --- .../src/main/java/org/togetherjava/tjbot/config/Config.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 4717444594..05f6f5b5ba 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -74,6 +74,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, required = true) String logInfoChannelWebhook, @JsonProperty(value = "logErrorChannelWebhook", required = true) String logErrorChannelWebhook, + @JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey, @JsonProperty(value = "starboard", required = true) StarboardConfig starboard) { this.token = Objects.requireNonNull(token); this.gistApiKey = Objects.requireNonNull(gistApiKey); @@ -320,6 +321,7 @@ public String getOpenaiApiKey() { return openaiApiKey; } + /** * Gets the config for the Starboard Contains the List of emoji names recognized by the * starboard as well as the name of the channel with the starboard. * From 86ceba8165e649e113ed2783a96c4183ca6f315a Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Thu, 18 May 2023 15:54:09 +0530 Subject: [PATCH 19/19] Applied changes as per CR --- .../tjbot/config/StarboardConfig.java | 1 - .../tjbot/features/basic/Starboard.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java index 0b093ebe8f..82568a7674 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java @@ -38,7 +38,6 @@ public List getEmojiNames() { * * @return the name of the channel with the starboard */ - public String getChannelName() { return channelName; } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java index 295a2a6fd5..f13f3ad253 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java @@ -31,31 +31,36 @@ public Starboard(Config config) { @Override public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { - String emojiName = event.getReaction().getEmoji().asCustom().getName(); + String emojiName = event.getEmoji().asCustom().getName(); Guild guild = event.getGuild(); - GuildChannel channel = event.getGuildChannel(); - if (!config.getEmojiNames().contains(emojiName) - || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL)) { + if (ignoreMessage(emojiName, guild, event.getGuildChannel())) { return; } - Optional starboardChannel = - guild.getTextChannelsByName(config.getChannelName(), false).stream().findFirst(); + Optional starboardChannel = getStarboardChannel(guild); if (starboardChannel.isEmpty()) { logger.warn("There is no channel for the starboard in the guild with the name {}", config.getChannelName()); return; } - event.getChannel() - .retrieveMessageById(event.getMessageId()) + event.retrieveMessage() .flatMap( message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))) .queue(); } + private boolean ignoreMessage(String emojiName, Guild guild, GuildChannel channel) { + return !config.getEmojiNames().contains(emojiName) + || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL); + } + + private Optional getStarboardChannel(Guild guild) { + return guild.getTextChannelsByName(config.getChannelName(), false).stream().findFirst(); + } + private static MessageEmbed formEmbed(Message message) { User author = message.getAuthor(); return new EmbedBuilder().setAuthor(author.getName(), null, author.getAvatarUrl()) .setDescription(message.getContentDisplay()) - .build(); // Maybe set footer as reacted emoji? + .build(); // TODO make footer with link and reacted emojis } }