[AB-97] adding react command

we are now actively loading messages in case its a parameter, because the provided message is only partially available
This commit is contained in:
Sheldan
2021-04-13 23:47:22 +02:00
parent 23379e4498
commit 537fd85be8
36 changed files with 820 additions and 22 deletions

View File

@@ -0,0 +1,21 @@
package dev.sheldan.abstracto.entertainment.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
public class ReactDuplicateCharacterException extends AbstractoRunTimeException implements Templatable {
public ReactDuplicateCharacterException() {
super("Could not replace all characters to be duplicate free.");
}
@Override
public String getTemplateName() {
return "react_duplicate_character_exception";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,21 @@
package dev.sheldan.abstracto.entertainment.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
public class ReactTooManyReactionsException extends AbstractoRunTimeException implements Templatable {
public ReactTooManyReactionsException() {
super("Adding reactions would lead to too many reactions.");
}
@Override
public String getTemplateName() {
return "react_too_many_reactions_exception";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,36 @@
package dev.sheldan.abstracto.entertainment.model;
import lombok.*;
import java.util.*;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReactMapping {
@Builder.Default
private HashMap<String, List<String>> single = new HashMap<>();
@Builder.Default
private HashMap<String, String> combination = new HashMap<>();
@Builder.Default
private SortedSet<String> combinationKeys = new TreeSet<>((o1, o2) -> {
if(o2.length() == o1.length()) {
return o2.compareTo(o1);
} else {
return Integer.compare(o2.length(), o1.length());
}
});
@Builder.Default
private Set<String> combinationReplacements = new HashSet<>();
public void populateKeys() {
combinationKeys.addAll(combination.keySet());
combinationKeys.forEach(s -> combinationReplacements.add(this.combination.get(s)));
}
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.entertainment.model;
package dev.sheldan.abstracto.entertainment.model.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import lombok.Getter;

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.entertainment.service;
import dev.sheldan.abstracto.entertainment.exception.ReactDuplicateCharacterException;
import net.dv8tion.jda.api.entities.Member;
import java.util.List;
@@ -11,4 +12,64 @@ public interface EntertainmentService {
boolean executeRoulette(Member memberExecuting);
String takeChoice(List<String> choices, Member memberExecuting);
String createMockText(String text, Member memberExecuting, Member mockedUser);
/**
* Converts the given text to unicode characters (with predefined values from a manual mapping) and returns the matched
* characters as a list. If the given text is null, an empty list will be returned. This method will actively try
* to avoid duplicates, and try to use alternatives, and throw an exception in case it was not possible to return unique values.
* The size of the list might not be equal to the length of the provided string, because sometimes multiple
* characters are combined into one unicode char.
* @throws ReactDuplicateCharacterException In case it was not possible to replace all text with appropriate unicode
* in case there too many duplicated characters
* @param text The text to convert
* @return A {@link List} of unicode characters, represented as strings, which look similar to the individual characters
* from the text
*/
List<String> convertTextToEmojis(String text);
/**
* Converts the given text to unicode characters (with predefined values from a manual mapping) and returns the matched
* characters as a string. If the given text is null, an empty string will be returned. This method will actively try
* to avoid duplicates, and try to use alternatives, and throw an exception in case it was not possible to return unique values.
* The length of the string might not be equal to the length of the provided string, because sometimes multiple
* characters are combined into one unicode char.
* @throws ReactDuplicateCharacterException In case it was not possible to replace all text with appropriate unicode
* in case there too many duplicated characters
* @param text The text to convert
* @return A string of unicode characters which look similar to the individual characters from the text
*/
String convertTextToEmojisAString(String text);
/**
* Converts the given text to unicode characters (with predefined values from a manual mapping) and returns the matched
* characters as a list. If the given text is null, an empty list will be returned. This method will actively try
* to avoid duplicates (if requested), and try to use alternatives, and throw an exception in case it was not possible
* to return unique values. In case duplicates are allowed, the first possible replacement value will be used,
* leading to all 1:1 replacements being of the same character.
* The size of the list might not be equal to the length of the provided string, because sometimes multiple
* characters are combined into one unicode char.
* @throws ReactDuplicateCharacterException In case it was not possible to replace all text with appropriate unicode
* in case there too many duplicated characters
* @param text The text to convert
* @param allowDuplicates Whether or not to allow duplicates
* @return A list of characters, represented as strings, which look similar to the individual characters
* from the text, possible with duplicates, if requested
*/
List<String> convertTextToEmojis(String text, boolean allowDuplicates);
/**
* Converts the given text to unicode characters (with predefined values from a manual mapping) and returns the matched
* characters as a string. If the given text is null, an empty string will be returned. This method will actively try
* to avoid duplicates (if requested), and try to use alternatives, and throw an exception in case it was not possible
* to return unique values. In case duplicates are allowed, the first possible replacement value will be used,
* leading to all 1:1 replacements being of the same character.
* The length of the string might not be equal to the length of the provided string, because sometimes multiple
* characters are combined into one unicode char.
* @throws ReactDuplicateCharacterException In case it was not possible to replace all text with appropriate unicode
* in case there too many duplicated characters
* @param text The text to convert
* @param allowDuplicates Whether or not to allow duplicates
* @return A string of unicode characters which look similar to the individual characters from the text
*/
String convertTextToEmojisAsString(String text, boolean allowDuplicates);
}