use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class WhatsMyColour method execute.
@Override
public String execute(String args, CommandObject command) {
UserObject user = command.user;
if (args != null && !args.isEmpty()) {
user = Utility.getUser(command, args, true, false);
if (user == null)
return "> Could not find user.";
}
boolean notAuthor = user.longID != command.user.longID;
Color color = user.getRandomColour();
XEmbedBuilder builder = new XEmbedBuilder(color);
String desc = notAuthor ? "**" + user.displayName + "'s** " : "Your ";
if (isAlias(command, names[2]) || isAlias(command, names[3])) {
desc += "color is : ";
} else {
desc += "colour is : ";
}
desc += "**#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase() + "**";
builder.withDescription(desc);
builder.send(command.channel);
return null;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class ModNote method execute.
@Override
public String execute(String args, CommandObject command) {
// Start by breaking the arguments apart
SplitFirstObject argsSplitter = new SplitFirstObject(args);
String userCall = argsSplitter.getFirstWord();
String opts = argsSplitter.getRest();
// check sub commands:
if (EDIT_MOD_NOTE.isSubCommand(command)) {
opts = "edit " + opts;
} else if (DELETE_MOD_NOTE.isSubCommand(command)) {
opts = "delete " + opts;
} else if (STRIKE_MOD_NOTE.isSubCommand(command)) {
opts = "strike " + opts;
} else if (GET_MOD_NOTE.isSubCommand(command)) {
opts = "info " + opts;
}
// empty user arg is not allowed;
if (userCall == null || userCall.isEmpty())
return missingArgs(command);
if (opts == null || opts.isEmpty())
opts = "list";
UserObject user = Utility.getUser(command, userCall, false, true);
if (user == null)
return "> Could not find user.";
if (user.get() == null) {
try {
long userID = Long.parseLong(userCall);
user = new UserObject(userID, command.guild);
} catch (NumberFormatException e) {
return "> Could not find user.";
}
}
ProfileObject profile = user.getProfile(command.guild);
if (profile == null)
return "> No profile found for " + user.displayName + ".";
long timestamp = command.message.getTimestamp().toEpochSecond();
String mode = new SplitFirstObject(opts.trim()).getFirstWord().toLowerCase();
// shortcut to "info [index]"
try {
int index = Integer.parseInt(mode);
mode = "info";
opts = "info " + index;
} catch (NumberFormatException e) {
// nop
}
if (mode.equals("list")) {
return createListEmbed(profile, command);
} else if (SPECIAL_MODES.contains(mode)) {
// these modes require special handling:
String modeOpts = new SplitFirstObject(opts).getRest();
if (modeOpts == null || modeOpts.isEmpty())
return missingArgs(command);
// try to parse an index:
int index;
try {
String modeIdx = new SplitFirstObject(modeOpts).getFirstWord();
index = Integer.parseInt(modeIdx);
if (profile.modNotes == null || profile.modNotes.size() == 0) {
return "> " + user.displayName + " doesn't have any notes yet.";
}
if (index <= 0 || index > profile.modNotes.size()) {
return "> Index out of bounds.";
}
} catch (NumberFormatException e) {
return "> I wasn't able to understand what you asked me.";
}
// cache modNotes list
List<ModNoteObject> modNotes = profile.modNotes;
switch(mode) {
// "edit" mode
case "edit":
String newNote = new SplitFirstObject(modeOpts).getRest();
modNotes.get(index - 1).editNote(newNote, command.user.longID, timestamp);
return "> Note #" + index + " edited for user " + user.displayName + ".";
// "info" mode
case "info":
createInfoEmbed(profile, command, index - 1);
return null;
// strike
case "strike":
boolean strike = modNotes.get(index - 1).getStrike();
if (strike) {
modNotes.get(index - 1).setStrike(false);
return "> Strike cleared for note " + index + " for user " + user.displayName + ".";
} else {
modNotes.get(index - 1).setStrike(true);
return "> Strike set for note " + index + " for user " + user.displayName + ".";
}
// "delete" command
case "delete":
case "del":
case "remove":
case "rem":
modNotes.remove(index - 1);
return "> Note #" + index + " for " + user.displayName + " deleted.";
}
} else {
if (profile.modNotes == null)
profile.modNotes = new LinkedList<>();
profile.modNotes.add(new ModNoteObject(opts, command.user.longID, timestamp));
return String.format("> Note added for %s at index %d.", user.displayName, profile.modNotes.size());
}
return "> This code should be unreachable.";
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class ModNote method createListEmbed.
private String createListEmbed(ProfileObject user, CommandObject command) {
if (user.modNotes == null || user.modNotes.size() == 0) {
return "> " + user.getUser(command.guild).displayName + " doesn't have any notes yet.";
}
UserObject userObject = user.getUser(command.guild);
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withColor(userObject.color);
builder.withTitle("Notes for " + userObject.displayName);
// avatar
if (userObject.get() != null)
builder.withThumbnail(userObject.get().getAvatarURL());
else
builder.withThumbnail(user.getDefaultAvatarURL());
// get all notes and put together the bits and bobs
int counter = 0;
String noteLine = "**Note #%d:**\n%s\n";
StringHandler content = new StringHandler();
for (ModNoteObject noteObject : user.modNotes) {
String shortNote = Utility.truncateString(Utility.removeFun(noteObject.getNote()), 65);
if (noteObject.getStrike()) {
content.append("⚠ ");
}
content.append(String.format(noteLine, ++counter, shortNote));
}
builder.withDesc(content.toString());
// finalize and send message:
builder.withFooterText("Total Notes: " + user.modNotes.size());
builder.send(command.channel);
return null;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class ModNote method createInfoEmbed.
private void createInfoEmbed(ProfileObject user, CommandObject command, int index) {
UserObject userObject = user.getUser(command.guild);
XEmbedBuilder builder = new XEmbedBuilder(userObject);
ModNoteObject noteObject = user.modNotes.get(index);
String displayName = user.getUser(command.guild).displayName;
// title and avatar of user in question.
if (noteObject.getStrike()) {
builder.withTitle("⚠ Note " + (index + 1) + " - " + displayName);
} else {
builder.withTitle("Note " + (index + 1) + " - " + displayName);
}
if (userObject.get() != null)
builder.withThumbnail(userObject.get().getAvatarURL());
else
builder.withThumbnail(user.getDefaultAvatarURL());
// add note to embed
builder.appendDesc(noteObject.getNote());
// Get a UserObject from the stored ID to add to the embed.
UserObject creator = new UserObject(command.guild.getUserByID(noteObject.getCreatorId()), command.guild);
builder.withFooterText("Created by " + creator.displayName);
builder.withFooterIcon(creator.get().getAvatarURL());
builder.withTimestamp(noteObject.getTimestamp() * 1000);
if (noteObject.getEditorId() != -1) {
// get editor's info and display it?
UserObject editor = new UserObject(command.guild.getUserByID(noteObject.getEditorId()), command.guild);
String editFieldText = "\n\n*Last edited by %s %s*";
long diff = command.message.getTimestamp().toEpochSecond() - noteObject.getLastEditedTimestamp();
if (diff >= 86400 * 7) {
// 7d
String editDate = new SimpleDateFormat("dd/MMM/yyyy").format(noteObject.getLastEditedTimestamp() * 1000);
builder.appendDesc(String.format(editFieldText, editor.displayName, "on " + editDate));
} else {
builder.appendDesc(String.format(editFieldText, editor.displayName, Utility.formatTimeDifference(diff)));
}
}
builder.send(command.channel);
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class Report method report.
public static String report(String args, CommandObject command, boolean isSilent) {
List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.ADMIN);
if (channels.size() != 0) {
IChannel channel = channels.get(0);
SplitFirstObject split = new SplitFirstObject(args);
UserObject reported = Utility.getUser(command, split.getFirstWord(), false, false);
if (reported == null) {
return "> Cannot send report. Could not find user.";
}
if (reported.longID == command.user.longID) {
return "> You can't report yourself.";
}
if (channel != null) {
StringBuilder builder = new StringBuilder();
IRole roleToMention = command.guild.getRoleByID(command.guild.config.getRoleToMentionID());
if (roleToMention != null) {
builder.append(roleToMention.mention() + "\n");
}
if (isSilent) {
builder.append("**User Report - Silent**\n");
} else {
builder.append("**User Report**\n");
}
split.editRestReplace(split.getRest(), Utility.convertMentionToText(split.getRest()));
String reason = split.getRest();
if (split.getRest() == null) {
reason = "No reason given.";
}
builder.append("Reporter: " + command.user.get().mention() + "\nReported: " + reported.get().mention() + "\nReason: `" + reason + "`");
builder.append("\n" + command.channel.get().mention());
IMessage message = RequestHandler.sendMessage(builder.toString(), channel).get();
if (message == null) {
return "> User report was not be sent. Looks like I can't send messages to " + channel.mention() + ".";
} else {
return "> User Report sent.";
}
}
return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
} else {
return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
}
}
Aggregations