Search in sources :

Example 11 with ProfileObject

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

the class SetGender method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user = command.user;
    String quote = args;
    boolean adminEdit = false;
    if (ADMIN_EDIT.isSubCommand(command)) {
        SplitFirstObject userCall = new SplitFirstObject(quote);
        user = Utility.getUser(command, userCall.getFirstWord(), false, true);
        if (user == null)
            return "> Could not find user.";
        quote = userCall.getRest();
        adminEdit = true;
    }
    int maxLength = 20;
    if (user.isPatron) {
        maxLength += 20;
    }
    ProfileObject u = user.getProfile(command.guild);
    quote = Utility.removeFun(quote);
    if (quote == null || quote.isEmpty())
        return "> You can't have an empty gender.";
    if (adminEdit) {
        if (quote.length() > maxLength) {
            return "> Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
        }
        u.setGender(quote);
        return "> " + user.displayName + "'s Gender Edited";
    } else {
        if (quote.length() > maxLength) {
            return "> Your Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
        }
        u.setGender(quote);
        return "> Gender Edited";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 12 with ProfileObject

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

the class EditXp method execute.

@Override
public String execute(String args, CommandObject command) {
    String[] splitArgs = args.split(" ");
    boolean xpChanged = false;
    UserObject user = Utility.getUser(command, splitArgs[0], false);
    if (user == null)
        return "> Could not find user.";
    if (Utility.testUserHierarchy(user, command.user, command.guild)) {
        return "> You do not have permission to edit " + user.displayName + "'s pixels.";
    }
    long pixelAmount;
    try {
        if (isSubType(command)) {
            if (splitArgs.length < 2)
                return getMissingArgsSubCommand(command);
            pixelAmount = Long.parseLong(splitArgs[1]);
        } else {
            if (splitArgs.length < 3)
                return missingArgs(command);
            pixelAmount = Long.parseLong(splitArgs[2]);
        }
    } catch (NumberFormatException e) {
        String value = isSubType(command) ? splitArgs[1] : splitArgs[2];
        return "> **" + value + "** Not a valid Number.";
    }
    if (pixelAmount < 0)
        return "> I don't know what negative pixels are. What are you trying to do?";
    if (pixelAmount > Constants.PIXELS_CAP)
        return "> That's too many pixels for me to be working with. (Max: " + Constants.PIXELS_CAP + ")";
    ProfileObject profile = user.getProfile(command.guild);
    if (profile == null)
        return "> " + user.displayName + " doesn't have a profile yet.";
    String out;
    if (SET_XP.isSubCommand(command)) {
        out = setXp(profile, pixelAmount, user);
        xpChanged = true;
    } else if (ADD_XP.isSubCommand(command)) {
        out = addXp(profile, pixelAmount, user);
        xpChanged = true;
    } else if (DEL_XP.isSubCommand(command)) {
        out = delXp(profile, pixelAmount, user);
        xpChanged = true;
    } else {
        String modif = splitArgs[1].toLowerCase();
        switch(modif) {
            case "+":
            case "add":
                out = addXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            case "-":
            case "rem":
            case "sub":
                out = delXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            case "=":
            case "set":
                out = setXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            default:
                out = "> Invalid modifier. Valid modifiers are **[+/-/=]** or **add/sub/set**";
                break;
        }
    }
    if (xpChanged) {
        profile.removeLevelFloor();
        GuildHandler.checkUsersRoles(user.longID, command.guild);
    }
    return out;
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 13 with ProfileObject

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

the class GuildHandler method checkUsersRoles.

public static void checkUsersRoles(long id, GuildObject content) {
    // don't try to edit your own roles ya butt.
    if (id == Client.getClient().getOurUser().getLongID())
        return;
    // do code.
    ProfileObject profile = content.users.getUserByID(id);
    if (profile == null) {
        return;
    }
    if (profile.getSettings().contains(DENY_AUTO_ROLE))
        return;
    IUser user = content.getUserByID(profile.getUserID());
    if (user == null) {
        return;
    }
    List<IRole> userRoles = user.getRolesForGuild(content.get());
    if (content.config.readRuleReward) {
        IRole ruleReward = content.getRoleByID(content.config.ruleCodeRewardID);
        if (ruleReward != null) {
            if (profile.getSettings().contains(UserSetting.READ_RULES)) {
                userRoles.add(ruleReward);
            } else {
                userRoles.remove(ruleReward);
            }
        }
    }
    if (content.config.modulePixels && content.config.xpGain) {
        // remove all rewardRoles to prep for checking.
        ListIterator iterator = userRoles.listIterator();
        while (iterator.hasNext()) {
            IRole role = (IRole) iterator.next();
            if (content.config.isRoleReward(role.getLongID())) {
                iterator.remove();
            }
        }
        // add all roles that the user should have.
        ArrayList<RewardRoleObject> allRewards = content.config.getAllRewards(profile.getCurrentLevel());
        for (RewardRoleObject r : allRewards) {
            userRoles.add(Globals.getClient().getRoleByID(r.getRoleID()));
        }
        // add the top ten role if they should have it.
        IRole topTenRole = content.get().getRoleByID(content.config.topTenRoleID);
        if (topTenRole != null) {
            long rank = PixelHandler.rank(content.users, content.get(), user.getLongID());
            if (rank <= 10 && rank > 0) {
                userRoles.add(topTenRole);
            }
        }
    }
    // only do a role update if the role count changes
    List<IRole> currentRoles = user.getRolesForGuild(content.get());
    if (!currentRoles.containsAll(userRoles) || currentRoles.size() != userRoles.size()) {
        RequestHandler.roleManagement(user, content.get(), userRoles);
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 14 with ProfileObject

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

the class SetXp method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject xpArgs = new SplitFirstObject(args);
    UserObject user = Utility.getUser(command, xpArgs.getFirstWord(), false);
    if (user == null) {
        return "> Could not find user.";
    }
    try {
        long xp = Long.parseLong(xpArgs.getRest());
        ProfileObject userObject = user.getProfile(command.guild);
        if (userObject != null) {
            userObject.setXp(xp);
            userObject.removeLevelFloor();
            GuildHandler.checkUsersRoles(user.longID, command.guild);
            return "> " + user.displayName + "'s Pixels is now set to: **" + xp + "**";
        } else {
            return "> User does not have a profile.";
        }
    } catch (NumberFormatException e) {
        return "> Invalid number";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 15 with ProfileObject

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

the class TopTen method execute.

@Override
public String execute(String args, CommandObject command) {
    ArrayList<ProfileObject> ranks = new ArrayList<>();
    ArrayList<String> response = new ArrayList<>();
    for (ProfileObject u : command.guild.users.getProfiles()) {
        long rank = PixelHandler.rank(command.guild.users, command.guild.get(), u.getUserID());
        if (rank <= 10 && rank != -1) {
            ranks.add(u);
        }
    }
    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()) + "** - ";
        StringBuilder toFormat = new StringBuilder(ranked.getDisplayName(command.guild.get()));
        toFormat.append("\n " + indent + "`Level: " + r.getCurrentLevel() + ", Pixels: " + NumberFormat.getInstance().format(r.getXP()) + "`");
        if (r.getUserID() == command.user.get().getLongID()) {
            response.add(rankPos + spacer + "**" + toFormat + "**");
        } else {
            response.add(rankPos + toFormat);
        }
    }
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle("Top Ten Users for the " + command.guild.get().getName() + " Server.");
    builder.withDesc(Utility.listFormatter(response, false));
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) 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