Search in sources :

Example 31 with XEmbedBuilder

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

the class PixelHelp method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args.equalsIgnoreCase("Decay") && command.guild.config.xpDecay)
        return decay(command);
    if (args.equalsIgnoreCase("Rules"))
        return rules(command);
    SplitFirstObject obe = new SplitFirstObject(args);
    String mode = obe.getFirstWord();
    switch(mode.toLowerCase()) {
        case "leveltoxp":
        case "level2xp":
        case "level->xp":
            return levelToXp(obe.getRest());
        case "xptolevel":
        case "xp2level":
        case "xp->level":
            return xpToLevel(obe.getRest());
        default:
            StringBuilder builder = new StringBuilder();
            XEmbedBuilder embed = new XEmbedBuilder(command);
            embed.withTitle("Pixel System Information.");
            embed.withDescription("Pixels are " + command.client.bot.displayName + "'s" + " form of xp, you can gain " + (int) (command.guild.config.xpRate * command.guild.config.xpModifier) + "xp" + " once per minute by sending a message that meets all of the specific message rules.\n\n");
            if (command.guild.config.getRewardRoles().size() != 0) {
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    IRole reward = command.guild.getRoleByID(r.getRoleID());
                    if (reward == null) {
                        break;
                    }
                    builder.append("\n> **" + reward.getName() + "** -> Level: **" + r.getLevel() + "**");
                }
                embed.appendField("Reward Roles:", builder.toString(), true);
            }
            if (command.guild.config.xpModifier != 1) {
                embed.appendField("\n**Current Xp Modifier:**\n", "> **x" + command.guild.config.xpModifier + "**.\n", true);
            }
            int random = new Random().nextInt(25);
            if (random == 1) {
                embed.withThumbnail(Constants.RANK_UP_IMAGE_URL);
            } else {
                embed.withThumbnail(Constants.LEVEL_UP_IMAGE_URL);
            }
            embed.appendField("Pixel and Level Calculators:", getModes(command) + "\n\n" + Utility.getCommandInfo(this, command), false);
            RequestHandler.sendEmbedMessage("", embed, command.channel.get());
            return null;
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) Random(java.util.Random) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 32 with XEmbedBuilder

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

the class Pixels method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder();
    UserObject user = command.user;
    if (args != null && !args.isEmpty()) {
        user = Utility.getUser(command, args, true);
        if (user == null) {
            return "> Could not find user.";
        }
    }
    ProfileObject profile = command.guild.users.getUserByID(user.longID);
    if (profile == null) {
        return "> " + user.displayName + " currently does not have a profile.";
    }
    if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
        return "> " + user.displayName + " has set their profile to private.";
    }
    String xpTitle = "Total Pixels: ";
    String xpTotal = NumberFormat.getInstance().format(profile.getXP());
    String levelTitle = "Level Progress: ";
    String rankTitle = "Rank: ";
    String rankTotal;
    if (PixelHandler.rank(command.guild.users, command.guild.get(), profile.getUserID()) != -1 && profile.getXP() != 0) {
        rankTotal = PixelHandler.rank(command.guild.users, command.guild.get(), profile.getUserID()) + "/" + PixelHandler.totalRanked(command);
    } else {
        rankTotal = "N/a";
    }
    long xpForNext = PixelHandler.levelToXP(profile.getCurrentLevel() + 1);
    long xpTillNext = PixelHandler.totalXPForLevel(profile.getCurrentLevel() + 1) - profile.getXP();
    long xpProgress = xpForNext - xpTillNext;
    long percentToLvl = (xpProgress * 100) / xpForNext;
    StringBuilder xpBar = new StringBuilder("-------------------");
    int pos = (int) (percentToLvl / 5);
    if (pos < 0) {
        pos = 0;
    }
    if (pos > xpBar.length()) {
        pos = xpBar.length();
    }
    if (user.isDecaying(command.guild)) {
        xpBar.replace(pos, pos, "**<**");
    } else {
        xpBar.replace(pos, pos, "**>**");
    }
    String levelTotal = "**" + profile.getCurrentLevel() + "** [" + xpBar.toString() + "] **" + (profile.getCurrentLevel() + 1) + "**";
    // colour of pixels
    builder.withColor(Constants.pixelColour);
    builder.withAuthorName(user.displayName + "'s Pixel stats.");
    // pixel icon
    builder.withAuthorIcon(Constants.PIXELS_ICON);
    builder.appendField(xpTitle, xpTotal, true);
    builder.appendField(rankTitle, rankTotal, true);
    if (profile.getXP() != 0) {
        builder.appendField(levelTitle, levelTotal, false);
    } else {
        builder.appendField(levelTitle, "N/a", false);
    }
    if (profile.getSettings().contains(UserSetting.HIT_LEVEL_FLOOR)) {
        builder.withDescription("**You have decayed to the level floor,\nYou will need to level up again to see your rank.**");
    }
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
        RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
        return "> Pixels sent to your Direct messages.";
    }
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 33 with XEmbedBuilder

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

