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);
}
}
}
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);
}
Aggregations