Search in sources :

Example 1 with CustomCommands

use of com.github.vaerys.pogos.CustomCommands 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)1 CustomCommands (com.github.vaerys.pogos.CustomCommands)1 IChannel (sx.blah.discord.handle.obj.IChannel)1 IGuild (sx.blah.discord.handle.obj.IGuild)1 IUser (sx.blah.discord.handle.obj.IUser)1