the class Rank method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user = command.user;
    if (args != null && !args.isEmpty()) {
        UserObject userObject = Utility.getUser(command, args, true);
        if (userObject != null) {
            user = userObject;
        } else {
            return "> Could not find user.";
        }
    }
    String error = "> Cannot get rank stats for " + user.displayName + ".";
    if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
        return "> " + user.displayName + " has set their profile to private.";
    } else if (user.isPrivateProfile(command.guild) && user.longID == command.user.longID) {
        return "> You cannot see your ranking as you have set your profile to private.";
    }
    if (user.getProfile(command.guild) == null) {
        return error;
    }
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.HIT_LEVEL_FLOOR)) {
        if (user.get() != command.user.get()) {
            return "> " + user.displayName + " has decayed to the level floor, they will need to level up again to see your rank.";
        } else {
            return "> You have decayed to the level floor, you will need to level up again to see your rank.";
        }
    }
    // grab a copy of the list
    ArrayList<ProfileObject> users = (ArrayList<ProfileObject>) command.guild.users.getProfiles().clone();
    // sort profiles by Xp in ascending order (lowest Xp to highest XP).
    Utility.sortUserObjects(users, true);
    // test to see if said user actually has rank stats.
    if (PixelHandler.rank(command.guild.users, command.guild.get(), user.longID) == -1) {
        return error;
    }
    // build the Array of stats
    for (int i = 0; i < users.size(); i++) {
        if (users.get(i).getUserID() == user.longID) {
            ArrayList<ProfileObject> ranks = new ArrayList();
            ArrayList<String> response = new ArrayList();
            int addedTop = 0;
            int addedBottom = 0;
            int posTop = 0;
            int posBottom = 0;
            // add profiles above
            while (addedTop < 3 && i + posTop < users.size()) {
                if (user.longID != users.get(i + posTop).getUserID() && PixelHandler.rank(command.guild.users, command.guild.get(), users.get(i + posTop).getUserID()) != -1) {
                    addedTop++;
                    ranks.add(users.get(i + posTop));
                }
                posTop++;
            }
            // add center user
            ranks.add(users.get(i));
            // add user below
            while (addedBottom < 3 && i + posBottom > 0) {
                if (user.longID != users.get(i + posBottom).getUserID() && PixelHandler.rank(command.guild.users, command.guild.get(), users.get(i + posBottom).getUserID()) != -1) {
                    addedBottom++;
                    ranks.add(users.get(i + posBottom));
                }
                posBottom--;
            }
            // sort ranked profiles
            Utility.sortUserObjects(ranks, false);
            // format rank stats
            for (ProfileObject r : ranks) {
                IUser ranked = command.guild.getUserByID(r.getUserID());
                String rankPos = "**" + PixelHandler.rank(command.guild.users, command.guild.get(), r.getUserID()) + "** - ";
                String toFormat = ranked.getDisplayName(command.guild.get()) + "\n " + indent + "`Level: " + r.getCurrentLevel() + ", Pixels: " + NumberFormat.getInstance().format(r.getXP()) + "`";
                if (r.getUserID() == user.longID) {
                    response.add(rankPos + spacer + "**" + toFormat + "**");
                } else {
                    response.add(rankPos + toFormat);
                }
            }
            XEmbedBuilder builder = new XEmbedBuilder(command);
            builder.withTitle("Rank stats for: " + user.displayName);
            builder.withDesc(Utility.listFormatter(response, false));
            RequestHandler.sendEmbedMessage("", builder, command.channel.get());
            return null;
        }
    }
    return error;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) UserObject(com.github.vaerys.masterobjects.UserObject) IUser(sx.blah.discord.handle.obj.IUser) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 34 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder 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 35 with XEmbedBuilder

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

