use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class Mute method execute.
@Override
public String execute(String args, CommandObject command) {
SplitFirstObject userCall = new SplitFirstObject(args);
IRole mutedRole = command.guild.getMutedRole();
UserObject muted = Utility.getUser(command, userCall.getFirstWord(), false, false);
if (muted == null)
return "> Could not find user";
if (muted.getProfile(command.guild) == null)
muted.addProfile(command.guild);
if (mutedRole == null)
return "> Muted role is not configured.";
// Un mute subtype
if (UN_MUTE.isSubCommand(command)) {
if (!muted.roles.contains(mutedRole))
return "> " + muted.displayName + " is not muted.";
command.guild.users.unMuteUser(muted.longID, command.guild.longID);
return "> " + muted.displayName + " was UnMuted.";
}
if (muted.longID == command.user.longID)
return "> Don't try to mute yourself you numpty.";
if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
return "> Cannot Mute " + muted.displayName + ". **" + mutedRole.getName() + "** role has a higher hierarchy than me.";
if (!Utility.testUserHierarchy(command.user.get(), muted.get(), command.guild.get()))
return "> Cannot Mute/UnMute " + muted.displayName + ". User hierarchy higher than yours.";
StringHandler reason = new StringHandler(userCall.getRest());
long timeSecs = Utility.getRepeatTimeValue(reason);
boolean isStrike = false;
// if (reason.toString().isEmpty()) return "> Reason Cannot be empty";
// mute the offender
command.guild.users.muteUser(muted.longID, timeSecs, command.guild.longID);
// build the response
// time value
String timeValue = "";
if (timeSecs > 0) {
timeValue = Utility.formatTime(timeSecs, true);
}
if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
isStrike = true;
}
// setup muted messages
// name was muted for timevalue;
String msgFormat = "> **%s** was muted%s";
// > name was muted for timevalue by mod in channel with `reason`;
String adminMsg = " by %s in %s with reason `%s`.";
// name muted with reason `reason` for timevalue in channel;
String modnote = "Muted by %s. Reason: `%s`. Time: %s. Channel: %s.";
IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
if (reason.toString().isEmpty())
reason.setContent("No reason given");
// final responses:
String responseTime = !timeValue.isEmpty() ? " for " + timeValue : "";
String response = String.format(msgFormat, muted.mention(), responseTime);
if (adminChannel != null) {
RequestHandler.sendMessage(response + String.format(adminMsg, command.user.displayName, command.channel.mention, reason), adminChannel);
}
muted.getProfile(command.guild).addSailModNote(String.format(modnote, command.user.displayName, reason, timeValue, command.channel.mention), command, isStrike);
return response + ".";
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class UserSettings method execute.
@Override
public String execute(String args, CommandObject command) {
if (args == null || args.isEmpty())
return settings(command) + "\n\n" + missingArgs(command);
SplitFirstObject split = new SplitFirstObject(args);
UserObject user = Utility.getUser(command, split.getFirstWord(), false);
if (user == null) {
return "> Could not find user.";
}
ProfileObject profile = user.getProfile(command.guild);
if (profile != null) {
if (split.getRest() == null || split.getRest().equalsIgnoreCase("list")) {
return sendList("", profile, command, user, false);
}
UserSetting toTest = UserSetting.get(split.getRest());
if (toTest == null)
return "> Not a valid user setting.\n" + settings(command);
if (command.guild.config.modulePixels) {
switch(toTest) {
case DENIED_XP:
return toggleSetting(profile, UserSetting.DENIED_XP, "> **" + user.displayName + "** will now gain xp again.", "> **" + user.displayName + "** will no longer gain XP.");
case DONT_SHOW_LEADERBOARD:
return toggleSetting(profile, UserSetting.DONT_SHOW_LEADERBOARD, "> **" + user.displayName + "'s** rank is now visible.", "> **" + user.displayName + "** will no longer show their rank.");
case DONT_DECAY:
return toggleSetting(profile, UserSetting.DONT_DECAY, "> **" + user.displayName + "** will now have pixel decay.", "> **" + user.displayName + "** will no longer have pixel decay.");
case DENY_AUTO_ROLE:
return toggleSetting(profile, UserSetting.DENY_AUTO_ROLE, "> **" + user.displayName + "** will now automatically be granted roles.", "> **" + user.displayName + "** will no longer automatically be granted roles.");
}
}
if (command.guild.config.moduleCC) {
switch(toTest) {
case DENY_MAKE_CC:
return toggleSetting(profile, UserSetting.DENY_MAKE_CC, "> **" + user.displayName + "** can now make custom commands.", "> **" + user.displayName + "** can no longer make custom commands.");
case DENY_USE_CCS:
return toggleSetting(profile, UserSetting.DENY_USE_CCS, "> **" + user.displayName + "** can now use custom commands.", "> **" + user.displayName + "** can no longer use custom commands.");
case AUTO_SHITPOST:
return toggleSetting(profile, UserSetting.AUTO_SHITPOST, "> **" + user.displayName + "** no longer has the shitpost tag automatically added to all of their new Custom Commands.", "> **" + user.displayName + "** now has the shitpost tag automatically added to all of their new Custom Commands.");
}
}
if (command.guild.config.artPinning) {
switch(toTest) {
case DENY_ART_PINNING:
return toggleSetting(profile, UserSetting.DENY_ART_PINNING, "> **" + user.displayName + "** can now pin art.", "> **" + user.displayName + "** can no longer pin art.");
}
}
switch(toTest) {
case DENY_INVITES:
return toggleSetting(profile, UserSetting.DENY_INVITES, "> **" + user.displayName + "** can now post instant invites.", "> **" + user.displayName + "** can no longer post instant invites.");
default:
String response = (split.getRest() == null || split.getRest().isEmpty()) ? "" : "> Not a valid User Setting.\n\n";
if (profile.getSettings().size() == 0) {
return response + "> **" + user.displayName + "** has no settings attached to their profile.\n\n" + settings(command) + "\n\n" + Utility.getCommandInfo(this, command);
} else {
return sendList(response, profile, command, user, true);
}
}
} else {
return "> Invalid user.";
}
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class Pixels method execute.
@Override
public String execute(String args, CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder();
UserObject user = command.user;
if (args != null && !args.isEmpty()) {
user = Utility.getUser(command, args, true);
if (user == null) {
return "> Could not find user.";
}
}
ProfileObject profile = command.guild.users.getUserByID(user.longID);
if (profile == null) {
return "> " + user.displayName + " currently does not have a profile.";
}
if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
return "> " + user.displayName + " has set their profile to private.";
}
String xpTitle = "Total Pixels: ";
String xpTotal = NumberFormat.getInstance().format(profile.getXP());
String levelTitle = "Level Progress: ";
String rankTitle = "Rank: ";
String rankTotal;
if (PixelHandler.rank(command.guild.users, command.guild.get(), profile.getUserID()) != -1 && profile.getXP() != 0) {
rankTotal = PixelHandler.rank(command.guild.users, command.guild.get(), profile.getUserID()) + "/" + PixelHandler.totalRanked(command);
} else {
rankTotal = "N/a";
}
long xpForNext = PixelHandler.levelToXP(profile.getCurrentLevel() + 1);
long xpTillNext = PixelHandler.totalXPForLevel(profile.getCurrentLevel() + 1) - profile.getXP();
long xpProgress = xpForNext - xpTillNext;
long percentToLvl = (xpProgress * 100) / xpForNext;
StringBuilder xpBar = new StringBuilder("-------------------");
int pos = (int) (percentToLvl / 5);
if (pos < 0) {
pos = 0;
}
if (pos > xpBar.length()) {
pos = xpBar.length();
}
if (user.isDecaying(command.guild)) {
xpBar.replace(pos, pos, "**<**");
} else {
xpBar.replace(pos, pos, "**>**");
}
String levelTotal = "**" + profile.getCurrentLevel() + "** [" + xpBar.toString() + "] **" + (profile.getCurrentLevel() + 1) + "**";
// colour of pixels
builder.withColor(Constants.pixelColour);
builder.withAuthorName(user.displayName + "'s Pixel stats.");
// pixel icon
builder.withAuthorIcon(Constants.PIXELS_ICON);
builder.appendField(xpTitle, xpTotal, true);
builder.appendField(rankTitle, rankTotal, true);
if (profile.getXP() != 0) {
builder.appendField(levelTitle, levelTotal, false);
} else {
builder.appendField(levelTitle, "N/a", false);
}
if (profile.getSettings().contains(UserSetting.HIT_LEVEL_FLOOR)) {
builder.withDescription("**You have decayed to the level floor,\nYou will need to level up again to see your rank.**");
}
if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
return "> Pixels sent to your Direct messages.";
}
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class Rank method execute.
@Override
public String execute(String args, CommandObject command) {
UserObject user = command.user;
if (args != null && !args.isEmpty()) {
UserObject userObject = Utility.getUser(command, args, true);
if (userObject != null) {
user = userObject;
} else {
return "> Could not find user.";
}
}
String error = "> Cannot get rank stats for " + user.displayName + ".";
if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
return "> " + user.displayName + " has set their profile to private.";
} else if (user.isPrivateProfile(command.guild) && user.longID == command.user.longID) {
return "> You cannot see your ranking as you have set your profile to private.";
}
if (user.getProfile(command.guild) == null) {
return error;
}
if (user.getProfile(command.guild).getSettings().contains(UserSetting.HIT_LEVEL_FLOOR)) {
if (user.get() != command.user.get()) {
return "> " + user.displayName + " has decayed to the level floor, they will need to level up again to see your rank.";
} else {
return "> You have decayed to the level floor, you will need to level up again to see your rank.";
}
}
// grab a copy of the list
ArrayList<ProfileObject> users = (ArrayList<ProfileObject>) command.guild.users.getProfiles().clone();
// sort profiles by Xp in ascending order (lowest Xp to highest XP).
Utility.sortUserObjects(users, true);
// test to see if said user actually has rank stats.
if (PixelHandler.rank(command.guild.users, command.guild.get(), user.longID) == -1) {
return error;
}
// build the Array of stats
for (int i = 0; i < users.size(); i++) {
if (users.get(i).getUserID() == user.longID) {
ArrayList<ProfileObject> ranks = new ArrayList();
ArrayList<String> response = new ArrayList();
int addedTop = 0;
int addedBottom = 0;
int posTop = 0;
int posBottom = 0;
// add profiles above
while (addedTop < 3 && i + posTop < users.size()) {
if (user.longID != users.get(i + posTop).getUserID() && PixelHandler.rank(command.guild.users, command.guild.get(), users.get(i + posTop).getUserID()) != -1) {
addedTop++;
ranks.add(users.get(i + posTop));
}
posTop++;
}
// add center user
ranks.add(users.get(i));
// add user below
while (addedBottom < 3 && i + posBottom > 0) {
if (user.longID != users.get(i + posBottom).getUserID() && PixelHandler.rank(command.guild.users, command.guild.get(), users.get(i + posBottom).getUserID()) != -1) {
addedBottom++;
ranks.add(users.get(i + posBottom));
}
posBottom--;
}
// sort ranked profiles
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()) + "** - ";
String toFormat = ranked.getDisplayName(command.guild.get()) + "\n " + indent + "`Level: " + r.getCurrentLevel() + ", Pixels: " + NumberFormat.getInstance().format(r.getXP()) + "`";
if (r.getUserID() == user.longID) {
response.add(rankPos + spacer + "**" + toFormat + "**");
} else {
response.add(rankPos + toFormat);
}
}
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withTitle("Rank stats for: " + user.displayName);
builder.withDesc(Utility.listFormatter(response, false));
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
}
return error;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetLevel 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 level = Long.parseLong(xpArgs.getRest());
if (level > Constants.LEVEL_CAP)
return "> No... " + level + " Is way too many levels. Im not setting your level that high.";
long xp = PixelHandler.totalXPForLevel(level);
ProfileObject userObject = user.getProfile(command.guild);
if (userObject == null) {
return "> User does not have a profile.";
}
if (Utility.testUserHierarchy(user, command.user, command.guild)) {
return "> You do not have permission to edit " + user.displayName + "'s pixels.";
}
userObject.setXp(xp);
userObject.removeLevelFloor();
GuildHandler.checkUsersRoles(user.longID, command.guild);
return "> " + user.displayName + "'s Level is now set to: **" + level + "**";
} catch (NumberFormatException e) {
return "> Invalid number";
}
}
Aggregations