Search in sources :

Example 16 with Command

use of com.github.vaerys.templates.Command 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;
}
Also used : Command(com.github.vaerys.templates.Command) SubCommandObject(com.github.vaerys.objects.SubCommandObject)

Example 17 with Command

use of com.github.vaerys.templates.Command 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;
}
Also used : SubCommandObject(com.github.vaerys.objects.SubCommandObject) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) java.util(java.util) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) GuildHandler(com.github.vaerys.handlers.GuildHandler) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) SAILType(com.github.vaerys.enums.SAILType) Command(com.github.vaerys.templates.Command) SubCommandObject(com.github.vaerys.objects.SubCommandObject)

Example 18 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class Help method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args == null || args.isEmpty()) {
        return "> If you are after a list of commands please run **" + new Commands().getUsage(command) + "** instead.\n\n" + missingArgs(command);
    }
    List<Command> commands = command.guild.getAllCommands(command);
    if (command.user.longID == command.client.creator.longID) {
        commands.addAll(Globals.getCreatorCommands(false));
    }
    Command foundCommand = null;
    for (Command c : commands) {
        if (c.isName(args, command)) {
            foundCommand = c;
        }
    }
    if (foundCommand == null)
        return "> Could not find information on any commands named **" + args + "**.";
    if (!GuildHandler.testForPerms(command, foundCommand.perms))
        return "> I'm sorry but you do not have permission to view the information for the **" + foundCommand.getCommand(command) + "** command.";
    RequestHandler.sendEmbedMessage("", foundCommand.getCommandInfo(command), command.channel.get());
    return "";
}
Also used : Command(com.github.vaerys.templates.Command)

Example 19 with Command

use of com.github.vaerys.templates.Command 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;
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) Iterator(java.util.Iterator) IRole(sx.blah.discord.handle.obj.IRole) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) GuildHandler(com.github.vaerys.handlers.GuildHandler) Constants(com.github.vaerys.main.Constants) Collectors(java.util.stream.Collectors) SubCommandObject(com.github.vaerys.objects.SubCommandObject) List(java.util.List) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) IRole(sx.blah.discord.handle.obj.IRole) Iterator(java.util.Iterator)

Example 20 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class ListModifs method getList.

public static XEmbedBuilder getList(CommandObject command) {
    String title = "> Here are the Modifier roles you can choose from:";
    List<String> list = command.guild.getModifierRoles().stream().map(iRole -> iRole.getName()).collect(Collectors.toList());
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + get(ModifierRoles.class).missingArgs(command));
    return builder;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Aggregations

Command (com.github.vaerys.templates.Command)24 CommandObject (com.github.vaerys.commands.CommandObject)10 SAILType (com.github.vaerys.enums.SAILType)10 Collectors (java.util.stream.Collectors)9 ChannelSetting (com.github.vaerys.enums.ChannelSetting)8 RequestHandler (com.github.vaerys.handlers.RequestHandler)7 Utility (com.github.vaerys.main.Utility)7 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)7 ArrayList (java.util.ArrayList)7 Permissions (sx.blah.discord.handle.obj.Permissions)7 List (java.util.List)6 SubCommandObject (com.github.vaerys.objects.SubCommandObject)5 GuildHandler (com.github.vaerys.handlers.GuildHandler)4 UserObject (com.github.vaerys.masterobjects.UserObject)3 java.util (java.util)3 UserSetting (com.github.vaerys.enums.UserSetting)2 StringHandler (com.github.vaerys.handlers.StringHandler)2 Constants (com.github.vaerys.main.Constants)2 GuildToggle (com.github.vaerys.templates.GuildToggle)2 IChannel (sx.blah.discord.handle.obj.IChannel)2