mirror of
https://github.com/Sheldan/Sissi.git
synced 2026-01-26 19:21:43 +00:00
[RAB-2] adding slash commands to quote comands
This commit is contained in:
@@ -4,9 +4,12 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
|||||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.SlashCommandConfig;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
@@ -14,6 +17,7 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
|||||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
|
import dev.sheldan.sissi.module.quotes.config.QuoteSlashCommandNames;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
||||||
@@ -21,6 +25,8 @@ import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
|||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -33,6 +39,9 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
@Component
|
@Component
|
||||||
public class QuoteCommand extends AbstractConditionableCommand {
|
public class QuoteCommand extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String QUOTE_COMMAND = "quote";
|
||||||
|
private static final String MEMBER_PARAMETER = "member";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
|
|
||||||
@@ -48,6 +57,11 @@ public class QuoteCommand extends AbstractConditionableCommand {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private QuoteCommand self;
|
private QuoteCommand self;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
@@ -61,14 +75,10 @@ public class QuoteCommand extends AbstractConditionableCommand {
|
|||||||
AUserInAServer user = userInServerManagementService.loadOrCreateUser(targetMember);
|
AUserInAServer user = userInServerManagementService.loadOrCreateUser(targetMember);
|
||||||
foundQuote = quoteServiceBean.getRandomQuoteForMember(user);
|
foundQuote = quoteServiceBean.getRandomQuoteForMember(user);
|
||||||
}
|
}
|
||||||
if(foundQuote.isPresent()) {
|
Quote quoteToDisplay = foundQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
Quote quoteToDisplay = foundQuote.get();
|
|
||||||
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
} else {
|
|
||||||
throw new QuoteNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -76,15 +86,55 @@ public class QuoteCommand extends AbstractConditionableCommand {
|
|||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
Optional<Quote> foundQuote;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
|
||||||
|
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
|
||||||
|
AUserInAServer user = userInServerManagementService.loadOrCreateUser(targetMember);
|
||||||
|
foundQuote = quoteServiceBean.getRandomQuoteForMember(user);
|
||||||
|
} else {
|
||||||
|
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
||||||
|
foundQuote = quoteServiceBean.getRandomQuote(server);
|
||||||
|
}
|
||||||
|
Quote quoteToDisplay = foundQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
|
.thenCompose(messageToSend -> self.replyMessage(event, messageToSend))
|
||||||
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CompletableFuture<InteractionHook> replyMessage(SlashCommandInteractionEvent event, MessageToSend messageToSend) {
|
||||||
|
return interactionService.replyMessageToSend(messageToSend, event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandConfiguration getConfiguration() {
|
public CommandConfiguration getConfiguration() {
|
||||||
Parameter memberParameter = Parameter.builder().templated(true).name("member").type(Member.class).optional(true).build();
|
Parameter memberParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEMBER_PARAMETER)
|
||||||
|
.type(Member.class)
|
||||||
|
.optional(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(QuoteSlashCommandNames.QUOTE)
|
||||||
|
.commandName("random")
|
||||||
|
.build();
|
||||||
|
|
||||||
List<Parameter> parameters = Collections.singletonList(memberParameter);
|
List<Parameter> parameters = Collections.singletonList(memberParameter);
|
||||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
return CommandConfiguration.builder()
|
return CommandConfiguration.builder()
|
||||||
.name("quote")
|
.name(QUOTE_COMMAND)
|
||||||
.module(QuotesModuleDefinition.QUOTES)
|
.module(QuotesModuleDefinition.QUOTES)
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
.async(true)
|
.async(true)
|
||||||
.supportsEmbedException(true)
|
.supportsEmbedException(true)
|
||||||
.causesReaction(false)
|
.causesReaction(false)
|
||||||
|
|||||||
@@ -4,29 +4,45 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
|||||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.SlashCommandConfig;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import dev.sheldan.sissi.module.quotes.config.QuoteSlashCommandNames;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class QuoteDelete extends AbstractConditionableCommand {
|
public class QuoteDelete extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String QUOTE_DELETE_COMMAND = "quoteDelete";
|
||||||
|
private static final String QUOTE_ID_PARAMETER = "quoteId";
|
||||||
|
private static final String QUOTE_DELETE_RESPONSE = "quoteDelete_response";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerManagementService serverManagementService;
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(CommandContext commandContext) {
|
public CommandResult execute(CommandContext commandContext) {
|
||||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
@@ -36,15 +52,41 @@ public class QuoteDelete extends AbstractConditionableCommand {
|
|||||||
return CommandResult.fromSuccess();
|
return CommandResult.fromSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
Long quoteId = slashCommandParameterService.getCommandOption(QUOTE_ID_PARAMETER, event, Integer.class).longValue();
|
||||||
|
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
||||||
|
quoteServiceBean.deleteQuote(quoteId, server);
|
||||||
|
return interactionService.replyEmbed(QUOTE_DELETE_RESPONSE, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandConfiguration getConfiguration() {
|
public CommandConfiguration getConfiguration() {
|
||||||
Parameter quoteIdParameter = Parameter.builder().templated(true).name("quoteId").type(Long.class).build();
|
Parameter quoteIdParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(QUOTE_ID_PARAMETER)
|
||||||
|
.type(Long.class)
|
||||||
|
.build();
|
||||||
List<Parameter> parameters = Collections.singletonList(quoteIdParameter);
|
List<Parameter> parameters = Collections.singletonList(quoteIdParameter);
|
||||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(QuoteSlashCommandNames.QUOTE_INTERNAL)
|
||||||
|
.commandName("delete")
|
||||||
|
.build();
|
||||||
|
|
||||||
return CommandConfiguration.builder()
|
return CommandConfiguration.builder()
|
||||||
.name("quoteDelete")
|
.name(QUOTE_DELETE_COMMAND)
|
||||||
.module(QuotesModuleDefinition.QUOTES)
|
.module(QuotesModuleDefinition.QUOTES)
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
.async(false)
|
.async(false)
|
||||||
.requiresConfirmation(true)
|
.requiresConfirmation(true)
|
||||||
.supportsEmbedException(true)
|
.supportsEmbedException(true)
|
||||||
|
|||||||
@@ -4,20 +4,26 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
|||||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.SlashCommandConfig;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
|
import dev.sheldan.sissi.module.quotes.config.QuoteSlashCommandNames;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
||||||
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -30,19 +36,27 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
@Component
|
@Component
|
||||||
public class QuoteGet extends AbstractConditionableCommand {
|
public class QuoteGet extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String QUOTE_GET_COMMAND = "quoteGet";
|
||||||
|
private static final String QUOTE_ID_PARAMETER = "quoteId";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerManagementService serverManagementService;
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChannelService channelService;
|
private ChannelService channelService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteGet self;
|
private QuoteGet self;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
@@ -50,14 +64,10 @@ public class QuoteGet extends AbstractConditionableCommand {
|
|||||||
AServer server = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
|
AServer server = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
|
||||||
|
|
||||||
Optional<Quote> possibleQuote = quoteServiceBean.getQuote(quoteId, server);
|
Optional<Quote> possibleQuote = quoteServiceBean.getQuote(quoteId, server);
|
||||||
if(possibleQuote.isPresent()) {
|
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
Quote quoteToDisplay = possibleQuote.get();
|
|
||||||
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
} else {
|
|
||||||
throw new QuoteNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -65,15 +75,49 @@ public class QuoteGet extends AbstractConditionableCommand {
|
|||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
Long quoteId = slashCommandParameterService.getCommandOption(QUOTE_ID_PARAMETER, event, Integer.class).longValue();
|
||||||
|
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
||||||
|
|
||||||
|
Optional<Quote> possibleQuote = quoteServiceBean.getQuote(quoteId, server);
|
||||||
|
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
|
.thenCompose(messageToSend -> self.replySlashCommand(event, messageToSend))
|
||||||
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CompletableFuture<InteractionHook> replySlashCommand(SlashCommandInteractionEvent event, MessageToSend messageToSend) {
|
||||||
|
return interactionService.replyMessageToSend(messageToSend, event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandConfiguration getConfiguration() {
|
public CommandConfiguration getConfiguration() {
|
||||||
Parameter quoteIdParameter = Parameter.builder().templated(true).name("quoteId").type(Long.class).build();
|
Parameter quoteIdParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(QUOTE_ID_PARAMETER)
|
||||||
|
.type(Long.class)
|
||||||
|
.build();
|
||||||
List<Parameter> parameters = Collections.singletonList(quoteIdParameter);
|
List<Parameter> parameters = Collections.singletonList(quoteIdParameter);
|
||||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(QuoteSlashCommandNames.QUOTE)
|
||||||
|
.commandName("get")
|
||||||
|
.build();
|
||||||
|
|
||||||
return CommandConfiguration.builder()
|
return CommandConfiguration.builder()
|
||||||
.name("quoteGet")
|
.name(QUOTE_GET_COMMAND)
|
||||||
.module(QuotesModuleDefinition.QUOTES)
|
.module(QuotesModuleDefinition.QUOTES)
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
.async(true)
|
.async(true)
|
||||||
.supportsEmbedException(true)
|
.supportsEmbedException(true)
|
||||||
.causesReaction(false)
|
.causesReaction(false)
|
||||||
|
|||||||
@@ -4,20 +4,26 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
|||||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.SlashCommandConfig;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
|
import dev.sheldan.sissi.module.quotes.config.QuoteSlashCommandNames;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
||||||
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
||||||
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -30,6 +36,9 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
@Component
|
@Component
|
||||||
public class QuoteSearch extends AbstractConditionableCommand {
|
public class QuoteSearch extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String QUOTE_SEARCH_COMMAND = "quoteSearch";
|
||||||
|
private static final String QUERY_PARAMETER = "query";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
|
|
||||||
@@ -42,6 +51,12 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private QuoteSearch self;
|
private QuoteSearch self;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
@@ -49,14 +64,10 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
AServer server = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
|
AServer server = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
|
||||||
|
|
||||||
Optional<Quote> possibleQuote = quoteServiceBean.searchQuote(query, server);
|
Optional<Quote> possibleQuote = quoteServiceBean.searchQuote(query, server);
|
||||||
if(possibleQuote.isPresent()) {
|
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
Quote quoteToDisplay = possibleQuote.get();
|
|
||||||
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
.thenCompose(messageToSend -> self.sendMessageToChannel(messageToSend, commandContext.getChannel()))
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
} else {
|
|
||||||
throw new QuoteNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -64,15 +75,49 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, messageChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
String query = slashCommandParameterService.getCommandOption(QUERY_PARAMETER, event, String.class);
|
||||||
|
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
||||||
|
|
||||||
|
Optional<Quote> possibleQuote = quoteServiceBean.searchQuote(query, server);
|
||||||
|
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
|
.thenCompose(messageToSend -> self.replyMessage(event, messageToSend))
|
||||||
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CompletableFuture<InteractionHook> replyMessage(SlashCommandInteractionEvent event, MessageToSend messageToSend) {
|
||||||
|
return interactionService.replyMessageToSend(messageToSend, event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandConfiguration getConfiguration() {
|
public CommandConfiguration getConfiguration() {
|
||||||
Parameter searchParameter = Parameter.builder().templated(true).name("query").type(String.class).build();
|
Parameter searchParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(QUERY_PARAMETER)
|
||||||
|
.type(String.class)
|
||||||
|
.build();
|
||||||
List<Parameter> parameters = Collections.singletonList(searchParameter);
|
List<Parameter> parameters = Collections.singletonList(searchParameter);
|
||||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(QuoteSlashCommandNames.QUOTE)
|
||||||
|
.commandName("search")
|
||||||
|
.build();
|
||||||
|
|
||||||
return CommandConfiguration.builder()
|
return CommandConfiguration.builder()
|
||||||
.name("quoteSearch")
|
.name(QUOTE_SEARCH_COMMAND)
|
||||||
.module(QuotesModuleDefinition.QUOTES)
|
.module(QuotesModuleDefinition.QUOTES)
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
.async(true)
|
.async(true)
|
||||||
.supportsEmbedException(true)
|
.supportsEmbedException(true)
|
||||||
.causesReaction(false)
|
.causesReaction(false)
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
|||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
import dev.sheldan.sissi.module.quotes.config.QuotesFeatureDefinition;
|
||||||
@@ -14,6 +16,7 @@ import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
|||||||
import dev.sheldan.sissi.module.quotes.model.command.QuoteStatsModel;
|
import dev.sheldan.sissi.module.quotes.model.command.QuoteStatsModel;
|
||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -24,13 +27,21 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
@Component
|
@Component
|
||||||
public class QuoteStats extends AbstractConditionableCommand {
|
public class QuoteStats extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String QUOTE_STATS_COMMAND = "quoteStats";
|
||||||
|
private static final String MEMBER_PARAMETER = "member";
|
||||||
|
private static final String QUOTE_STATS_RESPONSE_TEMPLATE_KEY = "quoteStats_response";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChannelService channelService;
|
private ChannelService channelService;
|
||||||
|
|
||||||
private static final String QUOTE_STATS_RESPONSE_TEMPLATE_KEY = "quoteStats_response";
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
@@ -46,13 +57,35 @@ public class QuoteStats extends AbstractConditionableCommand {
|
|||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
Member target;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
|
||||||
|
target = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
|
||||||
|
} else {
|
||||||
|
target = event.getMember();
|
||||||
|
}
|
||||||
|
QuoteStatsModel model = quoteServiceBean.getQuoteStats(target);
|
||||||
|
return interactionService.replyEmbed(QUOTE_STATS_RESPONSE_TEMPLATE_KEY, model, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandConfiguration getConfiguration() {
|
public CommandConfiguration getConfiguration() {
|
||||||
Parameter searchParameter = Parameter.builder().templated(true).name("member").type(Member.class).optional(true).build();
|
Parameter searchParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEMBER_PARAMETER)
|
||||||
|
.type(Member.class)
|
||||||
|
.optional(true)
|
||||||
|
.build();
|
||||||
List<Parameter> parameters = Collections.singletonList(searchParameter);
|
List<Parameter> parameters = Collections.singletonList(searchParameter);
|
||||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
return CommandConfiguration.builder()
|
return CommandConfiguration.builder()
|
||||||
.name("quoteStats")
|
.name(QUOTE_STATS_COMMAND)
|
||||||
.module(QuotesModuleDefinition.QUOTES)
|
.module(QuotesModuleDefinition.QUOTES)
|
||||||
.templated(true)
|
.templated(true)
|
||||||
.async(true)
|
.async(true)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package dev.sheldan.sissi.module.quotes.config;
|
||||||
|
|
||||||
|
public class QuoteSlashCommandNames {
|
||||||
|
public static final String QUOTE = "quote";
|
||||||
|
public static final String QUOTE_INTERNAL = "quoteInternal";
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"additionalMessage": "<@safe_include "quoteDelete_response_text"/>",
|
||||||
|
"messageConfig": {
|
||||||
|
"ephemeral": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Quote has been deleted.
|
||||||
Reference in New Issue
Block a user