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);
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations