Added sub commands for polls and did help command
This commit is contained in:
parent
311348dcf6
commit
c6bd15f141
|
|
@ -15,14 +15,13 @@ import java.net.URISyntaxException;
|
||||||
public class AltitudeBot {
|
public class AltitudeBot {
|
||||||
|
|
||||||
private JDA jda;
|
private JDA jda;
|
||||||
private PermissionManager permissionManager;
|
|
||||||
private static AltitudeBot instance;
|
private static AltitudeBot instance;
|
||||||
|
|
||||||
public static AltitudeBot getInstance() {
|
public static AltitudeBot getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void main(String args[]) {
|
public void main(String[] args) {
|
||||||
instance = this;
|
instance = this;
|
||||||
Logger.info("Starting bot...");
|
Logger.info("Starting bot...");
|
||||||
initConfigs();
|
initConfigs();
|
||||||
|
|
@ -36,7 +35,7 @@ public class AltitudeBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListeners() {
|
private void initListeners() {
|
||||||
jda.addEventListener(new CommandManager());
|
jda.addEventListener(new CommandManager(jda));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConfigs() {
|
private void initConfigs() {
|
||||||
|
|
@ -54,10 +53,6 @@ public class AltitudeBot {
|
||||||
return (null);
|
return (null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionManager getPermissionManager() {
|
|
||||||
return permissionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JDA getJDA() {
|
public JDA getJDA() {
|
||||||
return jda;
|
return jda;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,109 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.commands.CommandHelp;
|
||||||
|
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
||||||
import com.alttd.database.Database;
|
import com.alttd.database.Database;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
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 java.awt.*;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CommandManager extends ListenerAdapter {
|
public class CommandManager extends ListenerAdapter {
|
||||||
|
|
||||||
private final List<DiscordCommand> commands;
|
private final List<DiscordCommand> commands;
|
||||||
|
private final HashMap<String, List<ScopeInfo>> commandList = new HashMap<>();
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager(JDA jda) {
|
||||||
commands = List.of();
|
commands = List.of(new CommandHelp(jda, this),
|
||||||
|
new CommandPoll(jda, this));
|
||||||
|
loadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||||
|
Optional<DiscordCommand> first = commands.stream()
|
||||||
|
.filter(discordCommand -> discordCommand.getName().equalsIgnoreCase(event.getCommandString()))
|
||||||
|
.findFirst();
|
||||||
|
if (first.isEmpty()) {
|
||||||
|
event.replyEmbeds(new EmbedBuilder()
|
||||||
|
.setTitle("Invalid command")
|
||||||
|
.setDescription("We couldn't find this command, please report this issue to a Teri")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.build())
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
first.get().execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInteractionEvent event) {
|
||||||
|
Optional<DiscordCommand> first = commands.stream()
|
||||||
|
.filter(discordCommand -> discordCommand.getName().equalsIgnoreCase(event.getCommandString()))
|
||||||
|
.findFirst();
|
||||||
|
if (first.isEmpty())
|
||||||
|
return;
|
||||||
|
first.get().suggest(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DiscordCommand> getCommands() {
|
public List<DiscordCommand> getCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ScopeInfo> getActiveLocations(String command) { //TODO make this cache results
|
public List<DiscordCommand> getCommands(TextChannel textChannel) {
|
||||||
String sql = "SELECT FROM commands WHERE command_name = ?";
|
return commands.stream().filter(command -> {
|
||||||
List<ScopeInfo> scopeInfoList = new ArrayList<>();
|
List<ScopeInfo> scopeInfoList = commandList.get(command.getName());
|
||||||
|
for (ScopeInfo scopeInfo : scopeInfoList) {
|
||||||
|
switch (scopeInfo.getScope()) {
|
||||||
|
case GLOBAL -> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case GUILD -> {
|
||||||
|
if (textChannel.getGuild().getIdLong() == scopeInfo.getId())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadCommands() {
|
||||||
|
String sql = "SELECT * FROM commands";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
statement.setString(1, command.toLowerCase());
|
|
||||||
|
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
String commandName = resultSet.getString("command_name");
|
||||||
|
List<ScopeInfo> scopeInfoList = commandList.getOrDefault(commandName, new ArrayList<>());
|
||||||
scopeInfoList.add(new ScopeInfo(
|
scopeInfoList.add(new ScopeInfo(
|
||||||
CommandScope.valueOf(resultSet.getString("scope")),
|
CommandScope.valueOf(resultSet.getString("scope")),
|
||||||
resultSet.getLong("location_id")));
|
resultSet.getLong("location_id")));
|
||||||
|
commandList.put(commandName, scopeInfoList);
|
||||||
}
|
}
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
Logger.sql(exception);
|
Logger.sql(exception);
|
||||||
}
|
}
|
||||||
return scopeInfoList;
|
}
|
||||||
|
|
||||||
|
public List<ScopeInfo> getActiveLocations(String command) {
|
||||||
|
return commandList.getOrDefault(command, new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public abstract class DiscordCommand {
|
public abstract class DiscordCommand {
|
||||||
|
|
@ -12,6 +13,8 @@ public abstract class DiscordCommand {
|
||||||
|
|
||||||
public abstract void execute(SlashCommandInteractionEvent event);
|
public abstract void execute(SlashCommandInteractionEvent event);
|
||||||
|
|
||||||
|
public abstract void suggest(CommandAutoCompleteInteractionEvent event);
|
||||||
|
|
||||||
public abstract String getHelpMessage();
|
public abstract String getHelpMessage();
|
||||||
|
|
||||||
public String getExtendedHelpMessage() {
|
public String getExtendedHelpMessage() {
|
||||||
|
|
|
||||||
|
|
@ -1,81 +1,121 @@
|
||||||
//package com.alttd.commandManager.commands;
|
package com.alttd.commandManager.commands;
|
||||||
//
|
|
||||||
//import com.alttd.AltitudeBot;
|
import com.alttd.commandManager.CommandManager;
|
||||||
//import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
//import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.config.MessagesConfig;
|
||||||
//import com.alttd.config.MessagesConfig;
|
import com.alttd.permissions.PermissionManager;
|
||||||
//import com.alttd.permissions.PermissionManager;
|
import com.alttd.templates.Parser;
|
||||||
//import com.alttd.templates.Parser;
|
import com.alttd.templates.Template;
|
||||||
//import com.alttd.templates.Template;
|
import com.alttd.util.Util;
|
||||||
//import com.alttd.util.Logger;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
//import com.alttd.util.Util;
|
import net.dv8tion.jda.api.JDA;
|
||||||
//import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
//import net.dv8tion.jda.api.entities.PrivateChannel;
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
//import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
//import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.interactions.AutoCompleteQuery;
|
||||||
//
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
//import java.util.List;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
//import java.util.Optional;
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
//
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
//public class CommandHelp extends DiscordCommand {
|
|
||||||
//
|
import java.awt.*;
|
||||||
// private final CommandManager commandManager;
|
import java.util.List;
|
||||||
//
|
import java.util.Optional;
|
||||||
// public CommandHelp(CommandManager commandManager) {
|
import java.util.stream.Collectors;
|
||||||
// this.commandManager = commandManager;
|
|
||||||
// }
|
public class CommandHelp extends DiscordCommand {
|
||||||
//
|
|
||||||
// @Override
|
private final CommandManager commandManager;
|
||||||
// public String getName() {
|
|
||||||
// return "help";
|
public CommandHelp(JDA jda, CommandManager commandManager) {
|
||||||
// }
|
this.commandManager = commandManager;
|
||||||
//
|
|
||||||
// @Override
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Show info about all commands or a specific command.")
|
||||||
// public String execute(String[] args, Member commandSource, TextChannel textChannel) {
|
.addOption(OptionType.STRING, "command", "Command to get more info about", true , true);
|
||||||
// return execute(args, textChannel, commandSource.getIdLong(), textChannel.getGuild().getIdLong(), Util.getGroupIds(commandSource));
|
|
||||||
// }
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public String execute(String[] args, User commandSource, TextChannel textChannel) {
|
@Override
|
||||||
// if (!(textChannel instanceof PrivateChannel))
|
public String getName() {
|
||||||
// Logger.warning("Using User when executing command on Member: % Command: %", commandSource.getAsMention(), getName());
|
return "help";
|
||||||
// return execute(args, textChannel, commandSource.getIdLong(), 0, null);
|
}
|
||||||
// }
|
|
||||||
//
|
@Override
|
||||||
// public String execute(String[] args, TextChannel textChannel, long userId, long guildId, List<Long> groupIds) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
// PermissionManager permissionManager = AltitudeBot.getInstance().getPermissionManager();
|
PermissionManager permissionManager = PermissionManager.getInstance();
|
||||||
// StringBuilder helpMessage = new StringBuilder();
|
|
||||||
// if (args.length == 0) {
|
if (permissionManager.hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
// commandManager.getCommands().stream()
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
// .filter(command -> permissionManager.hasPermission(
|
return;
|
||||||
// textChannel,
|
}
|
||||||
// userId,
|
|
||||||
// groupIds,
|
StringBuilder helpMessage = new StringBuilder();
|
||||||
// command.getPermission()))
|
List<OptionMapping> options = event.getOptions();
|
||||||
// .forEach(command -> helpMessage.append(command.getHelpMessage()));
|
TextChannel textChannel = event.getTextChannel();
|
||||||
// } else {
|
if (options.size() == 0) {
|
||||||
// String arg = args[0].toLowerCase();
|
commandManager.getCommands(textChannel).stream()
|
||||||
// Optional<DiscordCommand> first = commandManager.getCommands().stream()
|
.filter(command -> permissionManager.hasPermission(
|
||||||
// .filter(command -> command.getName().equals(arg)
|
textChannel,
|
||||||
// || command.getAliases().contains(arg)).findFirst();
|
event.getUser().getIdLong(),
|
||||||
// if (first.isEmpty())
|
Util.getGroupIds(event.getMember()),
|
||||||
// return Parser.parse(MessagesConfig.INVALID_COMMAND_ARGS,
|
command.getPermission()))
|
||||||
// Template.of("args", arg),
|
.forEach(command -> helpMessage.append(command.getHelpMessage()));
|
||||||
// Template.of("command", getName()),
|
} else {
|
||||||
// Template.of("prefix", commandManager.getPrefix(guildId)));
|
OptionMapping optionMapping = event.getOption("command");
|
||||||
// DiscordCommand discordCommand = first.get();
|
if (optionMapping == null) {
|
||||||
// helpMessage.append(discordCommand.getExtendedHelpMessage());
|
event.replyEmbeds(new EmbedBuilder()
|
||||||
// }
|
.setTitle("Error")
|
||||||
// return Parser.parse(MessagesConfig.HELP_MESSAGE_TEMPLATE, Template.of("commands", helpMessage.toString()));
|
.setDescription("Missing command option")
|
||||||
// }
|
.setColor(Color.RED)
|
||||||
//
|
.build())
|
||||||
// @Override
|
.setEphemeral(true)
|
||||||
// public String getHelpMessage() {
|
.queue();
|
||||||
// return MessagesConfig.HELP_HELP;
|
return;
|
||||||
// }
|
}
|
||||||
//
|
String command = optionMapping.getAsString();
|
||||||
// @Override
|
Optional<DiscordCommand> first = commandManager.getCommands().stream()
|
||||||
// public List<String> getAliases() {
|
.filter(discordCommand -> discordCommand.getName().equals(command)).findFirst();
|
||||||
// return null;
|
if (first.isEmpty())
|
||||||
// }
|
{
|
||||||
//}
|
event.replyEmbeds(new EmbedBuilder()
|
||||||
|
.setTitle("Command Not Found")
|
||||||
|
.setDescription("Unable to find the `" + command + "` command.")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.build())
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
helpMessage.append(first.get().getExtendedHelpMessage());
|
||||||
|
}
|
||||||
|
event.replyEmbeds(new EmbedBuilder()
|
||||||
|
.setTitle("Help")
|
||||||
|
.setDescription(Parser.parse(MessagesConfig.HELP_MESSAGE_TEMPLATE, Template.of("commands", helpMessage.toString())))
|
||||||
|
.setColor(Color.GREEN)
|
||||||
|
.build())
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
AutoCompleteQuery focusedOption = event.getFocusedOption();
|
||||||
|
if (!focusedOption.getType().equals(OptionType.STRING) || !focusedOption.getName().equals("command"))
|
||||||
|
return;
|
||||||
|
String value = focusedOption.getValue().toLowerCase();
|
||||||
|
List<String> collect = commandManager.getCommands().stream()
|
||||||
|
.map(DiscordCommand::getName)
|
||||||
|
.filter(name -> name.toLowerCase().startsWith(value))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (int i = collect.size(); i > 25; i--) //Can only have 25 options
|
||||||
|
collect.remove(i - 1);
|
||||||
|
event.replyChoiceStrings(collect).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return MessagesConfig.HELP_HELP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,27 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.ScopeInfo;
|
import com.alttd.commandManager.SubCommand;
|
||||||
import com.alttd.permissions.PermissionManager;
|
import com.alttd.permissions.PermissionManager;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import net.dv8tion.jda.api.requests.RestAction;
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class CommandPoll extends DiscordCommand {
|
public class CommandPoll extends DiscordCommand {
|
||||||
|
|
||||||
private final CommandManager commandManager;
|
private final HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPoll(JDA jda, CommandManager commandManager) {
|
public CommandPoll(JDA jda, CommandManager commandManager) {
|
||||||
this.commandManager = commandManager;
|
|
||||||
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
||||||
.addSubcommands(
|
.addSubcommands(
|
||||||
new SubcommandData("add", "Add a new poll to a channel")
|
new SubcommandData("add", "Add a new poll to a channel")
|
||||||
|
|
@ -54,21 +54,15 @@ public class CommandPoll extends DiscordCommand {
|
||||||
new SubcommandData("results", "Get the results for a poll")
|
new SubcommandData("results", "Get the results for a poll")
|
||||||
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true, true)
|
||||||
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
||||||
for (ScopeInfo info : commandManager.getActiveLocations(getName())) {
|
Util.registerSubcommands(subCommandMap, new SubCommandAdd(this),
|
||||||
switch (info.getScope()) {
|
new SubCommandAddButton(this),
|
||||||
case GLOBAL -> jda.updateCommands().addCommands(slashCommandData).queue();
|
new SubCommandClose(this),
|
||||||
case GUILD -> {
|
new SubCommandEditDescription(this),
|
||||||
Guild guildById = jda.getGuildById(info.getId());
|
new SubCommandEditTitle(this),
|
||||||
if (guildById == null)
|
new SubCommandOpen(this),
|
||||||
{
|
new SubCommandRemoveButton(this),
|
||||||
Logger.warning("Tried to add command % to invalid guild %", getName(), String.valueOf(info.getId()));
|
new SubCommandResults(this));
|
||||||
continue;
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
}
|
|
||||||
guildById.updateCommands().addCommands(slashCommandData).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
|
||||||
}
|
|
||||||
case USER -> Logger.warning("Tried to add command % to user, this is not implemented yet since I don't know how this should work.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -78,12 +72,11 @@ public class CommandPoll extends DiscordCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
if (event.getGuild() == null || event.getMember() == null)
|
if (event.getGuild() == null || event.getMember() == null) {
|
||||||
{
|
|
||||||
event.replyEmbeds(Util.guildOnlyCommand(getName())).setEphemeral(true).queue();
|
event.replyEmbeds(Util.guildOnlyCommand(getName())).setEphemeral(true).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getMember(), getPermission())) {
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -94,89 +87,24 @@ public class CommandPoll extends DiscordCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (subcommandName) {
|
SubCommand subCommand = subCommandMap.get(subcommandName);
|
||||||
case "add" -> {
|
if (subCommand == null) {
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
event.replyEmbeds(new EmbedBuilder()
|
||||||
if (channel == null)
|
.setTitle("Subcommand not found")
|
||||||
return;
|
.setDescription("Unable to find subcommand `" + subcommandName + "`")
|
||||||
String title = OptionMappingParsing.getString("title", event, getName());
|
.setColor(Color.RED)
|
||||||
if (title == null)
|
.build())
|
||||||
return;
|
.setEphemeral(true)
|
||||||
}
|
.queue();
|
||||||
case "edit_title" -> {
|
return;
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
String title = OptionMappingParsing.getString("title", event, getName());
|
|
||||||
if (title == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "edit_description" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
String description = OptionMappingParsing.getString("description", event, getName());
|
|
||||||
if (description == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "add_button" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
Long rowLong = OptionMappingParsing.getLong("button_row", event, getName());
|
|
||||||
if (rowLong == null)
|
|
||||||
return;
|
|
||||||
int row = rowLong.intValue();
|
|
||||||
String buttonName = OptionMappingParsing.getString("button_name", event, getName());
|
|
||||||
if (buttonName == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "remove_button" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
String buttonName = OptionMappingParsing.getString("button_name", event, getName());
|
|
||||||
if (buttonName == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "open" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "close" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "results" -> {
|
|
||||||
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
|
||||||
if (messageId == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + subcommandName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subCommand.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandAdd extends SubCommand {
|
public class SubCommandAdd extends SubCommand {
|
||||||
|
|
@ -17,7 +19,12 @@ public class SubCommandAdd extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
String title = OptionMappingParsing.getString("title", event, getName());
|
||||||
|
if (title == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandAddButton extends SubCommand {
|
public class SubCommandAddButton extends SubCommand {
|
||||||
|
|
@ -16,7 +18,19 @@ public class SubCommandAddButton extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
|
Long rowLong = OptionMappingParsing.getLong("button_row", event, getName());
|
||||||
|
if (rowLong == null)
|
||||||
|
return;
|
||||||
|
int row = rowLong.intValue();
|
||||||
|
String buttonName = OptionMappingParsing.getString("button_name", event, getName());
|
||||||
|
if (buttonName == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandClose extends SubCommand {
|
public class SubCommandClose extends SubCommand {
|
||||||
|
|
@ -16,7 +18,12 @@ public class SubCommandClose extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandEditDescription extends SubCommand {
|
public class SubCommandEditDescription extends SubCommand {
|
||||||
|
|
@ -16,7 +18,15 @@ public class SubCommandEditDescription extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
|
String description = OptionMappingParsing.getString("description", event, getName());
|
||||||
|
if (description == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandEditTitle extends SubCommand {
|
public class SubCommandEditTitle extends SubCommand {
|
||||||
|
|
@ -16,7 +18,15 @@ public class SubCommandEditTitle extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
|
String title = OptionMappingParsing.getString("title", event, getName());
|
||||||
|
if (title == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandOpen extends SubCommand {
|
public class SubCommandOpen extends SubCommand {
|
||||||
|
|
@ -16,7 +18,12 @@ public class SubCommandOpen extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandRemoveButton extends SubCommand {
|
public class SubCommandRemoveButton extends SubCommand {
|
||||||
|
|
@ -16,7 +18,15 @@ public class SubCommandRemoveButton extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
|
String buttonName = OptionMappingParsing.getString("button_name", event, getName());
|
||||||
|
if (buttonName == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.util.OptionMappingParsing;
|
||||||
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandResults extends SubCommand {
|
public class SubCommandResults extends SubCommand {
|
||||||
|
|
@ -16,7 +18,12 @@ public class SubCommandResults extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandInteractionEvent event) {
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel channel = OptionMappingParsing.getGuildChannel("channel", event, getName());
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
Long messageId = OptionMappingParsing.getLong("message_id", event, getName());
|
||||||
|
if (messageId == null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,13 @@ public class MessagesConfig extends AbstractConfig {
|
||||||
messagesConfig.readConfig(MessagesConfig.class, null);
|
messagesConfig.readConfig(MessagesConfig.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String HELP_HELP = "`<prefix>help`: Shows help menu";
|
public static String HELP_HELP = "`/help`: Shows help menu";
|
||||||
public static String HELP_MESSAGE_TEMPLATE = "<commands>";
|
public static String HELP_MESSAGE_TEMPLATE = "<commands>";
|
||||||
private static void loadHelp() {
|
private static void loadHelp() {
|
||||||
HELP_HELP = messagesConfig.getString("help.help", HELP_HELP);
|
HELP_HELP = messagesConfig.getString("help.help", HELP_HELP);
|
||||||
HELP_MESSAGE_TEMPLATE = messagesConfig.getString("help.message-template", HELP_MESSAGE_TEMPLATE);
|
HELP_MESSAGE_TEMPLATE = messagesConfig.getString("help.message-template", HELP_MESSAGE_TEMPLATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void loadPollHelp() {
|
private static void loadPollHelp() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,31 @@
|
||||||
package com.alttd.util;
|
package com.alttd.util;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.ScopeInfo;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.Command;
|
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
|
import net.dv8tion.jda.api.requests.RestAction;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
public static List<Long> getGroupIds(Member member) {
|
public static List<Long> getGroupIds(Member member) {
|
||||||
|
if (member == null)
|
||||||
|
return new ArrayList<>();
|
||||||
return member.getRoles().stream()
|
return member.getRoles().stream()
|
||||||
.map(Role::getIdLong)
|
.map(Role::getIdLong)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
@ -54,4 +63,27 @@ public class Util {
|
||||||
}
|
}
|
||||||
return embedBuilder.build();
|
return embedBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerCommand(CommandManager commandManager, JDA jda, SlashCommandData slashCommandData, String commandName) {
|
||||||
|
for (ScopeInfo info : commandManager.getActiveLocations(commandName)) {
|
||||||
|
switch (info.getScope()) {
|
||||||
|
case GLOBAL -> jda.updateCommands().addCommands(slashCommandData).queue();
|
||||||
|
case GUILD -> {
|
||||||
|
Guild guildById = jda.getGuildById(info.getId());
|
||||||
|
if (guildById == null)
|
||||||
|
{
|
||||||
|
Logger.warning("Tried to add command % to invalid guild %", commandName, String.valueOf(info.getId()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
guildById.updateCommands().addCommands(slashCommandData).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||||
|
}
|
||||||
|
case USER -> Logger.warning("Tried to add command % to user, this is not implemented yet since I don't know how this should work.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerSubcommands(HashMap<String, SubCommand> subCommandMap, SubCommand... subCommands) {
|
||||||
|
for (SubCommand subCommand : subCommands)
|
||||||
|
subCommandMap.put(subCommand.getName(), subCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user