use of com.github.vaerys.templates.GuildToggle in project DiscordSailv2 by Vaerys-Dawn.
the class ModulesStage method stepText.
@Override
public void stepText(CommandObject command) {
StringHandler output = new StringHandler();
List<GuildToggle> modules = ToggleInit.getToggles(true);
output.append("First things first. Obviously.\n");
output.append("You're going to want to choose which modules you would like to use on your server.\n\n");
output.append("**Here's a list of modules I have for you to choose from:**\n");
String moduleItemFormat = "\t> **%s** - %s\n";
modules.sort(Comparator.comparing(GuildToggle::toString));
for (GuildToggle module : modules) {
output.appendFormatted(moduleItemFormat, module.name(), module.shortDesc(command));
}
String toggleReminder = "\nYou can toggle a module on and off with the `%s` command.\nIf you want more detailed information about the module, you can use `%s`";
output.appendFormatted(toggleReminder, new Module().getUsage(command), new HelpModules().getUsage(command));
// RequestHandler.sendMessage(output.toString(), command.user.getDmChannel());
XEmbedBuilder embed = new XEmbedBuilder(command);
StringHandler enabled = new StringHandler();
StringHandler disabled = new StringHandler();
for (GuildToggle m : modules) {
if (m.enabled(command.guild.config)) {
enabled.append(m.name() + "\n");
} else {
disabled.append(m.name() + "\n");
}
}
embed.withTitle("Here's the current list of enabled and disabled modules");
embed.appendField("Enabled Modules", enabled.toString(), true);
embed.appendField("Disabled Modules", disabled.toString(), true);
// embed.send(command.user.getDmChannel());
RequestHandler.sendEmbedMessage(output.toString(), embed, command.channel);
}
use of com.github.vaerys.templates.GuildToggle 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.templates.GuildToggle in project DiscordSailv2 by Vaerys-Dawn.
the class GuildObject method checkToggles.
private void checkToggles() {
toRemove = new ArrayList<>();
for (GuildToggle g : toggles) {
if (!g.enabled(config)) {
g.execute(this);
}
}
for (GuildToggle g : toRemove) {
ListIterator iterator = toggles.listIterator();
while (iterator.hasNext()) {
GuildToggle toggle = (GuildToggle) iterator.next();
if (toggle.name() == g.name()) {
if (g.isModule()) {
logger.trace("Module: " + g.name() + " removed.");
} else {
logger.trace("Toggle: " + g.name() + " removed.");
}
iterator.remove();
}
}
}
IChannel channel = client.get().getChannelByID(Globals.queueChannelID);
if (channel == null) {
ListIterator iterator = commands.listIterator();
while (iterator.hasNext()) {
Command command = (Command) iterator.next();
if (command.names[0] == new NewDailyMessage().names[0]) {
logger.trace(longID + ": Removed newDailyMsg command.");
iterator.remove();
}
}
}
}
use of com.github.vaerys.templates.GuildToggle in project DiscordSailv2 by Vaerys-Dawn.
the class GetGlobalStats method execute.
@Override
public String execute(String args, CommandObject command) {
ArrayList<ToggleStatsObject> toggleStats = new ArrayList<>();
ArrayList<String> outToggles = new ArrayList<>();
ArrayList<String> outModules = new ArrayList<>();
// ArrayList<ChannelStatsObject> channelStats = new ArrayList<>();
for (GuildToggle g : Globals.getGuildToggles()) {
toggleStats.add(new ToggleStatsObject(g.name().toString(), g.isModule()));
}
// for (ChannelSetting c : Globals.getChannelSettings()) {
// channelStats.add(new ChannelStatsObject(c.type(), c.isSetting()));
// }
long totalXpUsers = 0;
long totalXP = 0;
for (GuildObject g : Globals.getGuilds()) {
CommandObject object = command.setGuild(g.get());
for (ToggleStatsObject s : toggleStats) {
for (GuildToggle t : object.guild.toggles) {
if (t.name().toString().equalsIgnoreCase(s.getToggle())) {
if (t.isModule()) {
s.addOne();
} else if (t.enabled(object.guild.config) != t.getDefault()) {
s.addOne();
}
}
}
}
// }
if (command.guild.config.modulePixels) {
for (ProfileObject o : command.guild.users.getProfiles()) {
if (o.getXP() != 0) {
totalXP += o.getXP();
totalXpUsers++;
}
}
}
}
for (ToggleStatsObject t : toggleStats) {
String formatted = t.getToggle() + ": " + t.getCount();
if (t.isModule()) {
outModules.add(formatted);
} else {
outToggles.add(formatted);
}
}
StringBuilder output = new StringBuilder();
output.append("**[GLOBAL STATS]**");
output.append("\n\n**[TOGGLE STATS]**\n");
output.append(Utility.listFormatter(outToggles, false));
output.append("\n\n**[MODULE STATS]**\n");
output.append(Utility.listFormatter(outModules, false));
output.append("\n\n**[PIXEL STATS]**");
output.append("\nAvg Pixels: " + totalXP / totalXpUsers);
command.user.sendDm(output.toString());
return "> Data sent to Your DMs";
// int totalGlobalUsers = 0;
// int totalAvg = 0;
// for (IGuild guild : command.client.getGuilds()) {
// StringBuilder builder = new StringBuilder();
// long totalUsers = 0;
// long totalMessage = 0;
// long totalMessageAvg = 0;
// long topGuild = 0;
// long bottomGuild = 0;
// String topUser = null;
// String bottomUser = null;
// GuildContentObject content = Globals.getGuildContent(guild.getLongID());
// for (UserTypeObject user : content.getGuildUsers().getProfiles()) {
// if (bottomGuild == 0) {
// bottomGuild = user.getXP();
// bottomUser = user.getID();
// } else if (bottomGuild > user.getXP()) {
// bottomGuild = user.getXP();
// bottomUser = user.getID();
// }
// if (topGuild == 0) {
// topGuild = user.getXP();
// topUser = user.getID();
// } else if (topGuild < user.getXP()) {
// topGuild = user.getXP();
// topUser = user.getID();
// }
// totalMessage += user.getXP();
// totalGlobalUsers++;
// totalUsers++;
// }
// builder.append("**Guild: " + guild.getNames() + "**");
// IUser topIUser = command.client.getUserByID(topUser);
// IUser bottomIUser = command.client.getUserByID(bottomUser);
// if (topIUser != null && bottomIUser != null) {
// builder.append("\nTop User = @" + command.client.getUserByID(topUser).getNames() + "#" + command.client.getUserByID(topUser).getDiscriminator());
// builder.append(" With Total Messages " + topGuild);
// builder.append("\nBottom User = @" + command.client.getUserByID(bottomUser).getNames() + "#" + command.client.getUserByID(bottomUser).getDiscriminator());
// builder.append(" With Total Messages " + bottomGuild);
// builder.append("\nGuild Avg = " + totalMessageAvg / totalUsers);
// builder.append("\nTotal Guild Messages = " + totalMessage);
// builder.append("\nTotal Users = " + totalUsers);
// Utility.sendDM(builder.toString(), command.authorSID);
// }
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// Utility.sendStack(e);
// }
// }
// StringBuilder builder = new StringBuilder("**Global Stats**");
// builder.append("\nGlobal profiles = " + totalGlobalUsers);
// builder.append("\nGlobal Avg = " + totalAvg / totalGlobalUsers);
// Utility.sendDM(builder.toString(), command.authorSID);
// return null;
}
use of com.github.vaerys.templates.GuildToggle 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.";
}
Aggregations