Skip to content

Commit

Permalink
Stop bot from sending enhance message when reacting to a non enhancem…
Browse files Browse the repository at this point in the history
…ent emoji
  • Loading branch information
Alan19 committed Jul 23, 2019
1 parent 60997ec commit 7054aa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/listeners/PlotPointEnhancementListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void startListening() {
event.requestMessage().thenAcceptAsync(message -> {
if (reaction.getEmoji().equalsEmoji("\uD83C\uDDFD")) {
removeEnhancementEmojis(message);
} else {
} else if (new PlotPointEnhancementHelper().isEmojiNumberEmoji(reaction.getEmoji())) {
enhanceRoll(event, reaction, message);
//Wipe reactions and then add star emoji to show that it was enhanced with plot points
removeEnhancementEmojis(message);
Expand Down Expand Up @@ -149,8 +149,7 @@ private int getAddAmount(Emoji emoji) {
int toAdd = 0;
PlotPointEnhancementHelper helper = new PlotPointEnhancementHelper();
if (emoji.isCustomEmoji()) {
String tag = emoji.asKnownCustomEmoji().get().getMentionTag();
String trimmedEmoji = tag.substring(2, tag.length() - 1);
String trimmedEmoji = helper.trimCustomEmoji(emoji.asKnownCustomEmoji().get());
for (Map.Entry<Integer, String> emojiEntry : helper.getOneToTwelveEmojiMap().entrySet()) {
if (emojiEntry.getValue().equals(trimmedEmoji)) {
toAdd = emojiEntry.getKey();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/logic/PlotPointEnhancementHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package logic;

import com.vdurmont.emoji.EmojiParser;
import org.javacord.api.entity.emoji.Emoji;
import org.javacord.api.entity.emoji.KnownCustomEmoji;
import org.javacord.api.entity.message.Message;

import java.util.SortedMap;
Expand Down Expand Up @@ -37,6 +39,21 @@ public void addPlotPointEnhancementEmojis(Message rollMessage) {
rollMessage.addReaction("\uD83C\uDDFD");
}

public boolean isEmojiNumberEmoji(Emoji emoji) {
if (emoji.isUnicodeEmoji() && emoji.asUnicodeEmoji().isPresent()) {
return oneToTwelveEmojiMap.values().contains(emoji.asUnicodeEmoji().get());
} else if (emoji.isKnownCustomEmoji() && emoji.asKnownCustomEmoji().isPresent()) {
String trimmedEmoji = trimCustomEmoji(emoji.asKnownCustomEmoji().get());
return oneToTwelveEmojiMap.values().contains(trimmedEmoji);
}
return false;
}

public String trimCustomEmoji(KnownCustomEmoji emoji) {
String tag = emoji.asKnownCustomEmoji().get().getMentionTag();
return tag.substring(2, tag.length() - 1);
}

public String getCancelEmoji() {
return cancelEmoji;
}
Expand Down

0 comments on commit 7054aa2

Please sign in to comment.