use of com.github.vaerys.objects.SubCommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class NewCC method handleNameFilter.
private boolean handleNameFilter(CommandObject command, String nameCC) {
// ccs cannot have names that match existing commands:
List<Command> toTest = new ArrayList<>(command.guild.commands);
toTest.removeAll(exceptions);
for (Command c : command.guild.commands) {
// get all commands names.
List<String> names = new ArrayList<>(Arrays.asList(c.names));
for (SubCommandObject sc : c.subCommands) {
names.addAll(Arrays.asList(sc.getNames()));
}
// convert them to lowercase.
ListIterator<String> li = names.listIterator();
while (li.hasNext()) {
li.set(li.next().toLowerCase());
}
// do check
if (names.contains(nameCC.toLowerCase())) {
return true;
}
}
return false;
}
use of com.github.vaerys.objects.SubCommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class Command method getCommandInfo.
/**
* Creates a message used to fetch the command's documentations
*
* @param command
* @return
*/
public XEmbedBuilder getCommandInfo(CommandObject command) {
XEmbedBuilder infoEmbed = new XEmbedBuilder(command);
// command info
StringBuilder builder = new StringBuilder();
builder.append(description(command) + "\n");
builder.append("**Type: **" + type.toString() + ".");
// display permissions
if (perms != null && perms.length != 0) {
builder.append("\n**Perms: **");
ArrayList<String> permList = new ArrayList<>(perms.length);
for (Permissions p : perms) {
permList.add(Utility.enumToString(p));
}
builder.append(Utility.listFormatter(permList, true));
}
if (names.length > 1) {
List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
aliases.remove(0);
builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
}
List<SubCommandObject> objectList = subCommands.stream().filter(subCommandObject -> GuildHandler.testForPerms(command, subCommandObject.getPermissions())).collect(Collectors.toList());
if (objectList.size() != 0)
builder.append("\n" + Command.spacer);
infoEmbed.withTitle("> Help - " + names()[0]);
infoEmbed.appendField("**" + getUsage(command) + "** " + Command.spacer, builder.toString(), true);
for (SubCommandObject s : objectList) {
infoEmbed.appendField(s.getCommandUsage(command) + " " + Command.spacer, s.getHelpDesc(command), true);
}
// Handle channels
List<IChannel> channels = command.guild.getChannelsByType(channel);
List<String> channelMentions = Utility.getChannelMentions(channels);
// channel
if (channelMentions.size() > 0) {
if (channelMentions.size() == 1) {
infoEmbed.appendField("Channel ", Utility.listFormatter(channelMentions, true), false);
} else {
infoEmbed.appendField("Channels ", Utility.listFormatter(channelMentions, true), false);
}
}
return infoEmbed;
}
use of com.github.vaerys.objects.SubCommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class Commands method buildPage.
private String buildPage(List<Command> commands, CommandObject command, SAILType type, List<SAILType> types) {
Map<String, Boolean> commandNames = new TreeMap<>();
// build command name list
for (Command c : commands) {
// put command in the map
boolean isDm = (type == SAILType.DM && c.channel == ChannelSetting.FROM_DM);
if (c.type == type || isDm) {
commandNames.put(c.getCommand(command), c.testSubCommands(command, types));
}
// add any valid subCommands.
for (SubCommandObject s : c.subCommands) {
if (s.getType() == type) {
if (c.type == type && !c.showIndividualSubs)
break;
commandNames.put(s.getCommand(command), true);
if (!showIndividualSubs)
break;
}
}
}
// format command names
List<String> list = new LinkedList<>();
if (commandNames.containsValue(true)) {
List<String> finalList = list;
commandNames.forEach((s, hasSub) -> finalList.add((hasSub ? "* " : " ") + s));
} else {
list = commandNames.keySet().stream().collect(Collectors.toList());
}
// add suffixes to special pages
String suffix = "";
if (type == SAILType.DM) {
suffix = "**These commands can only be performed in DMs.**\n" + "> If you send a non command message to my DMs it will send it to my creator.\n\n";
} else if (type == SAILType.CREATOR) {
suffix = "**Only the creator of this bot can run these commands.**\n\n";
}
// finalise page
return "```\n" + Utility.listFormatter(list, false) + "```\n" + suffix;
}
use of com.github.vaerys.objects.SubCommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class Commands method execute.
@Override
public String execute(String args, CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder(command);
List<SAILType> types = new LinkedList<>();
Map<SAILType, String> pages = new TreeMap<>();
// get dm commands
List<Command> dmCommands = Globals.getCommands(true);
// is creator
if (command.user.checkIsCreator()) {
dmCommands.addAll(Globals.getCreatorCommands(true));
// add creator type and page
List<Command> creatorCommands = Globals.getCreatorCommands(false);
pages.put(SAILType.CREATOR, buildPage(creatorCommands, command, SAILType.CREATOR, types));
types.add(SAILType.CREATOR);
}
// add dm type and page
types.add(SAILType.DM);
// check visible commands;
List<Command> visibleCommands = command.guild.commands.stream().filter(c -> GuildHandler.testForPerms(command, c.perms)).collect(Collectors.toList());
// add all extra types
types.addAll(visibleCommands.stream().map(c -> c.type).collect(Collectors.toList()));
// remove duplicates
types = types.stream().distinct().collect(Collectors.toList());
// build dm page
pages.put(SAILType.DM, buildPage(dmCommands, command, SAILType.DM, types));
// build pages
for (SAILType s : types) {
if (s == SAILType.CREATOR || s == SAILType.DM)
continue;
List<Command> typeCommands = visibleCommands.stream().filter(c -> c.type == s).collect(Collectors.toList());
for (Command c : visibleCommands) {
for (SubCommandObject sub : c.subCommands) {
if (sub.getType() == s && GuildHandler.testForPerms(command, sub.getPermissions())) {
typeCommands.add(c);
}
}
}
pages.put(s, buildPage(typeCommands, command, s, types));
}
// post type list
SAILType type = SAILType.get(args);
boolean typeNull = type == null || !types.contains(type);
boolean argsNull = args == null || args.isEmpty();
if (typeNull || argsNull) {
// get prefix
String prefix = typeNull && !argsNull ? "> There are no commands with the type: **" + args + "**." : "";
// title
builder.withTitle("Here are the Command Types I have available for use:");
// desc
builder.withDesc("```\n" + Utility.listFormatter(types.stream().map(t -> t.toString()).collect(Collectors.toList()), false) + "```\n" + missingArgs(command));
builder.send(prefix, command);
return null;
}
// send page
builder.withTitle("> Here are all of the " + type.toString() + " Commands I have available.");
builder.withDesc(pages.get(type) + missingArgs(command));
builder.send(command);
return null;
}
use of com.github.vaerys.objects.SubCommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class Command method isVisibleInType.
public boolean isVisibleInType(CommandObject commandObject, SAILType type) {
if (this.type == type) {
return GuildHandler.testForPerms(commandObject, perms);
} else {
boolean hasPerms = false;
for (SubCommandObject s : subCommands) {
List<Permissions> allPerms = new ArrayList<>(Arrays.asList(perms));
allPerms.addAll(Arrays.asList(s.getPermissions()));
if (GuildHandler.testForPerms(commandObject, allPerms)) {
hasPerms = true;
}
}
return hasPerms;
}
}
Aggregations