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.";
}
}
Aggregations