Search in sources :

Example 6 with RewardRoleObject

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

the class GuildConfig method lowestReward.

public RewardRoleObject lowestReward() {
    validateRoles();
    RewardRoleObject lowest = null;
    for (RewardRoleObject r : rewardRoles) {
        if (lowest == null) {
            lowest = r;
        } else {
            if (lowest.getLevel() > r.getLevel()) {
                lowest = r;
            }
        }
    }
    return lowest;
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject)

Example 7 with RewardRoleObject

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

the class GuildConfig method getAllRewards.

public ArrayList<RewardRoleObject> getAllRewards(long currentLevel) {
    validateRoles();
    ArrayList<RewardRoleObject> rewards = new ArrayList<>();
    for (RewardRoleObject r : rewardRoles) {
        if (r.getLevel() <= currentLevel) {
            rewards.add(r);
        }
    }
    return rewards;
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) ArrayList(java.util.ArrayList)

Example 8 with RewardRoleObject

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

the class ManagePixelRoles method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args.equalsIgnoreCase("list")) {
        XEmbedBuilder builder = new XEmbedBuilder(command);
        builder.withTitle("Pixel Roles");
        IRole xpDenied = command.guild.getXPDeniedRole();
        IRole topTen = command.guild.getTopTenRole();
        List<RewardRoleObject> rewardRoles = command.guild.config.getRewardRoles();
        if (xpDenied == null && topTen == null && rewardRoles.size() == 0) {
            return "> No roles are set up.\n" + missingArgs(command);
        }
        String desc = "";
        if (rewardRoles.size() != 0) {
            desc += "**Reward Roles**";
            for (RewardRoleObject r : rewardRoles) {
                desc += "\n> **" + command.guild.getRoleByID(r.getRoleID()).getName() + "** -> Level: **" + r.getLevel() + "**";
            }
            desc += "\n\n";
        }
        if (topTen != null) {
            desc += "**Top Ten Role**: " + topTen.getName() + "\n\n";
        }
        if (xpDenied != null) {
            desc += "**Pixel Denied Role**: " + xpDenied.getName();
        }
        builder.withDesc(desc);
        builder.send(command.channel);
        return null;
    }
    SplitFirstObject mode = new SplitFirstObject(args);
    IRole role = GuildHandler.getRoleFromName(mode.getRest(), command.guild.get());
    if (role == null) {
        return "> **" + mode.getRest() + "** is not a valid Role name.";
    }
    try {
        long level = Long.parseLong(mode.getFirstWord());
        if (level > 256 || level <= 0) {
            return "> Level must be between 1-256.";
        }
        for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
            if (r.getLevel() == level) {
                return "> That level already has a reward set.";
            }
            if (r.getRoleID() == role.getLongID()) {
                r.setLevel(level);
                return "> Level to obtain **" + role.getName() + "** is now set to level **" + level + "**.";
            }
        }
        command.guild.config.getRewardRoles().add(new RewardRoleObject(role.getLongID(), level));
        return "> The role **" + role.getName() + "** will now be awarded at level **" + level + "**.";
    } catch (NumberFormatException e) {
        switch(mode.getFirstWord().toLowerCase()) {
            case "xpdenied":
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        return "> **" + role.getName() + "** is already set as a reward role.";
                    }
                }
                if (role.getLongID() == command.guild.config.topTenRoleID) {
                    return "> **" + role.getName() + "** is already set as the server's TopTen role.";
                }
                command.guild.config.xpDeniedRoleID = role.getLongID();
                return "> **" + role.getName() + "** is now the server's XpDenied role.";
            case "topten":
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        return "> **" + role.getName() + "** is already set as a reward role.";
                    }
                }
                if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
                    return "> **" + role.getName() + "** is already set as the server's xpDenied role.";
                }
                command.guild.config.topTenRoleID = role.getLongID();
                return "> **" + role.getName() + "** is now the server's TopTen role.";
            case "remove":
                if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
                    command.guild.config.xpDeniedRoleID = -1;
                    return "> **" + role.getName() + "** is no longer the server's xpDenied role.";
                } else if (role.getLongID() == command.guild.config.topTenRoleID) {
                    command.guild.config.topTenRoleID = -1;
                    return "> **" + role.getName() + "** is no longer the server's Top Ten role.";
                }
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        command.guild.config.getRewardRoles().remove(r);
                        return "> **" + role.getName() + "** is no longer set as a reward role.";
                    }
                }
                return "> **" + role.getName() + "** is not a valid Pixel role.";
            default:
                return "> Invalid Mode.\n" + modes + Utility.getCommandInfo(this, command);
        }
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 9 with RewardRoleObject

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

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

the class TransferLevels method execute.

@Override
public String execute(String args, CommandObject command) {
    if (command.guild.config.xpGain) {
        return "> Cannot transfer levels, xp gain enabled.";
    }
    if (command.guild.config.getRewardRoles().size() == 0) {
        return "> No rewards available to grant. cannot transfer levels";
    }
    IMessage message = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
    Utility.sortRewards(command.guild.config.getRewardRoles());
    for (IUser user : command.guild.getUsers()) {
        if (!user.isBot()) {
            ProfileObject uObject = command.guild.users.getUserByID(user.getLongID());
            if (uObject == null) {
                uObject = command.guild.users.addUser(user.getLongID());
            }
            uObject.lastTalked = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
            uObject.setXp(0);
            uObject.setCurrentLevel(-1);
            for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                if (user.getRolesForGuild(command.guild.get()).contains(r.get(command.guild))) {
                    uObject.setXp(r.getXp());
                    uObject.setCurrentLevel(r.getLevel());
                }
            }
            GuildHandler.checkUsersRoles(uObject.getUserID(), command.guild);
        }
    }
    RequestHandler.deleteMessage(message);
    command.guild.config.xpGain = true;
    return "> Transfer Complete.";
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) ProfileObject(com.github.vaerys.objects.ProfileObject)

Aggregations

RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)15 ProfileObject (com.github.vaerys.objects.ProfileObject)4 IRole (sx.blah.discord.handle.obj.IRole)4 ArrayList (java.util.ArrayList)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)2 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)2 ListIterator (java.util.ListIterator)2 Random (java.util.Random)1 IGuild (sx.blah.discord.handle.obj.IGuild)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 IUser (sx.blah.discord.handle.obj.IUser)1