Search in sources :

Example 21 with ProfileObject

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

the class PruneEmptyProfiles method execute.

@Override
public String execute(String args, CommandObject command) {
    ArrayList<ProfileObject> profiles = command.guild.users.getProfiles();
    ProfileObject defaultProfile = new ProfileObject(-1);
    long profileCount = 0;
    ListIterator listIterator = profiles.listIterator();
    while (listIterator.hasNext()) {
        ProfileObject profile = (ProfileObject) listIterator.next();
        boolean noXP = profile.getXP() == 0;
        boolean noGender = defaultProfile.getGender().equals(profile.getGender());
        boolean noQuote = defaultProfile.getQuote().equals(profile.getQuote());
        boolean noSettings = profile.getSettings().size() == 0;
        boolean noLinks = profile.getLinks().size() == 0;
        if (noXP && noGender && noQuote && noSettings && noLinks) {
            listIterator.remove();
            profileCount++;
        }
    }
    return "> " + NumberFormat.getInstance().format(profileCount) + " empty profiles pruned.";
}
Also used : ListIterator(java.util.ListIterator) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 22 with ProfileObject

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

the class PurgeBannedData method purgeData.

public void purgeData(long userID, CommandObject command) {
    ListIterator iterator = command.guild.users.profiles.listIterator();
    while (iterator.hasNext()) {
        ProfileObject object = (ProfileObject) iterator.next();
        if (userID == object.getUserID()) {
            iterator.remove();
            purgedProfiles++;
        }
    }
    iterator = command.guild.customCommands.getCommandList().listIterator();
    while (iterator.hasNext()) {
        CCommandObject ccObject = (CCommandObject) iterator.next();
        if (userID == ccObject.getUserID()) {
            iterator.remove();
            purgedCCs++;
        }
    }
    iterator = command.guild.characters.getCharacters(command.guild.get()).listIterator();
    while (iterator.hasNext()) {
        CharacterObject charObject = (CharacterObject) iterator.next();
        if (charObject.getUserID() == userID) {
            iterator.remove();
            purgedCharacters++;
        }
    }
    iterator = command.guild.servers.getServers().listIterator();
    while (iterator.hasNext()) {
        ServerObject serverObject = (ServerObject) iterator.next();
        if (serverObject.getCreatorID() == userID) {
            iterator.remove();
            purgedServers++;
        }
    }
// iterator = Globals.getDailyMessages().getMessages().listIterator();
// while (iterator.hasNext()) {
// DailyMessage dailyObject = (DailyMessage) iterator.next();
// if (dailyObject.getUserID() == userID) {
// iterator.remove();
// purgedDailyMessages++;
// }
// }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) CharacterObject(com.github.vaerys.objects.CharacterObject) ServerObject(com.github.vaerys.objects.ServerObject) ListIterator(java.util.ListIterator) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 23 with ProfileObject

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

the class UserSettings method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args == null || args.isEmpty())
        return settings(command) + "\n\n" + missingArgs(command);
    SplitFirstObject split = new SplitFirstObject(args);
    UserObject user = Utility.getUser(command, split.getFirstWord(), false);
    if (user == null) {
        return "> Could not find user.";
    }
    ProfileObject profile = user.getProfile(command.guild);
    if (profile != null) {
        if (split.getRest() == null || split.getRest().equalsIgnoreCase("list")) {
            return sendList("", profile, command, user, false);
        }
        UserSetting toTest = UserSetting.get(split.getRest());
        if (toTest == null)
            return "> Not a valid user setting.\n" + settings(command);
        if (command.guild.config.modulePixels) {
            switch(toTest) {
                case DENIED_XP:
                    return toggleSetting(profile, UserSetting.DENIED_XP, "> **" + user.displayName + "** will now gain xp again.", "> **" + user.displayName + "** will no longer gain XP.");
                case DONT_SHOW_LEADERBOARD:
                    return toggleSetting(profile, UserSetting.DONT_SHOW_LEADERBOARD, "> **" + user.displayName + "'s** rank is now visible.", "> **" + user.displayName + "** will no longer show their rank.");
                case DONT_DECAY:
                    return toggleSetting(profile, UserSetting.DONT_DECAY, "> **" + user.displayName + "** will now have pixel decay.", "> **" + user.displayName + "** will no longer have pixel decay.");
                case DENY_AUTO_ROLE:
                    return toggleSetting(profile, UserSetting.DENY_AUTO_ROLE, "> **" + user.displayName + "** will now automatically be granted roles.", "> **" + user.displayName + "** will no longer automatically be granted roles.");
            }
        }
        if (command.guild.config.moduleCC) {
            switch(toTest) {
                case DENY_MAKE_CC:
                    return toggleSetting(profile, UserSetting.DENY_MAKE_CC, "> **" + user.displayName + "** can now make custom commands.", "> **" + user.displayName + "** can no longer make custom commands.");
                case DENY_USE_CCS:
                    return toggleSetting(profile, UserSetting.DENY_USE_CCS, "> **" + user.displayName + "** can now use custom commands.", "> **" + user.displayName + "** can no longer use custom commands.");
                case AUTO_SHITPOST:
                    return toggleSetting(profile, UserSetting.AUTO_SHITPOST, "> **" + user.displayName + "** no longer has the shitpost tag automatically added to all of their new Custom Commands.", "> **" + user.displayName + "** now has the shitpost tag automatically added to all of their new Custom Commands.");
            }
        }
        if (command.guild.config.artPinning) {
            switch(toTest) {
                case DENY_ART_PINNING:
                    return toggleSetting(profile, UserSetting.DENY_ART_PINNING, "> **" + user.displayName + "** can now pin art.", "> **" + user.displayName + "** can no longer pin art.");
            }
        }
        switch(toTest) {
            case DENY_INVITES:
                return toggleSetting(profile, UserSetting.DENY_INVITES, "> **" + user.displayName + "** can now post instant invites.", "> **" + user.displayName + "** can no longer post instant invites.");
            default:
                String response = (split.getRest() == null || split.getRest().isEmpty()) ? "" : "> Not a valid User Setting.\n\n";
                if (profile.getSettings().size() == 0) {
                    return response + "> **" + user.displayName + "** has no settings attached to their profile.\n\n" + settings(command) + "\n\n" + Utility.getCommandInfo(this, command);
                } else {
                    return sendList(response, profile, command, user, true);
                }
        }
    } else {
        return "> Invalid user.";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject) UserSetting(com.github.vaerys.enums.UserSetting)

Example 24 with ProfileObject

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

use of com.github.vaerys.objects.ProfileObject 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)

Aggregations

ProfileObject (com.github.vaerys.objects.ProfileObject)34 UserObject (com.github.vaerys.masterobjects.UserObject)13 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)10 ArrayList (java.util.ArrayList)7 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 IChannel (sx.blah.discord.handle.obj.IChannel)5 UserSetting (com.github.vaerys.enums.UserSetting)4 RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 IUser (sx.blah.discord.handle.obj.IUser)4 CCommandObject (com.github.vaerys.objects.CCommandObject)3 ListIterator (java.util.ListIterator)3 IRole (sx.blah.discord.handle.obj.IRole)3 CommandObject (com.github.vaerys.commands.CommandObject)2 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2 NumberFormat (java.text.NumberFormat)2 ZonedDateTime (java.time.ZonedDateTime)2 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 SAILType (com.github.vaerys.enums.SAILType)1