use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.
the class PixelHelp method execute.
@Override
public String execute(String args, CommandObject command) {
if (args.equalsIgnoreCase("Decay") && command.guild.config.xpDecay)
return decay(command);
if (args.equalsIgnoreCase("Rules"))
return rules(command);
SplitFirstObject obe = new SplitFirstObject(args);
String mode = obe.getFirstWord();
switch(mode.toLowerCase()) {
case "leveltoxp":
case "level2xp":
case "level->xp":
return levelToXp(obe.getRest());
case "xptolevel":
case "xp2level":
case "xp->level":
return xpToLevel(obe.getRest());
default:
StringBuilder builder = new StringBuilder();
XEmbedBuilder embed = new XEmbedBuilder(command);
embed.withTitle("Pixel System Information.");
embed.withDescription("Pixels are " + command.client.bot.displayName + "'s" + " form of xp, you can gain " + (int) (command.guild.config.xpRate * command.guild.config.xpModifier) + "xp" + " once per minute by sending a message that meets all of the specific message rules.\n\n");
if (command.guild.config.getRewardRoles().size() != 0) {
for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
IRole reward = command.guild.getRoleByID(r.getRoleID());
if (reward == null) {
break;
}
builder.append("\n> **" + reward.getName() + "** -> Level: **" + r.getLevel() + "**");
}
embed.appendField("Reward Roles:", builder.toString(), true);
}
if (command.guild.config.xpModifier != 1) {
embed.appendField("\n**Current Xp Modifier:**\n", "> **x" + command.guild.config.xpModifier + "**.\n", true);
}
int random = new Random().nextInt(25);
if (random == 1) {
embed.withThumbnail(Constants.RANK_UP_IMAGE_URL);
} else {
embed.withThumbnail(Constants.LEVEL_UP_IMAGE_URL);
}
embed.appendField("Pixel and Level Calculators:", getModes(command) + "\n\n" + Utility.getCommandInfo(this, command), false);
RequestHandler.sendEmbedMessage("", embed, command.channel.get());
return null;
}
}
use of com.github.vaerys.objects.XEmbedBuilder 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.objects.XEmbedBuilder 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.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.
the class UserInfo method execute.
@Override
public String execute(String args, CommandObject command) {
UserObject user;
if (args == null || args.isEmpty()) {
user = command.user;
} else {
user = Utility.getUser(command, args, true);
}
if (user == null) {
return "> Could not find user.";
}
ProfileObject profile = user.getProfile(command.guild);
if (profile == null && user.get().isBot()) {
if (user.get().getPresence().getStatus().equals(StatusType.OFFLINE) || user.get().getPresence().getStatus().equals(StatusType.UNKNOWN)) {
return "> Could not get a profile for " + user.displayName + ".";
}
profile = new ProfileObject(user.longID);
command.guild.users.addUser(profile);
} else if (profile == null) {
return "> Could not get a profile for " + user.displayName + ".";
}
if (!GuildHandler.testForPerms(command, Permissions.ADMINISTRATOR) && (user.isPrivateProfile(command.guild) && user.longID != command.user.longID)) {
return "> " + user.displayName + " has set their profile to private.";
}
// start of the profile builder.
XEmbedBuilder builder = new XEmbedBuilder(user);
List<IRole> roles = user.roles;
ArrayList<String> roleNames = new ArrayList<>();
ArrayList<String> links = new ArrayList<>();
// If user is a bot it will display the image below as the user avatar icon.
if (user.get().isBot()) {
builder.withAuthorIcon("http://i.imgur.com/aRJpAP4.png");
}
// sets title to user Display Name;
builder.withAuthorName(user.displayName);
// sets thumbnail to user Avatar.
builder.withThumbnail(user.get().getAvatarURL());
// gets the age of the account.
long nowUTC = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
ZonedDateTime creationDate = user.get().getCreationDate().atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC);
long creationUTC = creationDate.toEpochSecond();
long difference = nowUTC - creationUTC;
// collect role names;
roleNames.addAll(roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
if (profile.getLinks() != null && profile.getLinks().size() > 0) {
links.addAll(profile.getLinks().stream().map(link -> link.toString()).collect(Collectors.toList()));
}
// builds desc
StringBuilder desc = new StringBuilder();
StringBuilder footer = new StringBuilder();
if (profile.getSettings().contains(UserSetting.READ_RULES) && command.guild.config.readRuleReward) {
builder.withFooterIcon(Constants.STICKER_STAR_URL);
// builder.withFooterIcon("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/120/glowing-star_1f31f.png");
}
if (command.guild.config.userInfoShowsDate) {
builder.withTimestamp(user.get().getCreationDate());
footer.append("UserID: " + profile.getUserID() + ", Creation Date");
// desc.append("**Account Created: **" + creationDate.format(formatter));
} else {
desc.append("**Account Created: **" + Utility.formatTimeDifference(difference));
footer.append("User ID: " + profile.getUserID());
}
builder.withFooterText(footer.toString());
desc.append("\n**Gender: **" + profile.getGender());
boolean showLevel = true;
boolean showCC = command.guild.config.moduleCC;
if (!command.guild.config.modulePixels || profile.getXP() == 0) {
showLevel = false;
}
if (showCC && !showLevel) {
desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild));
} else if (showLevel && !showCC) {
desc.append("\n**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
} else if (showLevel && showCC) {
desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild) + indent + indent + indent + "**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
}
desc.append("\n**Roles: **" + Utility.listFormatter(roleNames, true));
desc.append("\n\n*" + profile.getQuote() + "*");
desc.append("\n" + Utility.listFormatter(links, true));
if (user.isPatron) {
builder.withAuthorIcon(Constants.PATREON_ICON_URL);
}
builder.withDesc(desc.toString());
// sends Message
if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
return "> Profile sent to your Direct messages.";
}
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.
the class WhoWasThat method execute.
@Override
public String execute(String args, CommandObject command) {
GlobalUserObject user = null;
if (args.length() != 0) {
try {
long userID = Long.parseUnsignedLong(args);
user = new GlobalUserObject(userID);
} catch (NumberFormatException e) {
}
}
NumberFormat formatter = NumberFormat.getInstance();
if (user == null) {
user = new GlobalUserObject(Globals.lastDmUserID);
}
if (user.get() == null) {
return "> No user found.";
}
XEmbedBuilder embed = new XEmbedBuilder(command);
embed.withAuthorName("@" + user.username);
if (user.isPatron)
embed.withAuthorIcon(Constants.PATREON_ICON_URL);
embed.withThumbnail(user.get().getAvatarURL());
StringBuilder builder = new StringBuilder();
final double[] totalxp = { 0 };
final double[] ccActive = { 0 };
final double[] charsActive = { 0 };
final double[] serversActive = { 0 };
user.profiles.forEach(profileObject -> totalxp[0] += profileObject.getXP());
user.guilds.forEach(guildObject -> {
if (guildObject.config.moduleCC)
ccActive[0]++;
if (guildObject.config.moduleChars)
charsActive[0]++;
if (guildObject.config.moduleServers)
serversActive[0]++;
});
String mutualGuilds = Utility.listFormatter(user.guilds.stream().map(guildObject -> guildObject.get().getName()).collect(Collectors.toList()), true);
builder.append("**Mutual Guilds:** ");
if (mutualGuilds.length() > 300) {
builder.append(user.guilds.size());
} else {
builder.append(mutualGuilds);
}
builder.append("\n**Total Profiles:** " + user.profiles.size());
builder.append("\n**Total Pixels:** " + formatter.format(totalxp[0]) + " **Average Pixels:** " + formatter.format(totalxp[0] / user.profiles.size()));
builder.append("\n**Total CCs:** " + formatter.format(user.customCommands.size()));
if (ccActive[0] >= 0 && user.customCommands.size() != 0)
builder.append(" **Average CCs:** " + formatter.format((double) user.customCommands.size() / ccActive[0]));
builder.append("\n**Total Chars:** " + formatter.format(user.characters.size()));
if (charsActive[0] >= 0 && user.characters.size() != 0)
builder.append(" **Average Chars:** " + formatter.format((double) user.characters.size() / charsActive[0]));
builder.append("\n**Total Servers:** " + formatter.format(user.servers.size()));
if (serversActive[0] >= 0 && user.servers.size() != 0)
builder.append(" **Average Servers:** " + formatter.format((double) user.servers.size() / serversActive[0]));
builder.append("\n**Total DailyMessages:** " + user.dailyMessages.size());
builder.append("\n**Total Reminders:** " + user.reminders.size());
embed.withFooterText(user.longID + ", Creation Date");
embed.withTimestamp(user.get().getCreationDate());
embed.withDesc(builder.toString());
embed.send(command.channel);
return null;
}
Aggregations