Search in sources :

Example 21 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class ListRoles method getList.

public static XEmbedBuilder getList(CommandObject command) {
    String title = "> Here are the Cosmetic roles you can choose from:";
    List<String> list = command.guild.getCosmeticRoles().stream().map(iRole -> iRole.getName()).collect(Collectors.toList());
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + get(CosmeticRoles.class).missingArgs(command));
    return builder;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Example 22 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class GuildObject method removeCommandsByType.

public void removeCommandsByType(SAILType type) {
    ListIterator iterator = commands.listIterator();
    while (iterator.hasNext()) {
        Command c = (Command) iterator.next();
        if (c.type == type) {
            logger.trace("Command: " + c.names[0] + " removed.");
            iterator.remove();
        }
    }
    for (SAILType t : commandTypes) {
        if (t == type) {
            logger.trace("Type: " + t.toString() + " removed.");
            commandTypes.remove(t);
            return;
        }
    }
}
Also used : SAILType(com.github.vaerys.enums.SAILType) Command(com.github.vaerys.templates.Command)

Example 23 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class UserInfo method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user;
    if (args == null || args.isEmpty()) {
        user = command.user;
    } else {
        user = Utility.getUser(command, args, true);
    }
    if (user == null) {
        return "> Could not find user.";
    }
    ProfileObject profile = user.getProfile(command.guild);
    if (profile == null && user.get().isBot()) {
        if (user.get().getPresence().getStatus().equals(StatusType.OFFLINE) || user.get().getPresence().getStatus().equals(StatusType.UNKNOWN)) {
            return "> Could not get a profile for " + user.displayName + ".";
        }
        profile = new ProfileObject(user.longID);
        command.guild.users.addUser(profile);
    } else if (profile == null) {
        return "> Could not get a profile for " + user.displayName + ".";
    }
    if (!GuildHandler.testForPerms(command, Permissions.ADMINISTRATOR) && (user.isPrivateProfile(command.guild) && user.longID != command.user.longID)) {
        return "> " + user.displayName + " has set their profile to private.";
    }
    // start of the profile builder.
    XEmbedBuilder builder = new XEmbedBuilder(user);
    List<IRole> roles = user.roles;
    ArrayList<String> roleNames = new ArrayList<>();
    ArrayList<String> links = new ArrayList<>();
    // If user is a bot it will display the image below as the user avatar icon.
    if (user.get().isBot()) {
        builder.withAuthorIcon("http://i.imgur.com/aRJpAP4.png");
    }
    // sets title to user Display Name;
    builder.withAuthorName(user.displayName);
    // sets thumbnail to user Avatar.
    builder.withThumbnail(user.get().getAvatarURL());
    // gets the age of the account.
    long nowUTC = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
    ZonedDateTime creationDate = user.get().getCreationDate().atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC);
    long creationUTC = creationDate.toEpochSecond();
    long difference = nowUTC - creationUTC;
    // collect role names;
    roleNames.addAll(roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
    if (profile.getLinks() != null && profile.getLinks().size() > 0) {
        links.addAll(profile.getLinks().stream().map(link -> link.toString()).collect(Collectors.toList()));
    }
    // builds desc
    StringBuilder desc = new StringBuilder();
    StringBuilder footer = new StringBuilder();
    if (profile.getSettings().contains(UserSetting.READ_RULES) && command.guild.config.readRuleReward) {
        builder.withFooterIcon(Constants.STICKER_STAR_URL);
    // builder.withFooterIcon("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/120/glowing-star_1f31f.png");
    }
    if (command.guild.config.userInfoShowsDate) {
        builder.withTimestamp(user.get().getCreationDate());
        footer.append("UserID: " + profile.getUserID() + ", Creation Date");
    // desc.append("**Account Created: **" + creationDate.format(formatter));
    } else {
        desc.append("**Account Created: **" + Utility.formatTimeDifference(difference));
        footer.append("User ID: " + profile.getUserID());
    }
    builder.withFooterText(footer.toString());
    desc.append("\n**Gender: **" + profile.getGender());
    boolean showLevel = true;
    boolean showCC = command.guild.config.moduleCC;
    if (!command.guild.config.modulePixels || profile.getXP() == 0) {
        showLevel = false;
    }
    if (showCC && !showLevel) {
        desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild));
    } else if (showLevel && !showCC) {
        desc.append("\n**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
    } else if (showLevel && showCC) {
        desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild) + indent + indent + indent + "**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
    }
    desc.append("\n**Roles: **" + Utility.listFormatter(roleNames, true));
    desc.append("\n\n*" + profile.getQuote() + "*");
    desc.append("\n" + Utility.listFormatter(links, true));
    if (user.isPatron) {
        builder.withAuthorIcon(Constants.PATREON_ICON_URL);
    }
    builder.withDesc(desc.toString());
    // sends Message
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
        RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
        return "> Profile sent to your Direct messages.";
    }
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) IRole(sx.blah.discord.handle.obj.IRole) StatusType(sx.blah.discord.handle.obj.StatusType) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) UserSetting(com.github.vaerys.enums.UserSetting) GuildHandler(com.github.vaerys.handlers.GuildHandler) Constants(com.github.vaerys.main.Constants) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ArrayList(java.util.ArrayList) List(java.util.List) UserObject(com.github.vaerys.masterobjects.UserObject) Permissions(sx.blah.discord.handle.obj.Permissions) ProfileObject(com.github.vaerys.objects.ProfileObject) PixelHandler(com.github.vaerys.handlers.PixelHandler) Command(com.github.vaerys.templates.Command) ZoneOffset(java.time.ZoneOffset) Utility(com.github.vaerys.main.Utility) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject) IRole(sx.blah.discord.handle.obj.IRole) ZonedDateTime(java.time.ZonedDateTime)

