added assignable role place module including: setting up, configuring, deleting commands and documentation

upgraded JDA version to 4.2.0
refactored multiple interfaces to be more convenient/contain more information (reaction added/removed now gets the actual event)
added generic way to check for conditions. these conditions are provided by modules and are loosely connected via condition context and a condition name
added changeable flag to emotes to indicate that they can be updated via setEmote
refactored emote parsing in command parameters, the command parameters will now contain a fake emote
added feature to embed templates for fields to force a new message regardless of the discord limit
added some more functionality to message and channel service regarding field edit/embed sending
introduced the full emote parameter, to have both the emote (if custom) and a fake aemote at hand
refactored some methods to already throw exceptions within the retrieval methods, instead of optionals which need to be dealt outside
changed getEmotes to getEmotesBag to have duplicates of emotes
fixed setEmote to behave correctly with new parameter types
fixed creation of emotes, which previously created additional instances
fixed templating multiple fields handling
refactored command handling to allow async commands, they are the same interface, but configuration dicates whether or not it is async
added generic exception reporting for async commands
refactored a bunch of service methods to be named optional, and the non optional methods throw exceptions in case nothing is found
added a few more customized exceptions
added clearing freemarker internal template cache to clear cache
added feature to skip, not use, embeds if they look to be empty (no fields, no description, no attachment)
added virtual env to gitignore
fixed initial sync of roles un-marking roles as deleted
added some convenience methods to remove reactions from users directly
fixed post command handling in case it is not a templatable instance
fixed exceptions without cause in generic exception model
This commit is contained in:
Sheldan
2020-07-23 02:22:58 +02:00
parent 5317199bf4
commit fd4d784081
201 changed files with 6547 additions and 527 deletions

View File

@@ -55,4 +55,6 @@ public class EmbedConfiguration {
* The message which is posted along the {@link net.dv8tion.jda.api.entities.MessageEmbed} as a normal message.
*/
private String additionalMessage;
private boolean preventEmptyEmbed = false;
}

View File

@@ -24,4 +24,5 @@ public class EmbedField {
* This means, if multiple fields can be put on the same height in the {@link net.dv8tion.jda.api.entities.MessageEmbed} this will be done by discord.
*/
private Boolean inline;
private Boolean forceNewMessage;
}

View File

@@ -28,6 +28,7 @@ import java.util.stream.Collectors;
@Component
public class TemplateServiceBean implements TemplateService {
public static final double MAX_FIELD_COUNT = 25D;
@Autowired
private Configuration configuration;
@@ -60,9 +61,9 @@ public class TemplateServiceBean implements TemplateService {
@Override
public MessageToSend renderEmbedTemplate(String key, Object model) {
String embedConfig = this.renderTemplate(key + "_embed", model);
EmbedConfiguration embedConfiguration = gson.fromJson(embedConfig, EmbedConfiguration.class);
List<EmbedBuilder> embedBuilders = new ArrayList<>();
embedBuilders.add(new EmbedBuilder());
EmbedConfiguration embedConfiguration = gson.fromJson(embedConfig, EmbedConfiguration.class);
String description = embedConfiguration.getDescription();
if(description != null) {
double neededIndices = Math.ceil(description.length() / (double) MessageEmbed.TEXT_MAX_LENGTH) - 1;
@@ -104,7 +105,7 @@ public class TemplateServiceBean implements TemplateService {
}
List<MessageEmbed> embeds = new ArrayList<>();
if(embedBuilders.size() > 1 || !embedBuilders.get(0).isEmpty()) {
if((embedBuilders.size() > 1 || !embedBuilders.get(0).isEmpty()) && !isEmptyEmbed(embedConfiguration)) {
embeds = embedBuilders.stream().map(EmbedBuilder::build).collect(Collectors.toList());
}
@@ -114,6 +115,13 @@ public class TemplateServiceBean implements TemplateService {
.build();
}
private boolean isEmptyEmbed(EmbedConfiguration configuration) {
if(configuration.isPreventEmptyEmbed()) {
return configuration.getFields() == null && configuration.getDescription() == null && configuration.getImageUrl() == null;
}
return false;
}
@Override
public MessageToSend renderTemplateToMessageToSend(String key, Object model) {
return MessageToSend.builder().message(renderTemplate(key, model)).build();
@@ -129,13 +137,24 @@ public class TemplateServiceBean implements TemplateService {
configuration.getFields().add(i + 1, secondPart);
}
}
double neededIndex = Math.ceil(configuration.getFields().size() / 25D) - 1;
extendIfNecessary(embedBuilders, neededIndex);
int actualCurrentIndex = 0;
int neededMessages = 0;
for (int i = 0; i < configuration.getFields().size(); i++) {
double currentPart = Math.floor(i / 25D);
EmbedField field = configuration.getFields().get(i);
boolean lastMessageInEmbed = ((actualCurrentIndex + 1) % MAX_FIELD_COUNT) == 0;
boolean isStartOfNewMessage = (actualCurrentIndex % MAX_FIELD_COUNT) == 0;
boolean newMessageForcedWithinEmbeds = Boolean.TRUE.equals(field.getForceNewMessage()) && !lastMessageInEmbed;
boolean startOfNewMessage = actualCurrentIndex != 0 && isStartOfNewMessage;
if(newMessageForcedWithinEmbeds || startOfNewMessage) {
actualCurrentIndex = 0;
neededMessages++;
} else {
actualCurrentIndex++;
}
extendIfNecessary(embedBuilders, neededMessages);
EmbedField embedField = configuration.getFields().get(i);
boolean inline = embedField.getInline() != null ? embedField.getInline() : Boolean.FALSE;
embedBuilders.get((int) currentPart).addField(embedField.getName(), embedField.getValue(), inline);
embedBuilders.get(neededMessages).addField(embedField.getName(), embedField.getValue(), inline);
}
}
@@ -221,4 +240,9 @@ public class TemplateServiceBean implements TemplateService {
public String renderTemplatable(Templatable templatable) {
return renderTemplate(templatable.getTemplateName(), templatable.getTemplateModel());
}
@Override
public void clearCache() {
configuration.getCacheStorage().clear();
}
}