the class WhoWasThat method execute.

@Override
public String execute(String args, CommandObject command) {
    GlobalUserObject user = null;
    if (args.length() != 0) {
        try {
            long userID = Long.parseUnsignedLong(args);
            user = new GlobalUserObject(userID);
        } catch (NumberFormatException e) {
        }
    }
    NumberFormat formatter = NumberFormat.getInstance();
    if (user == null) {
        user = new GlobalUserObject(Globals.lastDmUserID);
    }
    if (user.get() == null) {
        return "> No user found.";
    }
    XEmbedBuilder embed = new XEmbedBuilder(command);
    embed.withAuthorName("@" + user.username);
    if (user.isPatron)
        embed.withAuthorIcon(Constants.PATREON_ICON_URL);
    embed.withThumbnail(user.get().getAvatarURL());
    StringBuilder builder = new StringBuilder();
    final double[] totalxp = { 0 };
    final double[] ccActive = { 0 };
    final double[] charsActive = { 0 };
    final double[] serversActive = { 0 };
    user.profiles.forEach(profileObject -> totalxp[0] += profileObject.getXP());
    user.guilds.forEach(guildObject -> {
        if (guildObject.config.moduleCC)
            ccActive[0]++;
        if (guildObject.config.moduleChars)
            charsActive[0]++;
        if (guildObject.config.moduleServers)
            serversActive[0]++;
    });
    String mutualGuilds = Utility.listFormatter(user.guilds.stream().map(guildObject -> guildObject.get().getName()).collect(Collectors.toList()), true);
    builder.append("**Mutual Guilds:** ");
    if (mutualGuilds.length() > 300) {
        builder.append(user.guilds.size());
    } else {
        builder.append(mutualGuilds);
    }
    builder.append("\n**Total Profiles:** " + user.profiles.size());
    builder.append("\n**Total Pixels:** " + formatter.format(totalxp[0]) + "    **Average Pixels:** " + formatter.format(totalxp[0] / user.profiles.size()));
    builder.append("\n**Total CCs:** " + formatter.format(user.customCommands.size()));
    if (ccActive[0] >= 0 && user.customCommands.size() != 0)
        builder.append("    **Average CCs:** " + formatter.format((double) user.customCommands.size() / ccActive[0]));
    builder.append("\n**Total Chars:** " + formatter.format(user.characters.size()));
    if (charsActive[0] >= 0 && user.characters.size() != 0)
        builder.append("    **Average Chars:** " + formatter.format((double) user.characters.size() / charsActive[0]));
    builder.append("\n**Total Servers:** " + formatter.format(user.servers.size()));
    if (serversActive[0] >= 0 && user.servers.size() != 0)
        builder.append("    **Average Servers:** " + formatter.format((double) user.servers.size() / serversActive[0]));
    builder.append("\n**Total DailyMessages:** " + user.dailyMessages.size());
    builder.append("\n**Total Reminders:** " + user.reminders.size());
    embed.withFooterText(user.longID + ", Creation Date");
    embed.withTimestamp(user.get().getCreationDate());
    embed.withDesc(builder.toString());
    embed.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) GlobalUserObject(com.github.vaerys.masterobjects.GlobalUserObject) NumberFormat(java.text.NumberFormat)

Aggregations

XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)51 ArrayList (java.util.ArrayList)15 ChannelSetting (com.github.vaerys.enums.ChannelSetting)10 SAILType (com.github.vaerys.enums.SAILType)10 CommandObject (com.github.vaerys.commands.CommandObject)9 IUser (sx.blah.discord.handle.obj.IUser)9 Utility (com.github.vaerys.main.Utility)8 UserObject (com.github.vaerys.masterobjects.UserObject)8 Collectors (java.util.stream.Collectors)8 Command (com.github.vaerys.templates.Command)7 List (java.util.List)6 Permissions (sx.blah.discord.handle.obj.Permissions)6 RequestHandler (com.github.vaerys.handlers.RequestHandler)5 StringHandler (com.github.vaerys.handlers.StringHandler)5 ProfileObject (com.github.vaerys.objects.ProfileObject)5 IRole (sx.blah.discord.handle.obj.IRole)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)4 GuildToggle (com.github.vaerys.templates.GuildToggle)4 LinkedList (java.util.LinkedList)4