Search in sources :

Example 1 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingSetupStage method checkForGeneralLog.

private boolean checkForGeneralLog(CommandObject command) {
    IChannel channel = null;
    StringHandler output = new StringHandler();
    for (String s : serverLogChannelNames) {
        List<IChannel> genLogChannel = command.guild.get().getChannelsByName(s);
        if (genLogChannel.size() == 1) {
            channel = genLogChannel.get(0);
            break;
        } else if (genLogChannel.size() > 1) {
            output.append("I found multiple valid channels...").append("\nPick a channel from the list below: ```");
            String format = "\n%s [%s]";
            for (IChannel c : genLogChannel) {
                output.appendFormatted(format, c.getName(), c.getLongID());
            }
            output.append("\n```").append("Respond with the ID of the channel you want to use.");
        // handle this some special way
        }
    }
    if (channel == null)
        return false;
    output.append("Do you want to use " + channel.getName() + " as the general log channel?");
    RequestHandler.sendMessage(output.toString(), command.channel);
    return true;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 2 with StringHandler

use of com.github.vaerys.handlers.StringHandler 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);
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) GuildToggle(com.github.vaerys.templates.GuildToggle) HelpModules(com.github.vaerys.commands.help.HelpModules) StringHandler(com.github.vaerys.handlers.StringHandler) Module(com.github.vaerys.commands.admin.Module)

Example 3 with StringHandler

use of com.github.vaerys.handlers.StringHandler 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);
}
Also used : ToggleInit(com.github.vaerys.guildtoggles.ToggleInit) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) java.util(java.util) CommandObject(com.github.vaerys.commands.CommandObject) HelpSettings(com.github.vaerys.commands.help.HelpSettings) DebugMode(com.github.vaerys.guildtoggles.toggles.DebugMode) RequestHandler(com.github.vaerys.handlers.RequestHandler) SAILType(com.github.vaerys.enums.SAILType) Toggle(com.github.vaerys.commands.admin.Toggle) SetupHandler(com.github.vaerys.handlers.SetupHandler) Collectors(java.util.stream.Collectors) GuildToggle(com.github.vaerys.templates.GuildToggle) StringHandler(com.github.vaerys.handlers.StringHandler) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) GuildToggle(com.github.vaerys.templates.GuildToggle) DebugMode(com.github.vaerys.guildtoggles.toggles.DebugMode) StringHandler(com.github.vaerys.handlers.StringHandler) SAILType(com.github.vaerys.enums.SAILType)

Example 4 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method formatTimestamp.

public static String formatTimestamp(ZonedDateTime time) {
    StringHandler content = new StringHandler();
    content.append(time.getYear());
    content.append("/").append(time.getMonthValue());
    content.append("/").append(time.getDayOfMonth());
    content.append(" - ").append(time.getHour());
    content.append(":").append(time.getMinute());
    content.append(":").append(time.getSecond());
    return content.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Example 5 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method enumToString.

public static String enumToString(Enum<?> e) {
    String enumValue = e.toString();
    enumValue = enumValue.toLowerCase();
    enumValue = enumValue.replace("_", " ");
    String[] words = enumValue.split(" ");
    StringHandler fixedEnum = new StringHandler();
    for (String s : words) {
        if (fixedEnum.toString().length() != 0) {
            fixedEnum.append(" ");
        }
        fixedEnum.append(StringUtils.capitalize(s));
    }
    return fixedEnum.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Aggregations

StringHandler (com.github.vaerys.handlers.StringHandler)23 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 SAILType (com.github.vaerys.enums.SAILType)3 GuildToggle (com.github.vaerys.templates.GuildToggle)3 IChannel (sx.blah.discord.handle.obj.IChannel)3 CommandObject (com.github.vaerys.commands.CommandObject)2 HelpModules (com.github.vaerys.commands.help.HelpModules)2 HelpSettings (com.github.vaerys.commands.help.HelpSettings)2 Utility (com.github.vaerys.main.Utility)2 UserObject (com.github.vaerys.masterobjects.UserObject)2 LinkedList (java.util.LinkedList)2 Collectors (java.util.stream.Collectors)2 Module (com.github.vaerys.commands.admin.Module)1 Toggle (com.github.vaerys.commands.admin.Toggle)1 ToggleInit (com.github.vaerys.guildtoggles.ToggleInit)1 ModuleLogging (com.github.vaerys.guildtoggles.modules.ModuleLogging)1 DebugMode (com.github.vaerys.guildtoggles.toggles.DebugMode)1 GuildHandler (com.github.vaerys.handlers.GuildHandler)1 RequestHandler (com.github.vaerys.handlers.RequestHandler)1 SetupHandler (com.github.vaerys.handlers.SetupHandler)1