Added sub commands for polls and did help command

This commit is contained in:
2022-04-01 02:54:33 +02:00
parent 311348dcf6
commit c6bd15f141
15 changed files with 342 additions and 219 deletions
+35 -3
View File
@@ -1,22 +1,31 @@
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.templates.Parser;
import com.alttd.templates.Template;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class Util {
public static List<Long> getGroupIds(Member member) {
if (member == null)
return new ArrayList<>();
return member.getRoles().stream()
.map(Role::getIdLong)
.collect(Collectors.toList());
@@ -54,4 +63,27 @@ public class Util {
}
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);
}
}