use of com.github.vaerys.commands.CommandObject 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.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class GuildToggle method info.
public XEmbedBuilder info(CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder(command);
if (isModule()) {
builder.withTitle("Module - " + name());
} else {
builder.withTitle("Setting - " + name());
}
String fullDesc = desc(command);
if (statsOnInfo()) {
String stats = stats(command);
if (stats != null && !stats.isEmpty()) {
fullDesc += "\n\n**Stats:**\n" + stats;
}
}
builder.withDesc(fullDesc);
List<String> commandNames = commands.stream().map(command1 -> command1.getCommand(command)).collect(Collectors.toList());
commandNames.addAll(Globals.getAllCommands().stream().filter(command1 -> command1.type() == affectsType).map(command1 -> command1.getCommand(command)).collect(Collectors.toList()));
commandNames = commandNames.stream().distinct().collect(Collectors.toList());
List<SAILType> settingNames = settings.stream().map(guildSetting -> guildSetting.name()).collect(Collectors.toList());
List<ChannelSetting> channelNames = channels.stream().map(channelSetting -> channelSetting).collect(Collectors.toList());
if (commandNames.size() != 0) {
builder.appendField("Commands:", "```\n" + Utility.listFormatter(commandNames, true) + Command.spacer + "```", true);
}
if (settingNames.size() != 0) {
builder.appendField("Settings:", "```\n" + Utility.listEnumFormatter(settingNames, true) + Command.spacer + "```", true);
}
if (channelNames.size() != 0) {
builder.appendField("Channels:", "```\n" + Utility.listEnumFormatter(channelNames, true) + Command.spacer + "```", true);
}
StringBuilder footer = new StringBuilder();
if (isModule())
footer.append("Module ");
else
footer.append("Setting ");
if (enabled(command.guild.config))
footer.append("Enabled.");
else
footer.append("Disabled.");
builder.withFooterText(footer.toString());
return builder;
}
use of com.github.vaerys.commands.CommandObject 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.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class AnnotationListener method onMessageDeleteEvent.
@EventSubscriber
public void onMessageDeleteEvent(MessageDeleteEvent event) {
if (event.getChannel().isPrivate())
return;
if (!Globals.isReady)
return;
if (event.getMessage() == null)
return;
if (event.getGuild().getUserByID(event.getAuthor().getLongID()) == null)
return;
CommandObject command = new CommandObject(event.getMessage());
if (!command.guild.config.moduleLogging)
return;
LoggingHandler.logDelete(command, event.getMessage());
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class CosmeticRoles method execute.
@Override
public String execute(String args, CommandObject command) {
if (args == null || args.isEmpty()) {
return get(ListRoles.class).execute(args, command);
}
if (EDIT_ROLES.isSubCommand(command)) {
boolean isAdding = args.split(" ")[0].equals("+");
// test the permissions of the user to make sure they can modify the role list.
IRole role = null;
String subArgs = EDIT_ROLES.getArgs(command);
try {
role = command.guild.getRoleByID(Utility.stringLong(subArgs));
} catch (NumberFormatException e) {
// move on.
}
if (role == null)
role = GuildHandler.getRoleFromName(subArgs, command.guild.get());
if (role == null)
return "> **" + subArgs + "** is not a valid Role Name.";
// tests to see if the bot is allowed to mess with a role.
if (!Utility.testUserHierarchy(command.client.bot.get(), role, command.guild.get())) {
return "> I do not have permission to modify the **" + role.getName() + "** role.";
}
// test the user's hierarchy to make sure that the are allowed to mess with that role.
if (Utility.testUserHierarchy(command.user.get(), role, command.guild.get())) {
// do if modifier is true
if (isAdding) {
// check for the role and add if its not a cosmetic role.
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
return "> The **" + role.getName() + "** role is already listed as a cosmetic role.";
} else {
command.guild.config.getCosmeticRoleIDs().add(role.getLongID());
return "> The **" + role.getName() + "** role was added to the cosmetic role list.";
}
// do if modifier is false
} else {
// check for the role and remove if it is a cosmetic role.
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
Iterator iterator = command.guild.config.getCosmeticRoleIDs().listIterator();
while (iterator.hasNext()) {
long id = (long) iterator.next();
if (role.getLongID() == id) {
iterator.remove();
}
}
return "> The **" + role.getName() + "** role was removed from the cosmetic role list.";
} else {
return "> The **" + role.getName() + "** role is not listed as a cosmetic role.";
}
}
} else {
return "> You do not have permission to modify the **" + role.getName() + "** role.";
}
// do user role modification
} else {
// check to make sure that the user isn't including the args brackets or the /remove at the end;
if (command.guild.config.getCosmeticRoleIDs().size() == 0)
return "> No Cosmetic roles are set up right now. Come back later.";
if (args.matches("[(|\\[].*[)|\\]]")) {
return Constants.ERROR_BRACKETS + "\n" + Utility.getCommandInfo(this, command);
}
if (args.matches(".*/remove")) {
return "> Did you mean `" + command.guild.config.getPrefixCommand() + names()[0] + " " + args.replaceAll("(?i)/remove", "") + "`?";
}
List<IRole> userRoles = command.user.roles;
String response;
// check if role is valid
IRole role;
role = GuildHandler.getRoleFromName(args, command.guild.get());
if (role == null && args.length() > 3) {
role = GuildHandler.getRoleFromName(args, command.guild.get(), true);
}
if (role == null && !args.equalsIgnoreCase("remove")) {
RequestHandler.sendEmbedMessage("> **" + args + "** is not a valid Role Name.", ListRoles.getList(command), command.channel.get());
return null;
// if args = remove. remove the user's cosmetic role
} else if (args.equalsIgnoreCase("remove")) {
userRoles = userRoles.stream().filter(r -> !command.guild.config.isRoleCosmetic(r.getLongID())).collect(Collectors.toList());
if (command.user.getCosmeticRoles(command).size() == 0)
return "> You don't have a role to remove...";
else
response = "> You have had your cosmetic role removed.";
} else {
// check if role is cosmetic
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
// check to see if roles are toggles
if (command.guild.config.roleIsToggle) {
// if user has role, remove it.
if (userRoles.contains(role)) {
userRoles.remove(role);
response = "> You have had the **" + role.getName() + "** role removed.";
// else add that role.
} else {
userRoles.add(role);
response = "> You have been granted the **" + role.getName() + "** role.";
}
// if roles arent toggles run this.
} else {
// if they already have that role
if (userRoles.contains(role)) {
return "> You already have the **" + role.getName() + "** role.";
} else {
// remove all cosmetic role and add the new one
userRoles = userRoles.stream().filter(r -> !command.guild.config.isRoleCosmetic(r.getLongID())).collect(Collectors.toList());
userRoles.add(role);
response = "> You have selected the cosmetic role: **" + role.getName() + "**.";
}
}
} else {
RequestHandler.sendEmbedMessage("> **" + args + "** is not a valid cosmetic role.", ListRoles.getList(command), command.channel.get());
return null;
}
}
// push the changes to the user's roles.
if (RequestHandler.roleManagement(command.user.get(), command.guild.get(), userRoles).get()) {
return response;
} else {
return Constants.ERROR_UPDATING_ROLE;
}
}
}
Aggregations