Dump roles ID command.

master
Pingex aka Raphaël 9 years ago
parent 5033de0355
commit 65d5972fa5

@ -2,11 +2,12 @@ package net.pingex.dcf.commands;
import net.pingex.dcf.commands.options.ICommandOption; import net.pingex.dcf.commands.options.ICommandOption;
import net.pingex.dcf.commands.options.ScopeOption; import net.pingex.dcf.commands.options.ScopeOption;
import net.pingex.dcf.commands.permissions.DefaultPermissionOption;
import net.pingex.dcf.core.Configuration; import net.pingex.dcf.core.Configuration;
import net.pingex.dcf.util.ArgumentParser; import net.pingex.dcf.util.ArgumentParser;
import net.pingex.dcf.util.DiscordInteractionsUtil; import net.pingex.dcf.util.DiscordInteractionsUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent; import sx.blah.discord.handle.obj.IRole;
import java.util.*; import java.util.*;
/** /**
@ -17,7 +18,7 @@ public class InternalCommands implements IWithCommands
@Override @Override
public Set<Command> getCommands() public Set<Command> getCommands()
{ {
return new HashSet<>(Arrays.asList(ListCommand.INSTANCE, UsageCommand.INSTANCE)); return new HashSet<>(Arrays.asList(ListCommand.INSTANCE, UsageCommand.INSTANCE, dumpRoles));
} }
/** /**
@ -154,4 +155,31 @@ public class InternalCommands implements IWithCommands
DiscordInteractionsUtil.sendMessage(context.getChannel(), output.toString()); DiscordInteractionsUtil.sendMessage(context.getChannel(), output.toString());
} }
} }
private static final Command dumpRoles = Command.builder("internal:dumpRoles")
.aliases("dumpRoles")
.description("Dump all Roles ID for the current Guild.")
.options(new HashSet<>(Arrays.asList(
new DefaultPermissionOption(DefaultPermissionOption.Value.ANY_OWNER),
new ScopeOption(ScopeOption.CommandScope.GUILD_CHAT))))
.build(InternalCommands::dumpRolesImpl);
private static void dumpRolesImpl(Context context)
{
if(context.getGuild().getRoles().size() == 0)
{
DiscordInteractionsUtil.sendMessage(context.getChannel(), "This guild has no role defined.");
return;
}
StringBuilder sb = new StringBuilder("**Roles ID** for ").append(context.getGuild().getName()).append("\n")
.append("```\n");
int longestName = context.getGuild().getRoles().stream().max(Comparator.comparingInt(i -> i.getName().length())).get().getName().length();
for(IRole i : context.getGuild().getRoles())
sb.append("* ").append(StringUtils.rightPad(i.getName(), longestName)).append(" - ").append(i.getID()).append("\n");
sb.append("```");
DiscordInteractionsUtil.sendMessage(context.getChannel(), sb.toString());
}
} }