Search in sources :

Example 11 with CCommandObject

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

the class GetCCData method execute.

@Override
public String execute(String args, CommandObject command) {
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        if (c.getName().equalsIgnoreCase(args)) {
            StringBuilder content = new StringBuilder("Command Name: \"" + c.getName() + "\"");
            IUser createdBy = command.guild.getUserByID(c.getUserID());
            if (createdBy == null)
                createdBy = command.client.get().fetchUser(c.getUserID());
            if (createdBy == null)
                content.append("\nCreated by: \"null\"");
            else
                content.append("\nCreated by: \"" + createdBy.getName() + "#" + createdBy.getDiscriminator() + "\"");
            content.append("\nTimes run: \"" + c.getTimesRun() + "\"");
            content.append("\nContents: \"" + c.getContents(false) + "\"");
            String filePath = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
            FileHandler.writeToFile(filePath, content.toString(), false);
            RequestHandler.sendFile("> Here is the raw data for Custom Command: **" + c.getName() + "**", new File(filePath), command.channel.get());
            try {
                Thread.sleep(4000);
                new File(filePath).delete();
            } catch (InterruptedException e) {
                Utility.sendStack(e);
            }
            return "";
        }
    }
    return "> Custom command " + args + " could not be found.";
// return command.customCommands.sendCCasJSON(command.channelSID, args);
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IUser(sx.blah.discord.handle.obj.IUser) File(java.io.File)

Example 12 with CCommandObject

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

the class InfoCC method execute.

@Override
public String execute(String args, CommandObject command) {
    CCommandObject customCommand = command.guild.customCommands.getCommand(args);
    if (customCommand == null) {
        return Constants.ERROR_CC_NOT_FOUND;
    }
    StringBuilder builder = new StringBuilder();
    XEmbedBuilder embedBuilder = new XEmbedBuilder(command);
    String title = "> Here is the information for command: **" + customCommand.getName() + "**\n";
    IUser createdBy = command.guild.getUserByID(customCommand.getUserID());
    if (createdBy == null)
        createdBy = command.client.get().fetchUser(customCommand.getUserID());
    if (createdBy == null)
        builder.append("Creator: **Null**\n");
    else
        builder.append("Creator: **@" + createdBy.getName() + "#" + createdBy.getDiscriminator() + "**\n");
    builder.append("Time Run: **" + customCommand.getTimesRun() + "**\n");
    builder.append("Is Locked: **" + customCommand.isLocked() + "**\n");
    builder.append("Is ShitPost: **" + customCommand.isShitPost() + "**");
    embedBuilder.appendField(title, builder.toString(), false);
    RequestHandler.sendEmbedMessage("", embedBuilder, command.channel.get());
    return null;
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser)

Example 13 with CCommandObject

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

the class ListCCs method listCommands.

public String listCommands(int page, CommandObject command) {
    ArrayList<String> pages = new ArrayList<>();
    int counter = 0;
    int totalCCs = 0;
    ArrayList<String> list = new ArrayList<>();
    XEmbedBuilder builder = new XEmbedBuilder(command);
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        if (counter > 15) {
            pages.add("```" + Utility.listFormatter(list, true) + "```");
            list.clear();
            counter = 0;
        }
        list.add(command.guild.config.getPrefixCC() + c.getName());
        totalCCs++;
        counter++;
    }
    pages.add("`" + Utility.listFormatter(list, true) + "`");
    try {
        String title = "> Here is Page **" + page + "/" + pages.size() + "** of Custom Commands:";
        builder.appendField(title, pages.get(page - 1), false);
        builder.withFooterText("Total Custom Commands stored on this Server: " + totalCCs);
        RequestHandler.sendEmbedMessage("", builder, command.channel.get());
        return null;
    } catch (IndexOutOfBoundsException e) {
        return "> That Page does not exist.";
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CCommandObject(com.github.vaerys.objects.CCommandObject) ArrayList(java.util.ArrayList)

Example 14 with CCommandObject

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

the class TransferCC method execute.

@Override
public String execute(String args, CommandObject command) {
    String filePath = Constants.DIRECTORY_OLD_FILES + command.guild.longID + "_CustomCommands.json";
    IGuild guild = command.guild.get();
    IUser author = command.user.get();
    IChannel channel = command.channel.get();
    CustomCommands customCommands = command.guild.customCommands;
    if (Paths.get(filePath).toFile().exists()) {
        com.github.vaerys.oldcode.CustomCommands oldCommands = null;
        if (oldCommands == null) {
            oldCommands = (com.github.vaerys.oldcode.CustomCommands) FileHandler.readFromJson(filePath, com.github.vaerys.oldcode.CustomCommands.class);
        }
        CCommandObject transfering = oldCommands.convertCommand(args);
        if (transfering == null) {
            return Constants.ERROR_CC_NOT_FOUND;
        }
        boolean locked = transfering.isLocked();
        long userID = transfering.getUserID();
        if (guild.getUserByID(userID) == null) {
            RequestHandler.sendMessage("> This command's old owner no longer is part of this server.\n" + Constants.PREFIX_INDENT + author.getDisplayName(guild) + " will become the new owner of this command.\n" + "> I am now attempting to transfer the command over.", channel);
            userID = author.getLongID();
        } else {
            RequestHandler.sendMessage("> I am now attempting to transfer " + guild.getUserByID(userID).getDisplayName(guild) + "'s command.", channel);
        }
        String name = transfering.getName();
        String contents = transfering.getContents(false);
        contents = contents.replace("#author!#", "#username#");
        boolean shitpost = transfering.isShitPost();
        command.setAuthor(Globals.getClient().getUserByID(userID));
        return customCommands.addCommand(locked, name, contents, shitpost, command);
    } else {
        return "> Your Server has no Legacy commands to transfer.";
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) CustomCommands(com.github.vaerys.pogos.CustomCommands)

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