Search in sources :

Example 1 with GenericCommand

use of at.xirado.bean.command.GenericCommand in project Bean by Xirado.

the class InteractionCommandHandler method updateCommands.

public void updateCommands(Consumer<List<Command>> success, Consumer<Throwable> failure) {
    if (!Bean.getInstance().isDebug()) {
        commandUpdateAction.queue(success, failure);
        for (Map.Entry<Long, List<GenericCommand>> entrySet : registeredGuildCommands.entrySet()) {
            Long guildID = entrySet.getKey();
            List<GenericCommand> slashCommands = entrySet.getValue();
            if (guildID == null || slashCommands == null)
                continue;
            if (slashCommands.isEmpty())
                continue;
            Guild guild = Bean.getInstance().getShardManager().getGuildById(guildID);
            if (guild == null)
                continue;
            CommandListUpdateAction guildCommandUpdateAction = guild.updateCommands();
            for (GenericCommand cmd : slashCommands) {
                guildCommandUpdateAction = guildCommandUpdateAction.addCommands(cmd.getData());
            }
            if (slashCommands.size() > 0)
                guildCommandUpdateAction.queue();
        }
    } else {
        List<GenericCommand> commands = registeredGuildCommands.get(Bean.TEST_SERVER_ID);
        if (commands != null && !commands.isEmpty()) {
            Guild guild = Bean.getInstance().getShardManager().getGuildById(Bean.TEST_SERVER_ID);
            if (guild == null)
                return;
            CommandListUpdateAction commandListUpdateAction = guild.updateCommands();
            for (GenericCommand cmd : commands) commandListUpdateAction.addCommands(cmd.getData());
            commandListUpdateAction.queue(success, failure);
        }
    }
}
Also used : GenericCommand(at.xirado.bean.command.GenericCommand) CommandListUpdateAction(net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction) ArrayList(java.util.ArrayList) List(java.util.List) Guild(net.dv8tion.jda.api.entities.Guild) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with GenericCommand

use of at.xirado.bean.command.GenericCommand in project Bean by Xirado.

the class InteractionCommandHandler method registerCommand.

private void registerCommand(GenericCommand command) {
    if (!command.isGlobal() && !Bean.getInstance().isDebug()) {
        if (command.getEnabledGuilds() == null || command.getEnabledGuilds().isEmpty())
            return;
        for (Long guildID : command.getEnabledGuilds()) {
            Guild guild = Bean.getInstance().getShardManager().getGuildById(guildID);
            if (guild == null)
                continue;
            List<GenericCommand> alreadyRegistered = registeredGuildCommands.containsKey(guildID) ? registeredGuildCommands.get(guildID) : new ArrayList<>();
            alreadyRegistered.add(command);
            registeredGuildCommands.put(guildID, alreadyRegistered);
        }
        return;
    }
    if (Bean.getInstance().isDebug()) {
        Guild guild = Bean.getInstance().getShardManager().getGuildById(Bean.TEST_SERVER_ID);
        if (guild != null) {
            List<GenericCommand> alreadyRegistered = registeredGuildCommands.containsKey(Bean.TEST_SERVER_ID) ? registeredGuildCommands.get(Bean.TEST_SERVER_ID) : new ArrayList<>();
            alreadyRegistered.add(command);
            registeredGuildCommands.put(Bean.TEST_SERVER_ID, alreadyRegistered);
        }
        return;
    }
    commandUpdateAction.addCommands(command.getData());
    registeredCommands.add(command);
}
Also used : GenericCommand(at.xirado.bean.command.GenericCommand) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

GenericCommand (at.xirado.bean.command.GenericCommand)2 Guild (net.dv8tion.jda.api.entities.Guild)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CommandListUpdateAction (net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction)1