Search in sources :

Example 1 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder 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 2 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder 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 3 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class GetCompEntries method execute.

@Override
public String execute(String args, CommandObject command) {
    if (command.guild.competition.getEntries().size() == 0) {
        return "> No entries were found.";
    }
    List<CompObject> compObjects = command.guild.competition.getEntries();
    for (int i = 0; i < compObjects.size(); i++) {
        XEmbedBuilder builder = new XEmbedBuilder(command);
        builder.withTitle("Entry " + (i + 1));
        IUser user = command.guild.getUserByID(compObjects.get(i).getUserID());
        if (user != null) {
            builder.withDesc(user.mention());
            builder.withColor(GuildHandler.getUsersColour(user, command.guild.get()));
        }
        if (Utility.isImageLink(compObjects.get(i).getFileUrl())) {
            builder.withThumbnail(compObjects.get(i).getFileUrl());
        } else {
            if (user != null) {
                builder.withDesc(user.mention() + "\n" + compObjects.get(i).getFileUrl());
            } else {
                builder.withDesc(compObjects.get(i).getFileUrl());
            }
        }
        builder.send(command.channel);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
    }
    return "";
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) CompObject(com.github.vaerys.objects.CompObject)

Example 4 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class SearchCCs method execute.

@Override
public String execute(String args, CommandObject command) {
    List<CCommandObject> searched = new ArrayList<>();
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        StringBuilder toSearch = new StringBuilder();
        toSearch.append(c.getName().toLowerCase());
        toSearch.append(c.getContents(false).toLowerCase());
        if (c.isLocked()) {
            toSearch.append("<locked>");
        }
        if (c.isShitPost()) {
            toSearch.append("<shitpost>");
        }
        if ((toSearch.toString()).contains(args.toLowerCase())) {
            searched.add(c);
        }
    }
    if (searched.size() == 0) {
        return "> Could not find any custom commands that contains **" + args + "**.";
    }
    String title = "> Here is your search:";
    XEmbedBuilder embedBuilder = new XEmbedBuilder(command);
    String contents = Utility.listFormatter(searched.stream().map(cCommandObject -> cCommandObject.getName(command)).collect(Collectors.toList()), true);
    if (contents.length() > 2040) {
        List<String> blah = new ArrayList<>();
        StringBuilder complete = new StringBuilder();
        complete.append("> Search for \"" + args + "\", Results found: " + searched.size() + "\n");
        for (CCommandObject c : searched) {
            if (blah.size() == 8) {
                complete.append(Utility.listFormatter(blah, true));
                blah = new ArrayList<>();
                complete.replace(complete.length() - 1, complete.length(), ",");
                complete.append("\n");
            }
            blah.add(c.getName(command));
        }
        if (blah.size() != 0) {
            complete.append(Utility.listFormatter(blah, true));
        }
        if (complete.toString().endsWith(",\n")) {
            complete.replace(complete.length() - 2, complete.length() - 1, ".");
        }
        String path = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
        FileHandler.writeToFile(path, complete.toString(), false);
        File file = new File(path);
        RequestHandler.sendFile(title, file, command.channel.get());
        try {
            Thread.sleep(4000);
            Files.delete(Paths.get(path));
        } catch (IOException e) {
            Utility.sendStack(e);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
        return null;
    } else {
        embedBuilder.withTitle(title);
        embedBuilder.withDesc("```\n" + contents + spacer + "```");
        RequestHandler.sendEmbedMessage("", embedBuilder, command.channel.get());
        embedBuilder.withFooterText("Results Found: " + searched.size());
        return null;
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 5 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder 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;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) ChannelSetting(com.github.vaerys.enums.ChannelSetting) UserObject(com.github.vaerys.masterobjects.UserObject) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) UserSetting(com.github.vaerys.enums.UserSetting) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) UserObject(com.github.vaerys.masterobjects.UserObject)

Aggregations

XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)51 ArrayList (java.util.ArrayList)15 ChannelSetting (com.github.vaerys.enums.ChannelSetting)10 SAILType (com.github.vaerys.enums.SAILType)10 CommandObject (com.github.vaerys.commands.CommandObject)9 IUser (sx.blah.discord.handle.obj.IUser)9 Utility (com.github.vaerys.main.Utility)8 UserObject (com.github.vaerys.masterobjects.UserObject)8 Collectors (java.util.stream.Collectors)8 Command (com.github.vaerys.templates.Command)7 List (java.util.List)6 Permissions (sx.blah.discord.handle.obj.Permissions)6 RequestHandler (com.github.vaerys.handlers.RequestHandler)5 StringHandler (com.github.vaerys.handlers.StringHandler)5 ProfileObject (com.github.vaerys.objects.ProfileObject)5 IRole (sx.blah.discord.handle.obj.IRole)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)4 GuildToggle (com.github.vaerys.templates.GuildToggle)4 LinkedList (java.util.LinkedList)4