use of com.github.vaerys.enums.SAILType in project DiscordSailv2 by Vaerys-Dawn.
the class SettingsStage method stepText.
@Override
public void stepText(CommandObject command) {
StringHandler output = new StringHandler();
output.append("Next step is to pick which settings you want to use.\n").append("There's a lot of settings in modules, and those will be set there.\n").append("Here's a list of the settings that aren't tied to any specific module.\n");
// Get the settings and modules.
List<GuildToggle> globalToggles = ToggleInit.getToggles(false);
List<GuildToggle> modules = ToggleInit.getToggles(true);
// Sort settings
globalToggles.sort(Comparator.comparing(GuildToggle::name));
// Init additional vars
List<String> enabled = new ArrayList<>();
List<String> disabled = new ArrayList<>();
String format = "\t> **%s** - %s\n";
// skip debug mode after it's defaulted to off:
if (!new DebugMode().getDefault()) {
globalToggles.removeIf(t -> t.name() == SAILType.DEBUG_MODE);
}
// Filter toggles that are not part of modules.
List<SAILType> types = new LinkedList<>();
modules.forEach(t -> types.addAll(t.settings.stream().map(s -> s.name()).collect(Collectors.toList())));
ListIterator iterator = globalToggles.listIterator();
while (iterator.hasNext()) {
GuildToggle toggle = (GuildToggle) iterator.next();
if (types.contains(toggle.name())) {
// Is part of a module, remove from list
iterator.remove();
} else {
// is not, get extra information...
if (toggle.enabled(command.guild.config))
enabled.add(toggle.name().toString());
else
disabled.add(toggle.name().toString());
// append to list of things.
output.appendFormatted(format, toggle.name().toString(), toggle.shortDesc(command));
}
}
// Send message
output.append("\nYou can switch settings on and off with **" + Command.get(Toggle.class).getCommand(command) + "** and get more info on each setting with **" + Command.get(HelpSettings.class).getCommand(command) + "**.");
// Append additional enabled/disabled state info.
XEmbedBuilder embed = new XEmbedBuilder(command);
embed.withTitle("Global Settings");
embed.appendField("Enabled", "```" + Utility.listFormatter(enabled, true) + "```", false);
embed.appendField("Disabled", "```" + Utility.listFormatter(disabled, true) + "```", false);
RequestHandler.sendEmbedMessage(output.toString(), embed, command.channel);
}
use of com.github.vaerys.enums.SAILType in project DiscordSailv2 by Vaerys-Dawn.
the class GuildToggle method info.
public XEmbedBuilder info(CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder(command);
if (isModule()) {
builder.withTitle("Module - " + name());
} else {
builder.withTitle("Setting - " + name());
}
String fullDesc = desc(command);
if (statsOnInfo()) {
String stats = stats(command);
if (stats != null && !stats.isEmpty()) {
fullDesc += "\n\n**Stats:**\n" + stats;
}
}
builder.withDesc(fullDesc);
List<String> commandNames = commands.stream().map(command1 -> command1.getCommand(command)).collect(Collectors.toList());
commandNames.addAll(Globals.getAllCommands().stream().filter(command1 -> command1.type() == affectsType).map(command1 -> command1.getCommand(command)).collect(Collectors.toList()));
commandNames = commandNames.stream().distinct().collect(Collectors.toList());
List<SAILType> settingNames = settings.stream().map(guildSetting -> guildSetting.name()).collect(Collectors.toList());
List<ChannelSetting> channelNames = channels.stream().map(channelSetting -> channelSetting).collect(Collectors.toList());
if (commandNames.size() != 0) {
builder.appendField("Commands:", "```\n" + Utility.listFormatter(commandNames, true) + Command.spacer + "```", true);
}
if (settingNames.size() != 0) {
builder.appendField("Settings:", "```\n" + Utility.listEnumFormatter(settingNames, true) + Command.spacer + "```", true);
}
if (channelNames.size() != 0) {
builder.appendField("Channels:", "```\n" + Utility.listEnumFormatter(channelNames, true) + Command.spacer + "```", true);
}
StringBuilder footer = new StringBuilder();
if (isModule())
footer.append("Module ");
else
footer.append("Setting ");
if (enabled(command.guild.config))
footer.append("Enabled.");
else
footer.append("Disabled.");
builder.withFooterText(footer.toString());
return builder;
}
use of com.github.vaerys.enums.SAILType in project DiscordSailv2 by Vaerys-Dawn.
the class Commands method execute.
@Override
public String execute(String args, CommandObject command) {
XEmbedBuilder builder = new XEmbedBuilder(command);
List<SAILType> types = new LinkedList<>();
Map<SAILType, String> pages = new TreeMap<>();
// get dm commands
List<Command> dmCommands = Globals.getCommands(true);
// is creator
if (command.user.checkIsCreator()) {
dmCommands.addAll(Globals.getCreatorCommands(true));
// add creator type and page
List<Command> creatorCommands = Globals.getCreatorCommands(false);
pages.put(SAILType.CREATOR, buildPage(creatorCommands, command, SAILType.CREATOR, types));
types.add(SAILType.CREATOR);
}
// add dm type and page
types.add(SAILType.DM);
// check visible commands;
List<Command> visibleCommands = command.guild.commands.stream().filter(c -> GuildHandler.testForPerms(command, c.perms)).collect(Collectors.toList());
// add all extra types
types.addAll(visibleCommands.stream().map(c -> c.type).collect(Collectors.toList()));
// remove duplicates
types = types.stream().distinct().collect(Collectors.toList());
// build dm page
pages.put(SAILType.DM, buildPage(dmCommands, command, SAILType.DM, types));
// build pages
for (SAILType s : types) {
if (s == SAILType.CREATOR || s == SAILType.DM)
continue;
List<Command> typeCommands = visibleCommands.stream().filter(c -> c.type == s).collect(Collectors.toList());
for (Command c : visibleCommands) {
for (SubCommandObject sub : c.subCommands) {
if (sub.getType() == s && GuildHandler.testForPerms(command, sub.getPermissions())) {
typeCommands.add(c);
}
}
}
pages.put(s, buildPage(typeCommands, command, s, types));
}
// post type list
SAILType type = SAILType.get(args);
boolean typeNull = type == null || !types.contains(type);
boolean argsNull = args == null || args.isEmpty();
if (typeNull || argsNull) {
// get prefix
String prefix = typeNull && !argsNull ? "> There are no commands with the type: **" + args + "**." : "";
// title
builder.withTitle("Here are the Command Types I have available for use:");
// desc
builder.withDesc("```\n" + Utility.listFormatter(types.stream().map(t -> t.toString()).collect(Collectors.toList()), false) + "```\n" + missingArgs(command));
builder.send(prefix, command);
return null;
}
// send page
builder.withTitle("> Here are all of the " + type.toString() + " Commands I have available.");
builder.withDesc(pages.get(type) + missingArgs(command));
builder.send(command);
return null;
}
use of com.github.vaerys.enums.SAILType 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.enums.SAILType in project DiscordSailv2 by Vaerys-Dawn.
the class GuildObject method removeCommandsByType.
public void removeCommandsByType(SAILType type) {
ListIterator iterator = commands.listIterator();
while (iterator.hasNext()) {
Command c = (Command) iterator.next();
if (c.type == type) {
logger.trace("Command: " + c.names[0] + " removed.");
iterator.remove();
}
}
for (SAILType t : commandTypes) {
if (t == type) {
logger.trace("Type: " + t.toString() + " removed.");
commandTypes.remove(t);
return;
}
}
}
Aggregations