use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class ListChars method execute.
@Override
public String execute(String args, CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder(command);
UserObject user = command.user;
String title = "> Here are all of your characters.";
// get user
if (args != null && !args.isEmpty()) {
user = Utility.getUser(command, args, true);
if (user == null) {
return "> Could not find user.";
}
if (user.longID != command.user.longID) {
title = "> Here are all of @" + user.displayName + "'s Characters.";
}
}
// check private
if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
return "> User has set their profile to private.";
}
// generate list
List<String> list = user.characters.stream().map(c -> c.getName()).collect(Collectors.toList());
// give message if empty
if (list.size() == 0) {
return "> You do not have any characters yet. Create one with **" + new UpdateChar().getUsage(command) + "**.";
}
// build embed data
builder.withTitle(title);
builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + new CharInfo().missingArgs(command));
builder.withFooterText(user.characters.size() + "/" + command.guild.characters.maxCharsForUser(user, command.guild) + " Slots used.");
// send private char list
if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
return "> Char list sent to your Direct messages.";
}
// send regular
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetupWizard method execute.
@Override
public String execute(String args, CommandObject command) {
if (SetupHandler.isRunningSetup(command.guild)) {
return "> Setup is already running for this guild. I can't run it twice!";
}
// user can only run setup for one guild at a time
UserObject user = command.user;
for (GuildObject guildObject : Globals.getGuilds()) {
if (guildObject.config.setupUser == user.longID) {
return "> You're running setup for a different guild. I can't do more than one at a time.";
}
}
// Handle Setup beginning
String message = "Hi! I'm " + command.client.bot.displayName + " and I'm here to help you get your server set up.\n" + "This guide will walk you through a bunch of commands and things you can do to make your server exactly the way you want it.\n\n" + "You can navigate forwards and backwards in this setup with **" + new SetupBack().getUsage(command) + "** and **" + new SetupNext().getUsage(command) + "**";
if (command.user.sendDm(message) == null) {
return "> **ERROR**: I wasn't able to send you a DM! Check your server privacy settings!";
}
// send first setup stage response
SetupHandler.setSetupStage(command, SetupStage.SETUP_MODULES);
return "> Check your DMs for more instructions.";
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class Sudo method execute.
@Override
public String execute(String args, CommandObject command) {
if (!command.guild.config.debugMode)
return "> Debug mode is disabled. No Sudo for you missy.";
SplitFirstObject sudo = new SplitFirstObject(args);
UserObject user = Utility.getUser(command, sudo.getFirstWord(), false, false);
if (user == null) {
return "> Could not find user.";
}
command.setAuthor(user.get());
if (sudo.getRest() == null) {
return "> You need to specify some arguments.";
}
try {
new MessageHandler(sudo.getRest(), command, false);
} catch (Exception e) {
String errorPos = "";
for (StackTraceElement s : e.getStackTrace()) {
if (s.toString().contains("com.github.vaerys")) {
errorPos = s.toString();
break;
}
}
StringBuilder builder = new StringBuilder();
builder.append("> I caught an Error, Please send this Error message and the message that caused this error " + "to my **Direct Messages** so my developer can look at it and try to solve the issue.\n```\n");
builder.append(e.getClass().getName());
builder.append(": " + e.getMessage());
if (!errorPos.isEmpty()) {
builder.append("\n" + Constants.PREFIX_INDENT + "at " + errorPos);
}
builder.append("```");
RequestHandler.sendMessage(builder.toString(), command.channel.get());
Utility.sendStack(e);
}
return null;
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class GetGuildInfo method execute.
@Override
public String execute(String args, CommandObject command) {
XEmbedBuilder serverInfo = new XEmbedBuilder(command);
XEmbedBuilder toggles = new XEmbedBuilder(command);
XEmbedBuilder channels = new XEmbedBuilder(command);
boolean isGuildStats = GUILD_STATS.isSubCommand(command);
IChannel channel = command.user.get().getOrCreatePMChannel();
boolean hasManageServer = GuildHandler.testForPerms(command, Permissions.MANAGE_SERVER);
// todo change this to the proper impl when api allows it.
boolean isVIP = command.guild.get().getRegion().isVIPOnly();
if (isVIP) {
serverInfo.withAuthorIcon("https://i.imgur.com/m0jqzBn.png");
}
serverInfo.withThumbnail(command.guild.get().getIconURL());
serverInfo.withAuthorName(command.guild.get().getName());
serverInfo.withFooterText("Creation Date");
serverInfo.withTimestamp(command.guild.get().getCreationDate());
StringBuilder serverStats = new StringBuilder();
UserObject owner = new UserObject(command.guild.getOwner(), command.guild);
serverStats.append("**Guild ID:** " + command.guild.longID);
serverStats.append("\n**Guild Owner:** @" + owner.username);
IRegion region = command.guild.get().getRegion();
if (region != null) {
serverStats.append("\n**Region:** ");
serverStats.append(command.guild.get().getRegion().getName());
}
serverStats.append("\n**Total Users:** " + command.guild.getUsers().size());
serverStats.append("\n**Total Channels:** " + command.guild.get().getChannels().size());
serverStats.append("\n**Total Voice Channels:** " + command.guild.get().getVoiceChannels().size());
serverStats.append("\n**Total Roles:** " + command.guild.get().getRoles().size());
serverStats.append("\n**Command Prefix:** " + command.guild.config.getPrefixCommand());
if (command.guild.config.moduleCC)
serverStats.append("\n**Custom Command Prefix:** " + command.guild.config.getPrefixCC());
if (command.guild.config.rateLimiting)
serverStats.append("\n**Guild Rate Limit:** " + command.guild.config.messageLimit + "/10s");
if (hasManageServer && !isGuildStats) {
StringBuilder adminBuilder = new StringBuilder();
if (command.guild.config.maxMentions)
adminBuilder.append("\n**Max Mentions:** " + command.guild.config.maxMentionLimit);
if (command.guild.config.muteRepeatOffenders && command.guild.config.getMutedRoleID() != -1)
adminBuilder.append("\n**Messages Until AutoMute:** " + (command.guild.config.messageLimit - 3));
if (command.guild.config.denyInvites) {
IRole role = command.guild.getRoleByID(command.guild.config.getInviteAllowedID());
if (role != null) {
adminBuilder.append("\n**Invite Allowed Role:** ");
adminBuilder.append(role.getName());
}
}
if (adminBuilder.length() != 0) {
serverStats.append("\n\n**[ADMIN STATS]**" + adminBuilder.toString());
}
}
serverInfo.withDescription(serverStats.toString());
if (isGuildStats) {
RequestHandler.sendEmbedMessage("", serverInfo, command.channel.get()).get();
return null;
} else {
RequestHandler.sendEmbedMessage("", serverInfo, channel).get();
}
if (hasManageServer) {
List<SAILType> enabledModules = new LinkedList<>();
List<SAILType> disabledModules = new LinkedList<>();
List<SAILType> enabledSettings = new LinkedList<>();
List<SAILType> disabledSettings = new LinkedList<>();
for (GuildToggle t : command.guild.toggles) {
if (t.isModule()) {
if (t.enabled(command.guild.config))
enabledModules.add(t.name());
else
disabledModules.add(t.name());
} else {
if (t.enabled(command.guild.config))
enabledSettings.add(t.name());
else
disabledSettings.add(t.name());
}
}
toggles.appendField("MODULES", "**Enabled**```\n" + spacer + Utility.listEnumFormatter(enabledModules, true) + "```\n" + "**Disabled**```" + Utility.listEnumFormatter(disabledModules, true) + "```\n" + Command.spacer, true);
toggles.appendField("SETTINGS", "**Enabled**```\n" + spacer + Utility.listEnumFormatter(enabledSettings, true) + "```\n" + "**Disabled**```" + Utility.listEnumFormatter(disabledSettings, true) + "```", true);
RequestHandler.sendEmbedMessage("", toggles, channel).get();
}
if (GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
List<ChannelSetting> channelSettings = command.guild.channelSettings;
channelSettings.sort(Comparator.comparing(ChannelSetting::toString));
channelSettings.sort((o1, o2) -> Boolean.compare(o1.isSetting(), o2.isSetting()));
for (ChannelSetting s : channelSettings) {
List<String> channelList = new ArrayList<>();
for (long id : s.getIDs(command.guild)) {
IChannel ch = command.guild.getChannelByID(id);
if (ch != null) {
channelList.add("#" + ch.getName() + "");
}
}
if (channelList.size() != 0) {
String content = Utility.listFormatter(channelList, true);
channels = resetEmbed(channels, channel, command, s.toString().length() + content.length());
channels.appendField(s.toString(), content, true);
}
}
channels.withTitle("CHANNEL STATS");
RequestHandler.sendEmbedMessage("", channels, channel).get();
}
// module builders.
XEmbedBuilder moduleStats = new XEmbedBuilder(command);
List<GuildToggle> guildmodules = new ArrayList(command.guild.toggles);
GuildToggle roleModule = null;
for (GuildToggle t : guildmodules) {
if (t.name() == new ModuleRoles().name()) {
roleModule = t;
}
}
int index = guildmodules.indexOf(roleModule);
guildmodules.remove(index);
guildmodules.add(0, roleModule);
for (GuildToggle toggle : guildmodules) {
if (toggle.isModule() && toggle.enabled(command.guild.config)) {
String stats = toggle.stats(command);
if (stats != null) {
// checks to make sure the field can be added.
String[] splitStats = stats.split("\n");
List<String> toSend = new ArrayList<>();
StringBuilder builder = new StringBuilder();
for (String s : splitStats) {
if (builder.length() + s.length() + 1 > EmbedBuilder.FIELD_CONTENT_LIMIT / 4) {
toSend.add(builder.toString());
builder = new StringBuilder();
}
if (s.startsWith("<split>")) {
s = s.replace("<split>", "");
toSend.add(builder.toString());
builder = new StringBuilder();
}
builder.append(s + "\n");
}
if (builder.length() != 0) {
toSend.add(builder.toString());
}
String title = toggle.name().toString().toUpperCase() + " STATS";
if (toSend.size() != 0) {
for (int i = 0; i < toSend.size(); i++) {
moduleStats = resetEmbed(moduleStats, channel, command, title.length() + toSend.get(i).length());
if (i + 1 < toSend.size()) {
if (toSend.get(i).length() + toSend.get(i + 1).length() < EmbedBuilder.FIELD_CONTENT_LIMIT / 4) {
moduleStats.appendField(title, toSend.get(i) + "\n\n" + toSend.get(i + 1), true);
i++;
} else {
moduleStats.appendField(title, toSend.get(i), true);
}
} else {
moduleStats.appendField(title, toSend.get(i), true);
}
}
} else {
moduleStats = resetEmbed(moduleStats, channel, command, title.length() + stats.length());
moduleStats.appendField(title, stats, true);
}
}
}
}
RequestHandler.sendEmbedMessage("", moduleStats, channel).get();
return "> Info sent to Dms.";
}
use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetGender 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)) {
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;
}
int maxLength = 20;
if (user.isPatron) {
maxLength += 20;
}
ProfileObject u = user.getProfile(command.guild);
quote = Utility.removeFun(quote);
if (quote == null || quote.isEmpty())
return "> You can't have an empty gender.";
if (adminEdit) {
if (quote.length() > maxLength) {
return "> Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
}
u.setGender(quote);
return "> " + user.displayName + "'s Gender Edited";
} else {
if (quote.length() > maxLength) {
return "> Your Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
}
u.setGender(quote);
return "> Gender Edited";
}
}
Aggregations