Example 24 with Command

use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.

the class InfoDM method execute.

@Override
public String execute(String args, CommandObject command) {
    List<Command> commands = command.guild.getAllCommands(command);
    if (command.user.longID == command.client.creator.longID) {
        commands.addAll(Globals.getCreatorCommands(true));
    }
    String error = "> Could not find information on any commands named **" + args + "**.";
    for (Command c : commands) {
        for (String s : c.names) {
            if (args.equalsIgnoreCase(s)) {
                // if (!Utility.testForPerms(c.perms(), command.user.getToggles(), command.guild.getToggles())) {
                // return error;
                // }
                RequestHandler.sendEmbedMessage("", c.getCommandInfo(command), command.channel.get());
                return "";
            }
        }
    }
    return error;
// List<Command> commands = Utility.getCommandsByType(Globals.getAllCommands(), command, TYPE_DM,
// true);
// 
// for (Command c : commands) {
// for (String s : c.names()) {
// if (args.equalsIgnoreCase(s)) {
// XEmbedBuilder infoEmbed = new XEmbedBuilder();
// 
// //command info
// StringBuilder builder = new StringBuilder();
// builder.append("**" + Globals.defaultPrefixCommand + c.names()[0]);
// if (c.usage() != null) {
// builder.append(" " + c.usage());
// }
// builder.append("**\nDesc: **" + c.description() + "**\n");
// builder.append("Type: **" + c.type() + "**\n");
// if (c.type().equals(DMCommand.TYPE_CREATOR)) {
// builder.append("**" + ownerOnly + "**");
// }
// infoEmbed.appendField("> Info - " + c.names()[0], builder.toString(), false);
// 
// //aliases
// if (c.names().length > 1) {
// StringBuilder aliasBuilder = new StringBuilder();
// for (int i = 1; i < c.names().length; i++) {
// aliasBuilder.append(Globals.defaultPrefixCommand + c.names()[i] + ", ");
// }
// aliasBuilder.delete(aliasBuilder.length() - 2, aliasBuilder.length());
// aliasBuilder.append(".\n");
// infoEmbed.appendField("Aliases:", aliasBuilder.toString(), false);
// }
// Utility.sendEmbedMessage("", infoEmbed, command.channel.getToggles());
// return "";
// }
// }
// }
// return "> Command with the name " + args + " not found.";
}
Also used : DMCommand(com.github.vaerys.templates.DMCommand) Command(com.github.vaerys.templates.Command)

Aggregations

Command (com.github.vaerys.templates.Command)24 CommandObject (com.github.vaerys.commands.CommandObject)10 SAILType (com.github.vaerys.enums.SAILType)10 Collectors (java.util.stream.Collectors)9 ChannelSetting (com.github.vaerys.enums.ChannelSetting)8 RequestHandler (com.github.vaerys.handlers.RequestHandler)7 Utility (com.github.vaerys.main.Utility)7 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)7 ArrayList (java.util.ArrayList)7 Permissions (sx.blah.discord.handle.obj.Permissions)7 List (java.util.List)6 SubCommandObject (com.github.vaerys.objects.SubCommandObject)5 GuildHandler (com.github.vaerys.handlers.GuildHandler)4 UserObject (com.github.vaerys.masterobjects.UserObject)3 java.util (java.util)3 UserSetting (com.github.vaerys.enums.UserSetting)2 StringHandler (com.github.vaerys.handlers.StringHandler)2 Constants (com.github.vaerys.main.Constants)2 GuildToggle (com.github.vaerys.templates.GuildToggle)2 IChannel (sx.blah.discord.handle.obj.IChannel)2