Search in sources :

Example 11 with Command

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

the class CommandInit method validate.

private static void validate(ArrayList<Command> commands) {
    for (Command c : commands) {
        logger.trace("Validating Command: " + c.getClass().getName());
        String errorReport = c.validate();
        Globals.addToErrorStack(errorReport);
    }
}
Also used : Command(com.github.vaerys.templates.Command)

Example 12 with Command

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

the class ListChars method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    UserObject user = command.user;
    String title = "> Here are all of your characters.";
    // get user
    if (args != null && !args.isEmpty()) {
        user = Utility.getUser(command, args, true);
        if (user == null) {
            return "> Could not find user.";
        }
        if (user.longID != command.user.longID) {
            title = "> Here are all of @" + user.displayName + "'s Characters.";
        }
    }
    // check private
    if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
        return "> User has set their profile to private.";
    }
    // generate list
    List<String> list = user.characters.stream().map(c -> c.getName()).collect(Collectors.toList());
    // give message if empty
    if (list.size() == 0) {
        return "> You do not have any characters yet. Create one with **" + new UpdateChar().getUsage(command) + "**.";
    }
    // build embed data
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + new CharInfo().missingArgs(command));
    builder.withFooterText(user.characters.size() + "/" + command.guild.characters.maxCharsForUser(user, command.guild) + " Slots used.");
    // send private char list
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
        RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
        return "> Char list sent to your Direct messages.";
    }
    // send regular
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
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) UserObject(com.github.vaerys.masterobjects.UserObject) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) UserSetting(com.github.vaerys.enums.UserSetting) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) UserObject(com.github.vaerys.masterobjects.UserObject)

Example 13 with Command

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

the class UpdateChar method execute.

@Override
public String execute(String args, CommandObject command) {
    List<CharacterObject> userChars = command.user.characters;
    String charName = args.split(" ")[0];
    CharacterObject selectedChar = command.guild.characters.getCharByName(charName);
    List<IRole> cosmeticRoles = command.user.getCosmeticRoles(command);
    List<Long> cosmeticRoleIDs = cosmeticRoles.stream().map(iRole -> iRole.getLongID()).collect(Collectors.toList());
    String cosmeticString = command.guild.config.moduleRoles ? " and cosmetic roles" : "";
    if (selectedChar != null) {
        if (selectedChar.getUserID() != command.user.longID) {
            return "> That is not your character you cannot update it.";
        }
        if (selectedChar.getNickname().equals(command.user.displayName) && selectedChar.getRoleIDs().containsAll(cosmeticRoleIDs)) {
            return "> You haven't updated your details since the last time this character was updated.\n" + "Characters use your nickname " + cosmeticString + " to use as data.";
        }
        selectedChar.update(command.user.displayName, cosmeticRoles);
        String response = "> Your character has been updated using your nickname" + cosmeticString + ".";
        if (!UPDATE_CHAR.isSubCommand(command)) {
            response += "\nIf you were attempting to create a new character and not edit this character you need to specify a different character ID.";
        }
        return response;
    } else {
        int maxChars = command.guild.characters.maxCharsForUser(command);
        int rewardCount = command.user.getRewardValue(command);
        if (userChars.size() == maxChars) {
            if (command.guild.config.modulePixels && command.guild.config.xpGain && rewardCount != 4) {
                return "> You have reached the maximum allowed characters for your level," + " you will have to either rank up or delete an old character to make room.";
            }
            return "> You have reached the maximum allowed characters. You will have to delete an old character to make room.";
        }
        command.guild.characters.addChar(charName, cosmeticRoles, command.user);
        int remainingSlots = (maxChars - userChars.size() - 1);
        String response = "> New Character Created using your nickname " + cosmeticString + " to fill in data." + "\n(" + remainingSlots + " Character slot";
        if (remainingSlots != 1)
            response += "s";
        response += " remaining)";
        if (!UPDATE_CHAR.isSubCommand(command)) {
            response += "\nTo update the name";
            if (command.guild.config.moduleRoles)
                response += " or roles";
            response += " linked to this character just run this command again.";
        }
        return response;
    }
}
Also used : SubCommandObject(com.github.vaerys.objects.SubCommandObject) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) IRole(sx.blah.discord.handle.obj.IRole) CharacterObject(com.github.vaerys.objects.CharacterObject) 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) Collectors(java.util.stream.Collectors) CharacterObject(com.github.vaerys.objects.CharacterObject) IRole(sx.blah.discord.handle.obj.IRole)

Example 14 with Command

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

Example 15 with Command

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

the class HelpDM method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    List<Command> commands = Utility.getCommandsByType(Globals.getAllCommands(), command, SAILType.DM, true);
    List<String> list = new ArrayList<>();
    for (Command c : commands) {
        list.add(c.getCommand(command));
    }
    Collections.sort(list);
    StringBuilder desc = new StringBuilder("**> Direct Message Commands.**```" + Utility.listFormatter(list, false) + "```\n");
    desc.append(Utility.getCommandInfo(new InfoDM()));
    builder.withDescription(desc.toString());
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) DMCommand(com.github.vaerys.templates.DMCommand) Command(com.github.vaerys.templates.Command) ArrayList(java.util.ArrayList)

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