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);
}
}
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;
}
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;
}
}
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;
}
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;
}
Aggregations