added error message logging to reaction post execution

added validation to post target command
added templates for post target command
moved ping and echo model to interface
added show emote command
This commit is contained in:
Sheldan
2020-03-22 12:34:52 +01:00
parent d95382b589
commit 8cd9068cfc
32 changed files with 154 additions and 17 deletions

View File

@@ -0,0 +1,53 @@
package dev.sheldan.abstracto.utility.command;
import dev.sheldan.abstracto.command.Command;
import dev.sheldan.abstracto.command.HelpInfo;
import dev.sheldan.abstracto.command.execution.*;
import dev.sheldan.abstracto.templating.TemplateService;
import dev.sheldan.abstracto.utility.Utility;
import dev.sheldan.abstracto.utility.models.template.ShowEmoteLog;
import net.dv8tion.jda.api.entities.Emote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class ShowEmote implements Command {
private static final String SHOW_EMOTE_RESPONSE_TEMPLATE = "showEmote_response";
@Autowired
private TemplateService templateService;
@Override
public Result execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
Object emoteParameter = parameters.get(0);
if(!(emoteParameter instanceof Emote)) {
return Result.fromError("No custom emote found.");
}
Emote emote = (Emote) emoteParameter;
ShowEmoteLog emoteLog = (ShowEmoteLog) ContextConverter.fromCommandContext(commandContext, ShowEmoteLog.class);
emoteLog.setEmote(emote);
String message = templateService.renderTemplate(SHOW_EMOTE_RESPONSE_TEMPLATE, emoteLog);
commandContext.getChannel().sendMessage(message).queue();
return Result.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder().name("emote").type(Emote.class).optional(false).build());
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("showEmote")
.module(Utility.UTILITY)
.templated(true)
.causesReaction(false)
.parameters(parameters)
.help(helpInfo)
.build();
}
}

View File

@@ -0,0 +1 @@
**Name**: ${emote.name} **Link**: ${emote.imageUrl}