-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform rename slot to a slash command
- Loading branch information
1 parent
0a22e1a
commit f367d5c
Showing
8 changed files
with
67 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 34 additions & 22 deletions
56
src/main/java/de/webalf/slotbot/service/bot/command/event/RenameSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
package de.webalf.slotbot.service.bot.command.event; | ||
|
||
import de.webalf.slotbot.model.annotations.bot.Command; | ||
import de.webalf.slotbot.model.annotations.bot.SlashCommand; | ||
import de.webalf.slotbot.model.bot.TranslatableOptionData; | ||
import de.webalf.slotbot.service.bot.EventBotService; | ||
import de.webalf.slotbot.service.bot.command.DiscordCommand; | ||
import de.webalf.slotbot.service.bot.command.DiscordSlashCommand; | ||
import de.webalf.slotbot.util.bot.DiscordLocaleHelper; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.Permission; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
|
||
import java.util.List; | ||
|
||
import static de.webalf.slotbot.util.StringUtils.onlyNumbers; | ||
import static de.webalf.slotbot.util.bot.MessageUtils.deleteMessagesInstant; | ||
import static de.webalf.slotbot.util.bot.MessageUtils.replyAndDelete; | ||
import static de.webalf.slotbot.util.permissions.BotPermissionHelper.Authorization.EVENT_MANAGE; | ||
import static de.webalf.slotbot.util.bot.InteractionUtils.finishedVisibleInteraction; | ||
import static de.webalf.slotbot.util.bot.SlashCommandUtils.getIntegerOption; | ||
import static de.webalf.slotbot.util.bot.SlashCommandUtils.getStringOption; | ||
|
||
/** | ||
* @author Alf | ||
* @since 12.01.2021 | ||
*/ | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Command(names = {"renameSlot", "editSlot", "eventRenameSlot"}, | ||
description = "Ermöglicht es einen Slot umzubenennen.", | ||
usage = "<Slotnummer> \"<Slotname>\"", | ||
argCount = {2}, | ||
authorization = EVENT_MANAGE) | ||
public class RenameSlot implements DiscordCommand { | ||
@SlashCommand(name = "bot.slash.event.renameSlot", | ||
description = "bot.slash.event.renameSlot.description", | ||
authorization = Permission.MANAGE_CHANNEL, | ||
optionPosition = 0) | ||
public class RenameSlot implements DiscordSlashCommand { | ||
private final EventBotService eventBotService; | ||
|
||
private static final String OPTION_SLOT_NUMBER = "bot.slash.event.renameSlot.option.slotNumber"; | ||
private static final String OPTION_NAME = "bot.slash.event.renameSlot.option.name"; | ||
private static final List<List<TranslatableOptionData>> OPTIONS = List.of( | ||
List.of(new TranslatableOptionData(OptionType.INTEGER, OPTION_SLOT_NUMBER, "bot.slash.event.renameSlot.option.slotNumber.description", true), | ||
new TranslatableOptionData(OptionType.STRING, OPTION_NAME, "bot.slash.event.renameSlot.option.name.description", true)) | ||
); | ||
|
||
@Override | ||
public void execute(Message message, List<String> args) { | ||
log.trace("Command: renameslot"); | ||
public void execute(@NonNull SlashCommandInteractionEvent event, @NonNull DiscordLocaleHelper locale) { | ||
log.trace("Slash command: renameSlot"); | ||
|
||
final int slotNumber = getIntegerOption(event, OPTION_SLOT_NUMBER); | ||
final String name = getStringOption(event, OPTION_NAME); | ||
eventBotService.renameSlot(event.getChannel().getIdLong(), slotNumber, name); | ||
|
||
final String slotNumber = args.get(0); | ||
if (!onlyNumbers(slotNumber)) { | ||
replyAndDelete(message, "Die Slotnummer muss eine Zahl sein."); | ||
return; | ||
} | ||
finishedVisibleInteraction(event); | ||
} | ||
|
||
eventBotService.renameSlot(message.getChannel().getIdLong(), Integer.parseInt(slotNumber), args.get(1)); | ||
deleteMessagesInstant(message); | ||
@Override | ||
public List<TranslatableOptionData> getOptions(int optionPosition) { | ||
return OPTIONS.get(optionPosition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters