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