mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-17 04:29:13 +00:00
added tests for utility module
refactored various commands and services optimized code for message embeds removed emoteUtils completely and moved to service removed suggestion validation, because its now done via feature config fixed regex for discord links changed template to handle the case in which a member which suggested it originally left the server added suggestion update exception in cases the message to edit, does not qualify as a suggestion added check to not allow cross server quoting and added test case refactored mocking for jda objects
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedReaction;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface EmoteService {
|
||||
boolean isEmoteUsableByBot(Emote emote);
|
||||
AEmote buildAEmoteFromReaction(MessageReaction.ReactionEmote reaction);
|
||||
@@ -13,4 +17,7 @@ public interface EmoteService {
|
||||
void throwIfEmoteDoesNotExist(String emoteKey, Long serverId);
|
||||
AEmote getEmoteOrFakeEmote(String emoteKey, Long serverId);
|
||||
String getDefaultEmote(String emoteKey);
|
||||
boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote storedEmote, Emote actualEmoteInGuild);
|
||||
Optional<CachedReaction> getReactionFromMessageByEmote(CachedMessage message, AEmote emote);
|
||||
boolean compareAEmote(AEmote a, AEmote b);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public interface PostTargetService {
|
||||
List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTarget target);
|
||||
List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTarget target);
|
||||
List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTargetEnum postTargetName, Long serverId);
|
||||
void editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target, List<CompletableFuture<Message>> future);
|
||||
void editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTarget, Long serverId, List<CompletableFuture<Message>> future);
|
||||
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target);
|
||||
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTarget, Long serverId);
|
||||
void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId);
|
||||
boolean validPostTarget(String name);
|
||||
List<PostTarget> getPostTargets(AServer server);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.utils;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedReaction;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EmoteUtils {
|
||||
|
||||
private EmoteUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote emote, Emote emoteInGuild) {
|
||||
if(reaction.isEmote() && emote.getCustom()) {
|
||||
if(emoteInGuild != null) {
|
||||
return emoteInGuild.equals(reaction.getEmote());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if(reaction.isEmoji()){
|
||||
return reaction.getEmoji().equals(emote.getEmoteKey());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Optional<CachedReaction> getReactionFromMessageByEmote(CachedMessage message, AEmote emote) {
|
||||
return message.getReactions().stream().filter(reaction -> compareAEmote(reaction.getEmote(), emote)).findFirst();
|
||||
}
|
||||
|
||||
public static boolean compareAEmote(AEmote a, AEmote b) {
|
||||
if(Boolean.TRUE.equals(a.getCustom()) && Boolean.TRUE.equals(b.getCustom())) {
|
||||
return a.getEmoteId().equals(b.getEmoteId());
|
||||
} else {
|
||||
if(Boolean.FALSE.equals(a.getCustom()) && Boolean.FALSE.equals(b.getCustom())) {
|
||||
return a.getEmoteKey().equals(b.getEmoteKey());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user