Refactor command packages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-11-20 18:56:57 +01:00
parent 3474593dc9
commit 913e8e023a
10 changed files with 44 additions and 31 deletions

View File

@ -65,9 +65,9 @@ public class HidekoBot
String botUserId = jda.getSelfUser().getId(); String botUserId = jda.getSelfUser().getId();
Configuration.setBotApplicationId(botUserId); Configuration.setBotApplicationId(botUserId);
// store if we have to force refresh commands despite no apparent changes.
boolean forceUpdateCommands = false; boolean forceUpdateCommands = false;
// if there is more than 1 arg, then iterate through them because we have additional things to do. // if there is more than 1 arg, then iterate through them because we have additional things to do.
// we are doing this at the end because we might need the API to be already initialized for some things. // we are doing this at the end because we might need the API to be already initialized for some things.
if(args.length > 1) { if(args.length > 1) {

View File

@ -0,0 +1,33 @@
package wtf.beatrice.hidekobot.commands.completer;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.commands.slash.AvatarCommand;
import java.util.ArrayList;
import java.util.List;
public class AvatarCompleter
{
public AvatarCompleter(@NotNull CommandAutoCompleteInteractionEvent event)
{
if(event.getFocusedOption().getName().equals("size"))
{
List<Command.Choice> options = new ArrayList<>();
for(int res : AvatarCommand.acceptedSizes)
{
String resString = String.valueOf(res);
String userInput = event.getFocusedOption().getValue();
if(resString.startsWith(userInput))
options.add(new Command.Choice(resString, res));
}
event.replyChoices(options).queue();
}
}
}

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.MessageHistory;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.hidekobot.slashcommands; package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -2,11 +2,7 @@ package wtf.beatrice.hidekobot.listeners;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.Command; import wtf.beatrice.hidekobot.commands.completer.AvatarCompleter;
import wtf.beatrice.hidekobot.slashcommands.AvatarCommand;
import java.util.ArrayList;
import java.util.List;
public class SlashCommandCompleter extends ListenerAdapter public class SlashCommandCompleter extends ListenerAdapter
{ {
@ -14,24 +10,8 @@ public class SlashCommandCompleter extends ListenerAdapter
@Override @Override
public void onCommandAutoCompleteInteraction(CommandAutoCompleteInteractionEvent event) public void onCommandAutoCompleteInteraction(CommandAutoCompleteInteractionEvent event)
{ {
if(event.getName().equals("avatar")) switch (event.getName().toLowerCase()) {
{ case "avatar" -> new AvatarCompleter(event);
if(event.getFocusedOption().getName().equals("size"))
{
List<Command.Choice> options = new ArrayList<>();
for(int res : AvatarCommand.acceptedSizes)
{
String resString = String.valueOf(res);
String userInput = event.getFocusedOption().getValue();
if(resString.startsWith(userInput))
options.add(new Command.Choice(resString, res));
}
event.replyChoices(options).queue();
}
} }
} }
} }

View File

@ -3,7 +3,7 @@ package wtf.beatrice.hidekobot.listeners;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.slashcommands.*; import wtf.beatrice.hidekobot.commands.slash.*;
public class SlashCommandListener extends ListenerAdapter public class SlashCommandListener extends ListenerAdapter
{ {