use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class JoinMessageInfo method execute.
@Override
public String execute(String args, CommandObject command) {
int index;
List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
XEmbedBuilder builder = new XEmbedBuilder(command);
try {
index = Integer.parseInt(args);
} catch (NumberFormatException e) {
return "> Not a valid number.";
}
index--;
if (index < 0 || index >= messages.size()) {
return "> Could not find message.";
}
JoinMessage message = messages.get(index);
builder.withTitle("Message #" + (index + 1));
builder.withDesc(message.getContent());
UserObject user = new UserObject(message.getCreator(), command.guild);
if (user.get() == null) {
builder.withFooterText("Could not find user.");
} else {
builder.withFooterText("Creator: @" + user.username);
builder.withFooterIcon(user.getAvatarURL());
}
builder.send(command.channel);
return null;
}
use of com.github.vaerys.masterobjects.UserObject 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.masterobjects.UserObject 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.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class TopUserForRole method execute.
@Override
public String execute(String args, CommandObject command) {
// init index value
int index = 1;
// try to get role.
IRole role = GuildHandler.getRoleFromName(args, command.guild.get());
if (role == null) {
try {
// if role get fails, try again, but this time assume the first "word" is the rank the user wants to get.
index = Integer.parseInt(new SplitFirstObject(args).getFirstWord());
} catch (NumberFormatException e) {
// not a valid number, can't find role, bork.
return "> Invalid Role";
}
// remove index from string, try to get role again.
args = new SplitFirstObject(args).getRest();
role = GuildHandler.getRoleFromName(args, command.guild.get());
if (role == null)
return "> Invalid Role.";
}
IMessage working = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
// populate list with users with role defined.
List<Long> userIDs = command.guild.get().getUsersByRole(role).stream().map(IUser::getLongID).collect(Collectors.toList());
if (userIDs.isEmpty()) {
RequestHandler.deleteMessage(working);
return "> Could not find any users with that role!";
}
userIDs.removeIf(f -> PixelHandler.rank(command.guild.users, command.guild.get(), f) == -1);
userIDs.sort((o1, o2) -> {
long rank1 = PixelHandler.rank(command.guild.users, command.guild.get(), o1);
long rank2 = PixelHandler.rank(command.guild.users, command.guild.get(), o2);
return Long.compare(rank1, rank2);
});
if (userIDs.size() == 0)
return "> Could not find any ranked users with that role.";
if (index > userIDs.size()) {
RequestHandler.deleteMessage(working);
return "> There's only " + userIDs.size() + (userIDs.size() == 1 ? " user" : " users") + " with that role.";
}
if (index == 1) {
// show an embed with the top (at most) 5 users instead.
RequestHandler.deleteMessage(working);
getEmbed(command, role, userIDs);
return null;
}
ProfileObject topUserProfile = command.guild.users.getUserByID(userIDs.get(index - 1));
UserObject topUser = topUserProfile.getUser(command.guild);
NumberFormat nf = NumberFormat.getInstance();
RequestHandler.deleteMessage(working);
return "> @" + topUser.username + ", **Pixels:** " + nf.format(topUserProfile.getXP()) + ", **Level:** " + topUserProfile.getCurrentLevel() + ", **User ID:** " + topUser.longID;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class TopUserForRole method getEmbed.
private void getEmbed(CommandObject command, IRole role, List<Long> userIDs) {
XEmbedBuilder embed = new XEmbedBuilder(command);
int showing = (userIDs.size() > 5 ? 5 : userIDs.size());
embed.withTitle("Top " + (userIDs.size() == 1 ? " user" : showing + " users") + " for role " + role.getName());
embed.withFooterText("Total ranked users with this role: " + userIDs.size());
ProfileObject userProfile;
UserObject userObject;
NumberFormat nf = NumberFormat.getInstance();
String titlef = "#%s. %s";
String contentf = "**XP:** %s\t**Level:** %s\n**UID:** %s";
for (int i = 0; i < showing; i++) {
userProfile = command.guild.users.getUserByID(userIDs.get(i));
userObject = userProfile.getUser(command.guild);
embed.appendField(String.format(titlef, i + 1, userObject.displayName), String.format(contentf, nf.format(userProfile.getXP()), userProfile.getCurrentLevel(), userObject.longID), false);
}
embed.send(command.channel);
}
Aggregations