-
-
Notifications
You must be signed in to change notification settings - Fork 104
Oofs and Lmaos Starboard #798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bbee8b2
Set up config and create reaction listener
java-coding-prodigy 199484a
Refactor class names
java-coding-prodigy b34b074
Add \@JsonProperty
java-coding-prodigy 0e369c7
Remove :
java-coding-prodigy ce45662
config changes
java-coding-prodigy b4cae21
Some stuff
java-coding-prodigy 5079521
config fix
java-coding-prodigy dc1ba36
log
java-coding-prodigy a2ec12f
added docs
java-coding-prodigy 0ec514d
Make embed
java-coding-prodigy cb10c88
Add feature
java-coding-prodigy fe83510
json fix
java-coding-prodigy edd9b50
config changes
java-coding-prodigy 4922242
Replace channel name with Starboard
java-coding-prodigy 9564d4c
forgot sptoless
java-coding-prodigy ad41f3e
Changes from CR
java-coding-prodigy e2b7ee6
Null check
java-coding-prodigy 1ae7a61
Spotless + Fix merge conflict
java-coding-prodigy 86ceba8
Applied changes as per CR
java-coding-prodigy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
application/src/main/java/org/togetherjava/tjbot/config/StarboardConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.togetherjava.tjbot.config; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.JsonRootName; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| @JsonRootName("starboard") | ||
| public final class StarboardConfig { | ||
| private final List<String> emojiNames; | ||
| private final String channelName; | ||
|
|
||
| @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
| public StarboardConfig( | ||
| @JsonProperty(value = "emojiNames", required = true) List<String> emojiNames, | ||
| @JsonProperty(value = "channelName", required = true) String channelName) { | ||
| this.emojiNames = Objects.requireNonNull(emojiNames); | ||
| this.channelName = Objects.requireNonNull(channelName); | ||
| } | ||
|
|
||
| /** | ||
| * 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<String> 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 | ||
| */ | ||
| public String getChannelName() { | ||
| return channelName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
application/src/main/java/org/togetherjava/tjbot/features/basic/Starboard.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||
| 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.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; | ||||||
| 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; | ||||||
|
|
||||||
| 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) { | ||||||
| this.config = config.getStarboard(); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { | ||||||
| String emojiName = event.getEmoji().asCustom().getName(); | ||||||
| Guild guild = event.getGuild(); | ||||||
| if (ignoreMessage(emojiName, guild, event.getGuildChannel())) { | ||||||
| return; | ||||||
| } | ||||||
| Optional<TextChannel> 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.retrieveMessage() | ||||||
| .flatMap( | ||||||
| message -> starboardChannel.orElseThrow().sendMessageEmbeds(formEmbed(message))) | ||||||
| .queue(); | ||||||
| } | ||||||
|
|
||||||
| private boolean ignoreMessage(String emojiName, Guild guild, GuildChannel channel) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return !config.getEmojiNames().contains(emojiName) | ||||||
| || !guild.getPublicRole().hasPermission(channel, Permission.VIEW_CHANNEL); | ||||||
| } | ||||||
|
|
||||||
| private Optional<TextChannel> 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(); // TODO make footer with link and reacted emojis | ||||||
| } | ||||||
| } | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.