Search in sources :

Example 1 with ProfileObject

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

the class PixelHandler method grantXP.

/**
 * handler for granting users pixels.
 *
 * @param object the container for all relevant API content.
 */
public static void grantXP(CommandObject object) {
    // bots don't get XP
    if (object.user.get().isBot())
        return;
    // creates a profile for the user if they don't already have one.
    ProfileObject user = new ProfileObject(object.user.longID);
    if (object.guild.users.getUserByID(object.user.longID) == null) {
        object.guild.users.getProfiles().add(user);
    } else {
        user = object.guild.users.getUserByID(object.user.longID);
    }
    // update last talked timestamp
    user.lastTalked = object.message.getTimestamp().toEpochSecond();
    // ony do xp checks if module is true
    if (!object.guild.config.modulePixels)
        return;
    if (!object.guild.config.xpGain)
        return;
    // user setting no xp gain
    if (user.getSettings().contains(NO_XP_GAIN) || user.getSettings().contains(DENIED_XP))
        return;
    // role xp denying
    IRole xpDenied = object.guild.getXPDeniedRole();
    if (xpDenied != null && object.user.roles.contains(xpDenied))
        return;
    // you can only gain xp once per min
    if (object.guild.getSpokenUsers().contains(object.user.longID))
        return;
    // messages that might be considered commands should be ignored.
    List<String> deniedPrefixes = new ArrayList<>(object.guild.config.getXpDeniedPrefixes());
    deniedPrefixes.add(object.guild.config.getPrefixCommand());
    deniedPrefixes.add(object.guild.config.getPrefixCC());
    for (String s : deniedPrefixes) {
        if (object.message.get().getContent().startsWith(s)) {
            return;
        }
    }
    // you must have typed at least 10 chars to gain xp and doesn't contain an image.
    if (object.message.get().getContent().length() < 10 && object.message.get().getAttachments().isEmpty())
        return;
    // you cannot gain xp in an xpDenied channel
    if (object.channel.settings.contains(ChannelSetting.XP_DENIED))
        return;
    // gives them their xp.
    user.addXP(object.guild.config);
    // check level cap, don't grant xp to level-capped users
    if (user.getXP() >= Constants.PIXELS_CAP)
        user.setXp(Constants.PIXELS_CAP);
    // adds to the list of users who have spoken in the last min
    object.guild.getSpokenUsers().add(object.user.longID);
    // check the level up state of the user.
    handleLevelUp(user, object);
}
Also used : ArrayList(java.util.ArrayList) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 2 with ProfileObject

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

the class PixelHandler method isUnRanked.

public static boolean isUnRanked(long userID, GuildUsers users, IGuild guild) {
    ProfileObject user = users.getUserByID(userID);
    GuildObject guildObject = Globals.getGuildContent(guild.getLongID());
    if (user == null) {
        return true;
    }
    if (guild.getUserByID(userID) == null) {
        return true;
    }
    if (user.getXP() == 0) {
        return true;
    }
    for (UserSetting s : user.getSettings()) {
        for (UserSetting test : Constants.dontLogStates) {
            if (s == test) {
                return true;
            }
        }
    }
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    long diff = now.toEpochSecond() - user.getLastTalked();
    long days = TimeUnit.DAYS.convert(diff, TimeUnit.SECONDS);
    if (days > 14 && guildObject.config.xpDecay && !user.getSettings().contains(UserSetting.DONT_DECAY)) {
        return true;
    }
    return false;
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) ZonedDateTime(java.time.ZonedDateTime) ProfileObject(com.github.vaerys.objects.ProfileObject) UserSetting(com.github.vaerys.enums.UserSetting)

Example 3 with ProfileObject

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

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

the class PixelHandler method totalRanked.

public static long totalRanked(CommandObject command) {
    long totalRanked = 0;
    for (ProfileObject u : command.guild.users.getProfiles()) {
        boolean hideRank;
        UserObject object = new UserObject(command.guild.getUserByID(u.getUserID()), command.guild);
        hideRank = !object.showRank(command.guild);
        if (command.guild.getUserByID(u.getUserID()) != null) {
            if (u.getXP() != 0 && !hideRank) {
                totalRanked++;
            }
        }
    }
    return totalRanked;
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 5 with ProfileObject

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

the class GuildUsers method addUser.

public ProfileObject addUser(long id) {
    ProfileObject user = new ProfileObject(id);
    profiles.add(user);
    return user;
}
Also used : 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