mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-17 04:29:13 +00:00
[AB-77] moving the templating module into the core module
adding a possibility to overlay specific templates for particular servers adding commands to configure templates adding file parameter support
This commit is contained in:
@@ -62,17 +62,17 @@ public class DeletedEmoteStats extends AbstractConditionableCommand {
|
||||
// only show the embed, if there are static emotes to show
|
||||
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
|
||||
log.trace("Deleted emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
// only show the embed, if there are animated emotes to show
|
||||
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
|
||||
log.trace("Deleted emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
// if neither static nor animated emote stats are available, show an embed indicating so
|
||||
if(!emoteStatsModel.areStatsAvailable()) {
|
||||
log.info("No delete emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
}
|
||||
|
||||
return FutureUtils.toSingleFutureGeneric(messagePromises)
|
||||
|
||||
@@ -63,17 +63,17 @@ public class EmoteStats extends AbstractConditionableCommand {
|
||||
// only show embed if static emote stats are available
|
||||
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
|
||||
log.trace("Emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
// only show embed if animated emote stats are available
|
||||
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
|
||||
log.trace("Emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
// show an embed if no emote stats are available indicating so
|
||||
if(!emoteStatsModel.areStatsAvailable()) {
|
||||
log.info("No emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
}
|
||||
|
||||
return FutureUtils.toSingleFutureGeneric(messagePromises)
|
||||
|
||||
@@ -8,19 +8,19 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.UploadFileTooLargeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FileUtils;
|
||||
import dev.sheldan.abstracto.core.utils.FileService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.exception.DownloadEmoteStatsFileTooBigException;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.DownloadEmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -37,7 +37,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
/**
|
||||
* This command renders a file containing information about emote statistics and provides the file as a download.
|
||||
* If the file size is over the size limit of the {@link net.dv8tion.jda.api.entities.Guild}, this command will fail, but
|
||||
* throw an {@link DownloadEmoteStatsFileTooBigException}.
|
||||
* throw an {@link UploadFileTooLargeException}.
|
||||
* This will create a temporary file on the server, which will be deleted after it has been send.
|
||||
*/
|
||||
@Component
|
||||
@@ -61,7 +61,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
private UsedEmoteManagementService usedEmoteManagementService;
|
||||
|
||||
@Autowired
|
||||
private FileUtils fileUtils;
|
||||
private FileService fileService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
@@ -77,7 +77,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
List<UsedEmote> usedEmotes = usedEmoteManagementService.loadEmoteUsagesForServerSince(actualServer, statsSince);
|
||||
// if there are no stats available, render a message indicating so
|
||||
if(usedEmotes.isEmpty()) {
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY, new Object(), commandContext.getChannel()))
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY, new Object(), commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
// info might not be nice to handle in the template, and 1970 would look weird to users
|
||||
@@ -93,13 +93,13 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
.build();
|
||||
String fileName = templateService.renderTemplate(DOWNLOAD_EMOTE_STATS_FILE_NAME_TEMPLATE_KEY, model);
|
||||
String fileContent = templateService.renderTemplate(DOWNLOAD_EMOTE_STATS_FILE_CONTENT_TEMPLATE_KEY, model);
|
||||
File tempFile = fileUtils.createTempFile(fileName);
|
||||
File tempFile = fileService.createTempFile(fileName);
|
||||
try {
|
||||
fileUtils.writeContentToFile(tempFile, fileContent);
|
||||
fileService.writeContentToFile(tempFile, fileContent);
|
||||
long maxFileSize = commandContext.getGuild().getMaxFileSize();
|
||||
// in this case, we cannot upload the file, so we need to fail
|
||||
if(maxFileSize < tempFile.length()) {
|
||||
throw new DownloadEmoteStatsFileTooBigException(tempFile.length(), maxFileSize);
|
||||
if(tempFile.length() > maxFileSize) {
|
||||
throw new UploadFileTooLargeException(tempFile.length(), maxFileSize);
|
||||
}
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(DOWNLOAD_EMOTE_STATS_RESPONSE_TEMPLATE_KEY, model);
|
||||
messageToSend.setFileToSend(tempFile);
|
||||
@@ -109,7 +109,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
throw new AbstractoRunTimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
fileUtils.safeDelete(tempFile);
|
||||
fileService.safeDelete(tempFile);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to delete temporary export emote statistics file {}.", tempFile.getAbsoluteFile(), e);
|
||||
}
|
||||
|
||||
@@ -66,19 +66,19 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
|
||||
// only show embed if static emote stats are available
|
||||
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
|
||||
log.trace("External emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show embed if animated emote stats are available
|
||||
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
|
||||
log.trace("External emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// show an embed if no emote stats are available indicating so
|
||||
if(!emoteStatsModel.areStatsAvailable()) {
|
||||
log.info("No external emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
}
|
||||
|
||||
return FutureUtils.toSingleFutureGeneric(messagePromises)
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
|
||||
if(!trackedEmote.getExternal()) {
|
||||
throw new AbstractoTemplatedException("Emote is not external", "showExternalTrackedEmote_emote_is_not_external");
|
||||
}
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, trackedEmote, commandContext.getChannel()))
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, trackedEmote, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
|
||||
@@ -63,25 +63,25 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
|
||||
// only show the embed, if there are static tracked emotes
|
||||
if(!trackedEmoteOverview.getStaticEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed if there are animated tracked emotes
|
||||
if(!trackedEmoteOverview.getAnimatedEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed, if there are deleted static emotes
|
||||
if(!trackedEmoteOverview.getDeletedStaticEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed, if there are deleted animated emotes
|
||||
if(!trackedEmoteOverview.getDeletedAnimatedEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, commandContext.getGuild().getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
@@ -92,19 +92,19 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
|
||||
// only show the embed if there are external static emotes
|
||||
if(!trackedEmoteOverview.getExternalStaticEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed if there are external animated emotes
|
||||
if(!trackedEmoteOverview.getExternalAnimatedEmotes().isEmpty()) {
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
}
|
||||
|
||||
// if there are no tracked emotes available, show an embed indicating so
|
||||
if(noTrackedEmotesAvailable) {
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
|
||||
}
|
||||
return FutureUtils.toSingleFutureGeneric(messagePromises)
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SyncTrackedEmotes extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
TrackedEmoteSynchronizationResult syncResult = trackedEmoteService.synchronizeTrackedEmotes(commandContext.getGuild());
|
||||
// show a result of how many emotes were deleted/added
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, syncResult, commandContext.getChannel()))
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, syncResult, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.command.parameter.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.handler.CommandParameterHandler;
|
||||
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
|
||||
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
|
||||
@@ -47,12 +48,12 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
|
||||
* does not need to actually exist.
|
||||
*/
|
||||
@Override
|
||||
public Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context) {
|
||||
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Class clazz, Message context) {
|
||||
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, Emote.class, context);
|
||||
if(emote != null) {
|
||||
return trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild());
|
||||
} else {
|
||||
long trackedEmoteId = Long.parseLong(input);
|
||||
long trackedEmoteId = Long.parseLong((String) input.getValue());
|
||||
return trackedEmoteService.getFakeTrackedEmote(trackedEmoteId, context.getGuild());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.command.parameter.handler;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
|
||||
import dev.sheldan.abstracto.core.command.handler.CommandParameterHandler;
|
||||
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
|
||||
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
|
||||
@@ -50,14 +51,14 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
|
||||
* used directly. In every successful case, it will contain a faked {@link TrackedEmote}.
|
||||
*/
|
||||
@Override
|
||||
public Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context) {
|
||||
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Class clazz, Message context) {
|
||||
TrackEmoteParameter parameter = TrackEmoteParameter.builder().build();
|
||||
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, Emote.class, context);
|
||||
if(emote != null) {
|
||||
parameter.setEmote(emote);
|
||||
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild()));
|
||||
} else {
|
||||
long trackedEmoteId = Long.parseLong(input);
|
||||
long trackedEmoteId = Long.parseLong((String) input.getValue());
|
||||
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(trackedEmoteId, context.getGuild()));
|
||||
}
|
||||
return parameter;
|
||||
|
||||
Reference in New Issue
Block a user