Search in sources :

Example 1 with CCommandObject

use of com.github.vaerys.objects.CCommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class CustomCommands method addCommand.

public String addCommand(boolean isLocked, String commandName, String commandContents, boolean isShitPost, CommandObject object) {
    int counter = 0;
    int limitCCs;
    String toCheck = commandName + commandContents;
    if (Utility.checkBlacklist(toCheck, blackList) != null) {
        return Utility.checkBlacklist(toCheck, blackList);
    }
    if (commandName.length() > 50) {
        return "> Command name too long.";
    }
    if (commandName.isEmpty()) {
        return "> Command name cannot be empty.";
    }
    if (StringUtils.countMatches(commandContents, "#embedImage#{") > 1) {
        return "> Custom Commands Cannot have multiple #embedImage# tags";
    }
    limitCCs = maxCCs(object.user, object.guild);
    for (CCommandObject c : commands) {
        if (c.getName().equalsIgnoreCase(commandName)) {
            return "> Command name already in use.";
        }
        if (c.getUserID() == object.user.longID) {
            counter++;
        }
    }
    if (counter < limitCCs) {
        commands.add(new CCommandObject(isLocked, object.user.longID, commandName, commandContents, isShitPost));
        long remaining = limitCCs - counter - 1;
        String response = "> Command Added, you have ";
        if (remaining > 1) {
            response += remaining + " custom command slots left.\n";
        } else {
            response += remaining + " custom command slot left.\n";
        }
        response += Constants.PREFIX_INDENT + "You can run your new command by performing `" + object.guild.config.getPrefixCC() + commandName + "`.";
        return response;
    } else {
        return "> You have run out of custom command slots. you can make room by deleting or editing old custom commands.";
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject)

Example 2 with CCommandObject

use of com.github.vaerys.objects.CCommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class SearchCCs method execute.

@Override
public String execute(String args, CommandObject command) {
    List<CCommandObject> searched = new ArrayList<>();
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        StringBuilder toSearch = new StringBuilder();
        toSearch.append(c.getName().toLowerCase());
        toSearch.append(c.getContents(false).toLowerCase());
        if (c.isLocked()) {
            toSearch.append("<locked>");
        }
        if (c.isShitPost()) {
            toSearch.append("<shitpost>");
        }
        if ((toSearch.toString()).contains(args.toLowerCase())) {
            searched.add(c);
        }
    }
    if (searched.size() == 0) {
        return "> Could not find any custom commands that contains **" + args + "**.";
    }
    String title = "> Here is your search:";
    XEmbedBuilder embedBuilder = new XEmbedBuilder(command);
    String contents = Utility.listFormatter(searched.stream().map(cCommandObject -> cCommandObject.getName(command)).collect(Collectors.toList()), true);
    if (contents.length() > 2040) {
        List<String> blah = new ArrayList<>();
        StringBuilder complete = new StringBuilder();
        complete.append("> Search for \"" + args + "\", Results found: " + searched.size() + "\n");
        for (CCommandObject c : searched) {
            if (blah.size() == 8) {
                complete.append(Utility.listFormatter(blah, true));
                blah = new ArrayList<>();
                complete.replace(complete.length() - 1, complete.length(), ",");
                complete.append("\n");
            }
            blah.add(c.getName(command));
        }
        if (blah.size() != 0) {
            complete.append(Utility.listFormatter(blah, true));
        }
        if (complete.toString().endsWith(",\n")) {
            complete.replace(complete.length() - 2, complete.length() - 1, ".");
        }
        String path = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
        FileHandler.writeToFile(path, complete.toString(), false);
        File file = new File(path);
        RequestHandler.sendFile(title, file, command.channel.get());
        try {
            Thread.sleep(4000);
            Files.delete(Paths.get(path));
        } catch (IOException e) {
            Utility.sendStack(e);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
        return null;
    } else {
        embedBuilder.withTitle(title);
        embedBuilder.withDesc("```\n" + contents + spacer + "```");
        RequestHandler.sendEmbedMessage("", embedBuilder, command.channel.get());
        embedBuilder.withFooterText("Results Found: " + searched.size());
        return null;
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 3 with CCommandObject

use of com.github.vaerys.objects.CCommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class ListCCs method getUserCommands.

public String getUserCommands(CommandObject command, long userID) {
    IUser user = Globals.getClient().getUserByID(userID);
    int total = 0;
    command.setAuthor(user);
    int max = command.guild.customCommands.maxCCs(command.user, command.guild);
    XEmbedBuilder builder = new XEmbedBuilder(command);
    String title = "> Here are the custom commands for user: **@" + user.getName() + "#" + user.getDiscriminator() + "**.";
    List<String> list = new ArrayList<>();
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        if (c.getUserID() == userID) {
            list.add(command.guild.config.getPrefixCC() + c.getName());
            total++;
        }
    }
    builder.withTitle(title);
    String content = Utility.listFormatter(list, true);
    if (content.length() > 2000) {
        String path = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
        FileHandler.writeToFile(path, content, false);
        File file = new File(path);
        RequestHandler.sendFile(title, file, command.channel.get());
        return null;
    }
    builder.withDescription("```\n" + content + "```");
    builder.withFooterText("Total Custom commands: " + total + "/" + max + ".");
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CCommandObject(com.github.vaerys.objects.CCommandObject) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) File(java.io.File)

Example 4 with CCommandObject

use of com.github.vaerys.objects.CCommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class RandomCC method execute.

@Override
public String execute(String args, CommandObject command) {
    Random random = new Random();
    int counter = 0;
    List<CCommandObject> commands = command.guild.customCommands.getCommandList();
    CCommandObject randCC = commands.get(random.nextInt(commands.size()));
    while (!command.channel.settings.contains(ChannelSetting.SHITPOST) && randCC.isShitPost() && command.guild.config.shitPostFiltering) {
        if (counter > 25) {
            return "> Your server has way to many shitpost commands, I couldn't find you a normal one.";
        }
        randCC = commands.get(random.nextInt(commands.size()));
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
        counter++;
    }
    String response = randCC.getContents(true);
    for (TagObject t : TagList.getType(TagType.CC)) {
        if (t.name.equals(new TagEmbedImage(0).name)) {
            response = t.handleTag(response + "\n`" + command.guild.config.getPrefixCC() + randCC.getName() + "`", command, args);
        } else {
            response = t.handleTag(response, command, args);
        }
    }
    return response;
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) Random(java.util.Random) TagObject(com.github.vaerys.templates.TagObject) TagEmbedImage(com.github.vaerys.tags.cctags.TagEmbedImage)

Example 5 with CCommandObject

use of com.github.vaerys.objects.CCommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class CCHandler method handleCommand.

public static void handleCommand(String args, CommandObject command) {
    // cc lockout handling
    SplitFirstObject commandName = new SplitFirstObject(args);
    CCommandObject commandObject = command.guild.customCommands.getCommand(commandName.getFirstWord(), command);
    String ccArgs = commandName.getRest();
    if (ccArgs == null) {
        ccArgs = "";
    }
    if (commandObject == null)
        return;
    List<IChannel> ccDenied = command.guild.getChannelsByType(ChannelSetting.CC_DENIED);
    if (ccDenied.contains(command.channel.get())) {
        RequestHandler.sendMessage("> Custom Command usage has been disabled for this channel.", command.channel);
        return;
    }
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_USE_CCS)) {
        RequestHandler.sendMessage("> Nothing interesting happens. `(ERROR: 403)`", command.channel.get());
        return;
    }
    command.guild.sendDebugLog(command, "CUSTOM_COMMAND", commandObject.getName(command), ccArgs);
    String contents = commandObject.getContents(true);
    // shitpost handling
    if (commandObject.isShitPost() && command.guild.config.shitPostFiltering && !GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
        List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.SHITPOST);
        if (channels.size() != 0 && !channels.contains(command.channel.get())) {
            channels = command.user.getVisibleChannels(channels);
            List<String> channelMentions = Utility.getChannelMentions(channels);
            RequestHandler.sendMessage(Utility.getChannelMessage(channelMentions), command.channel.get());
            return;
        }
    }
    // tag handling
    for (TagObject t : TagList.getType(TagType.CC)) {
        contents = t.handleTag(contents, command, ccArgs);
        if (contents == null)
            return;
    }
    RequestHandler.sendMessage(contents, command.channel.get());
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) TagObject(com.github.vaerys.templates.TagObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Aggregations

CCommandObject (com.github.vaerys.objects.CCommandObject)14 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)4 File (java.io.File)4 IUser (sx.blah.discord.handle.obj.IUser)4 ProfileObject (com.github.vaerys.objects.ProfileObject)3 ArrayList (java.util.ArrayList)3 IChannel (sx.blah.discord.handle.obj.IChannel)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)2 TagObject (com.github.vaerys.templates.TagObject)2 CharacterObject (com.github.vaerys.objects.CharacterObject)1 ServerObject (com.github.vaerys.objects.ServerObject)1 CustomCommands (com.github.vaerys.pogos.CustomCommands)1 TagEmbedImage (com.github.vaerys.tags.cctags.TagEmbedImage)1 GuildFile (com.github.vaerys.templates.GuildFile)1 IOException (java.io.IOException)1 ListIterator (java.util.ListIterator)1 Random (java.util.Random)1 IGuild (sx.blah.discord.handle.obj.IGuild)1