Search in sources :

Example 1 with RewardRoleObject

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

the class PixelHandler method checkUsersRoles.

/**
 * Handler for performing automatic role allocation
 *
 * @param id      the user ID of the user that is having their roles checked.
 * @param content a wrapper around the Guild API object that contains extra information about the guild.
 */
public static void checkUsersRoles(long id, GuildObject content) {
    // do code.
    ProfileObject userObject = content.users.getUserByID(id);
    if (userObject == null) {
        return;
    }
    // if denyAutoRole exit
    if (userObject.getSettings().contains(DENY_AUTO_ROLE))
        return;
    // check if user is on the server.
    IUser user = Globals.getClient().getUserByID(userObject.getUserID());
    if (user == null) {
        return;
    }
    List<IRole> userRoles = user.getRolesForGuild(content.get());
    // 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(userObject.getCurrentLevel());
    for (RewardRoleObject r : allRewards) {
        userRoles.add(r.getRole(content));
    }
    // 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) ListIterator(java.util.ListIterator) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 2 with RewardRoleObject

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

the class PixelHandler method doDecay.

/**
 * Handler for performing pixel decay.
 *
 * @param content The Guild decay is being checked on ({@link GuildObject})
 * @param user    the profile object for the user that is having decay tested.
 */
public static void doDecay(GuildObject content, ProfileObject user) {
    long days = user.daysDecayed(content);
    if (7 > days) {
        long decay;
        user.setCurrentLevel(PixelHandler.xpToLevel(user.getXP()));
        // modifiable min and max decay days needs to be implemented.
        if (days > 15) {
            // plateaued xp decay
            decay = (long) ((15 - 7) * (Globals.avgMessagesPerDay * content.config.xpRate * content.config.xpModifier) / 8);
        } else if (days > 90) {
            // kill the xp after 90 days of absences
            decay = (long) ((90 - 7) * (Globals.avgMessagesPerDay * content.config.xpRate * content.config.xpModifier) / 8);
        } else {
            // normal xp decay formula
            decay = (long) ((days - 7) * (Globals.avgMessagesPerDay * content.config.xpRate * content.config.xpModifier) / 8);
        }
        // half decay if you turn you xp gain off but only if it is voluntary
        if (user.getSettings().contains(UserSetting.NO_XP_GAIN))
            decay = decay / 2;
        // half decay for patreon supporters
        if (user.getUser(content).isPatron)
            decay = decay / 2;
        // reward handlers
        if (PixelHandler.getRewardCount(content, user.getUserID()) != 0) {
            long pseudoLevel = xpToLevel(user.getXP() + 120);
            RewardRoleObject rewardRole = content.config.getCurrentReward(pseudoLevel);
            if (rewardRole != null) {
                long rewardFloor = rewardRole.getXp() - 100;
                if (user.getXP() > rewardFloor) {
                    user.setXp(user.getXP() - decay);
                    // your total xp should never reach below 0;
                    if (user.getXP() < 0) {
                        user.setXp(0);
                    }
                    // decay should never lower your total xp below the reward floor.
                    if (user.getXP() < rewardFloor) {
                        user.setXp(rewardFloor);
                    }
                    // if user is at level floor add setting.
                    if (user.getXP() == rewardFloor && !user.getSettings().contains(HIT_LEVEL_FLOOR)) {
                        user.getSettings().add(HIT_LEVEL_FLOOR);
                    }
                }
                // reward floor, if you are reward decay occurs
                if (days % 30 == 0 && user.getXP() == rewardFloor) {
                    user.setXp(user.getXP() - 100);
                }
            }
        }
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject)

Example 3 with RewardRoleObject

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

the class PixelHandler method rewardForLevel.

public static RewardRoleObject rewardForLevel(long currentLevel, CommandObject object) {
    Utility.sortRewards(object.guild.config.getRewardRoles());
    RewardRoleObject reward = null;
    for (RewardRoleObject r : object.guild.config.getRewardRoles()) {
        if (reward == null) {
            reward = r;
            if (reward.getLevel() > currentLevel) {
                return null;
            }
        } else {
            if (r.getLevel() <= currentLevel) {
                reward = r;
            }
        }
    }
    return reward;
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject)

Example 4 with RewardRoleObject

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

the class GuildConfig method validateRoles.

public void validateRoles() {
    IGuild guild = Globals.client.getGuildByID(guildID);
    if (guild == null) {
        return;
    }
    ListIterator iterator = cosmeticRoleIDs.listIterator();
    while (iterator.hasNext()) {
        IRole role = guild.getRoleByID((Long) iterator.next());
        if (role == null) {
            iterator.remove();
        }
    }
    iterator = modifierRoleIDs.listIterator();
    while (iterator.hasNext()) {
        IRole role = guild.getRoleByID((Long) iterator.next());
        if (role == null) {
            iterator.remove();
        }
    }
    IRole inviteAllowedRole = guild.getRoleByID(inviteAllowedID);
    if (inviteAllowedRole == null) {
        inviteAllowedID = -1;
    }
    IRole mutedRole = guild.getRoleByID(mutedRoleID);
    if (mutedRole == null) {
        mutedRoleID = -1;
    }
    IRole roleToMention = guild.getRoleByID(roleToMentionID);
    if (roleToMention == null) {
        roleToMentionID = -1;
    }
    iterator = rewardRoles.listIterator();
    while (iterator.hasNext()) {
        RewardRoleObject reward = (RewardRoleObject) iterator.next();
        IRole role = guild.getRoleByID(reward.getRoleID());
        if (role == null) {
            iterator.remove();
        }
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) IGuild(sx.blah.discord.handle.obj.IGuild) ListIterator(java.util.ListIterator)

Example 5 with RewardRoleObject

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

the class GuildConfig method getLowerReward.

public RewardRoleObject getLowerReward(RewardRoleObject rewardRole) {
    validateRoles();
    Utility.sortRewards(rewardRoles);
    ArrayList<RewardRoleObject> compareRewards = new ArrayList<>();
    RewardRoleObject lowerReward = null;
    // remove reward roles that are above it or are it.
    for (int i = 0; i < rewardRoles.size(); i++) {
        if (rewardRoles.get(i).getLevel() < rewardRole.getLevel()) {
            compareRewards.add(rewardRoles.get(i));
        }
    }
    if (compareRewards.size() == 0) {
        return null;
    }
    for (RewardRoleObject r : compareRewards) {
        if (lowerReward == null) {
            lowerReward = r;
        } else {
            if (r.getLevel() < lowerReward.getLevel()) {
                lowerReward = r;
            }
        }
    }
    return lowerReward;
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) ArrayList(java.util.ArrayList)

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