Search in sources :

Example 16 with XEmbedBuilder

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

the class BotInfo method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    StringBuilder response = new StringBuilder();
    IUser creator = command.client.fetchUser(153159020528533505L);
    IUser andriel = command.client.fetchUser(175442602508812288L);
    IUser c0bra = command.client.fetchUser(222041304761237505L);
    builder.withTitle("Information about " + Globals.botName);
    response.append("Created by: **@" + creator.getName() + "#" + creator.getDiscriminator() + "**.");
    response.append("\nCreated entirely using Java 8 and the **[Discord4J Libraries](https://discord4j.com/)**.");
    response.append("\nSupport " + Globals.botName + " on **[Patreon](https://www.patreon.com/DawnFelstar)**.");
    response.append("\nFind " + Globals.botName + " on **[GitHub](https://github.com/Vaerys-Dawn/DiscordSailv2)**.");
    response.append("\nBot's Support Discord: **https://discord.gg/XSyQQrR**.");
    response.append("\n\nContributors: **@" + andriel.getName() + "#" + andriel.getDiscriminator() + "**, ");
    response.append("**@").append(c0bra.getName()).append("#").append(c0bra.getDiscriminator()).append("**.");
    builder.withDesc(response.toString());
    builder.withThumbnail(command.client.bot.getAvatarURL());
    builder.withFooterText("Bot Version: " + Globals.version + " | D4J Version: " + Globals.d4jVersion);
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser)

Example 17 with XEmbedBuilder

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

Example 18 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder 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.";
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) GuildToggle(com.github.vaerys.templates.GuildToggle) ArrayList(java.util.ArrayList) UserObject(com.github.vaerys.masterobjects.UserObject) ModuleRoles(com.github.vaerys.guildtoggles.modules.ModuleRoles) IRegion(sx.blah.discord.handle.obj.IRegion) LinkedList(java.util.LinkedList) ChannelSetting(com.github.vaerys.enums.ChannelSetting) IRole(sx.blah.discord.handle.obj.IRole) SAILType(com.github.vaerys.enums.SAILType)

Example 19 with XEmbedBuilder

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

the class ListTags method sendModes.

private void sendModes(CommandObject command, String s) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle("> Modes");
    builder.withDesc("```\n" + Utility.listFormatter(modes, false) + "```\n" + missingArgs(command));
    RequestHandler.sendEmbedMessage(s, builder, command);
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Example 20 with XEmbedBuilder

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

the class ListTags method execute.

@Override
public String execute(String args, CommandObject command) {
    List<String> list;
    XEmbedBuilder builder = new XEmbedBuilder(command);
    TagType type = TagType.get(args);
    if (args.isEmpty() && !TAGS.isSubCommand(command)) {
        sendModes(command, "");
        return null;
    } else if (TAGS.isSubCommand(command)) {
        list = TagList.getNames(TagType.CC);
    } else {
        list = TagList.getNames(type);
    }
    if (list.size() == 0) {
        sendModes(command, "> Invalid mode.");
        return null;
    }
    builder.withTitle("> Here are all of the " + StringUtils.capitalize(args) + " tags:");
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + "Tags are run in the order listed above.\n\n" + new HelpTags().missingArgs(command));
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : TagType(com.github.vaerys.enums.TagType) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

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