use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetQuote 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)) {
if (GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES)) {
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;
} else {
return command.user.notAllowed;
}
}
int maxLength = 140;
if (user.isPatron) {
maxLength += 140;
}
ProfileObject u = user.getProfile(command.guild);
quote = Utility.removeFun(quote);
if (quote == null || quote.isEmpty())
return "> You can't have an empty quote.";
for (String s : quote.split(" ")) {
if (!Utility.checkURL(s)) {
return "> Cannot add quote. Malicious link found.";
}
}
if (adminEdit) {
if (quote.length() > maxLength) {
return "> Quote is too long...\n(must be under " + maxLength + " chars)";
}
u.setQuote(quote);
return "> " + user.displayName + "'s Quote Edited.";
} else {
if (quote.length() > maxLength) {
return "> Your Quote is too long...\n(must be under " + maxLength + " chars)";
}
u.setQuote(quote);
return "> Quote Edited.";
}
}
use of com.github.vaerys.masterobjects.UserObject 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.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class EditLinks method execute.
@Override
public String execute(String args, CommandObject command) {
UserObject user = command.user;
SplitFirstObject userCall = new SplitFirstObject(args);
boolean adminEdit = false;
if (GuildHandler.testForPerms(command, ADMIN_EDIT.getPermissions()) || GuildHandler.canBypass(command.user.get(), command.guild.get())) {
user = Utility.getUser(command, userCall.getFirstWord(), false);
if (user != null && userCall.getRest() != null && user.getProfile(command.guild) != null) {
adminEdit = true;
} else {
user = command.user;
}
}
SplitFirstObject linkName;
if (adminEdit) {
linkName = new SplitFirstObject(userCall.getRest());
} else {
linkName = new SplitFirstObject(args);
}
ProfileObject userObject = user.getProfile(command.guild);
if (userObject == null) {
return "> " + user.displayName + " Has not Spoken yet thus they have nothing to edit.";
}
userObject.setLinks();
for (UserLinkObject link : userObject.getLinks()) {
if (link.getName().equalsIgnoreCase(linkName.getFirstWord())) {
userObject.getLinks().remove(link);
if (adminEdit) {
return "> " + user.displayName + "'s Link was removed.";
} else {
return "> Link removed.";
}
}
}
int maxLinks = 5;
if (user.isPatron) {
maxLinks += 5;
}
if (linkName.getRest() == null) {
return "> Cannot add link, Must specify a URL.";
} else {
if (userObject.getLinks().size() >= maxLinks) {
if (adminEdit) {
return "> " + user.displayName + " already has " + maxLinks + " links, a link must be removed to add a new one.";
} else {
return "> You already have " + maxLinks + " links, you must remove one to add a new one.";
}
}
if (linkName.getFirstWord().length() > 15) {
return "> Link Name too long. (Max 15 chars)";
}
if (Utility.checkURL(linkName.getRest())) {
try {
new URL(linkName.getRest());
userObject.getLinks().add(new UserLinkObject(linkName.getFirstWord(), linkName.getRest()));
if (adminEdit) {
return "> New link added for " + user.displayName + ".";
} else {
return "> New link added.";
}
} catch (MalformedURLException e) {
return "> Cannot add link, Invalid URL.";
}
} else {
return "> Cannot add link, Invalid URL.";
}
}
}
Aggregations