Search in sources :

Example 21 with IChannel

use of sx.blah.discord.handle.obj.IChannel 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 22 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class ProfileSettings method getSettings.

private String getSettings(CommandObject object) {
    StringBuilder builder = new StringBuilder();
    List<IChannel> levelUp = object.guild.getChannelsByType(ChannelSetting.LEVEL_UP);
    builder.append("**Settings:**\n");
    if (object.guild.config.modulePixels) {
        if (levelUp.size() != 0) {
            builder.append("> " + UserSetting.SEND_LVLUP_RANK_CHANNEL + " - `Level up messages will be sent to `" + levelUp.get(0).mention() + "\n");
        }
        builder.append("> " + UserSetting.SEND_LVLUP_CURRENT_CHANNEL + " - `Level up messages will be sent to the current channel.`\n" + "> " + UserSetting.SEND_LVLUP_DMS + " - `Level up messages will be sent to your DMs.`\n" + "> " + UserSetting.DONT_SEND_LVLUP + " - `Hides your Level up messages.`\n" + "> " + UserSetting.NO_XP_GAIN + " - `Stops you from gaining pixels.`\n" + "> " + UserSetting.HIDE_RANK + " - `Hides your rank on the server.`\n" + "> " + UserSetting.NO_LEVEL_UP_REACTIONS + " - `Stops level up reactions.`\n");
    }
    builder.append("> " + UserSetting.PRIVATE_PROFILE + " - `Hides your profile from other users.`");
    if (object.guild.config.modulePixels) {
        UserSetting setting = object.guild.config.defaultLevelMode;
        if (setting == UserSetting.SEND_LVLUP_RANK_CHANNEL && levelUp.size() == 0) {
            setting = UserSetting.SEND_LVLUP_CURRENT_CHANNEL;
        }
        builder.append("\n\nCurrent Guild Default: **" + setting.toString() + "**\n");
    } else {
        builder.append("\n");
    }
    return builder.toString();
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) UserSetting(com.github.vaerys.enums.UserSetting)

Example 23 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class ProfileSettings method execute.

@Override
public String execute(String args, CommandObject command) {
    String message = "> Your Level messages will now be sent to ";
    ProfileObject userObject = command.guild.users.getUserByID(command.user.longID);
    StringBuilder builder = new StringBuilder();
    boolean pixels = command.guild.config.modulePixels;
    boolean levelChannel = command.guild.getChannelsByType(ChannelSetting.LEVEL_UP).size() != 0;
    String error = getSettings(command) + "\n" + Utility.getCommandInfo(this, command);
    for (String s : args.split(" ")) {
        UserSetting toTest = UserSetting.get(s);
        if (toTest == null) {
            return error;
        }
        if (pixels && levelChannel && toTest == UserSetting.SEND_LVLUP_RANK_CHANNEL) {
            IChannel levelUp = command.guild.getChannelByType(ChannelSetting.LEVEL_UP);
            if (levelUp != null) {
                removeLevelSettings(userObject);
                userObject.getSettings().add(UserSetting.SEND_LVLUP_RANK_CHANNEL);
                builder.append(message + levelUp.mention() + ".");
            } else {
                removeLevelSettings(userObject);
                userObject.getSettings().add(UserSetting.SEND_LVLUP_CURRENT_CHANNEL);
                builder.append(message + "the current channel.");
            }
        } else if (pixels && toTest == UserSetting.SEND_LVLUP_CURRENT_CHANNEL) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.SEND_LVLUP_CURRENT_CHANNEL);
            builder.append(message + "the current channel.");
        } else if (pixels && toTest == UserSetting.SEND_LVLUP_DMS) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.SEND_LVLUP_DMS);
            builder.append(message + "your Direct messages.");
        } else if (pixels && toTest == UserSetting.DONT_SEND_LVLUP) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.DONT_SEND_LVLUP);
            builder.append("> You will no longer see any level up messages.");
        } else if (pixels && toTest == UserSetting.NO_XP_GAIN) {
            builder.append(toggleSetting(userObject, UserSetting.NO_XP_GAIN, "> You will now gain Xp again.", "> You will no longer gain XP"));
        } else if (pixels && toTest == UserSetting.HIDE_RANK) {
            builder.append(toggleSetting(userObject, UserSetting.HIDE_RANK, "> Your rank is now visible.", "> Your rank is now hidden."));
        } else if (pixels && toTest == UserSetting.NO_LEVEL_UP_REACTIONS) {
            builder.append(toggleSetting(userObject, UserSetting.NO_LEVEL_UP_REACTIONS, "> You will now get reactions added to the message that leveled you up.", "> You will no longer get reactions added to the message that leveled you up."));
        } else if (toTest == UserSetting.PRIVATE_PROFILE) {
            builder.append(toggleSetting(userObject, UserSetting.PRIVATE_PROFILE, "> Your profile is now public.", "> Your profile is now private."));
        } else {
            if (!builder.toString().contains(error)) {
                builder.append(error);
            }
        }
        if (!builder.toString().endsWith("\n")) {
            builder.append("\n");
        }
    }
    return builder.toString();
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) ProfileObject(com.github.vaerys.objects.ProfileObject) UserSetting(com.github.vaerys.enums.UserSetting)

Example 24 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class Report method report.

public static String report(String args, CommandObject command, boolean isSilent) {
    List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.ADMIN);
    if (channels.size() != 0) {
        IChannel channel = channels.get(0);
        SplitFirstObject split = new SplitFirstObject(args);
        UserObject reported = Utility.getUser(command, split.getFirstWord(), false, false);
        if (reported == null) {
            return "> Cannot send report. Could not find user.";
        }
        if (reported.longID == command.user.longID) {
            return "> You can't report yourself.";
        }
        if (channel != null) {
            StringBuilder builder = new StringBuilder();
            IRole roleToMention = command.guild.getRoleByID(command.guild.config.getRoleToMentionID());
            if (roleToMention != null) {
                builder.append(roleToMention.mention() + "\n");
            }
            if (isSilent) {
                builder.append("**User Report - Silent**\n");
            } else {
                builder.append("**User Report**\n");
            }
            split.editRestReplace(split.getRest(), Utility.convertMentionToText(split.getRest()));
            String reason = split.getRest();
            if (split.getRest() == null) {
                reason = "No reason given.";
            }
            builder.append("Reporter: " + command.user.get().mention() + "\nReported: " + reported.get().mention() + "\nReason: `" + reason + "`");
            builder.append("\n" + command.channel.get().mention());
            IMessage message = RequestHandler.sendMessage(builder.toString(), channel).get();
            if (message == null) {
                return "> User report was not be sent. Looks like I can't send messages to " + channel.mention() + ".";
            } else {
                return "> User Report sent.";
            }
        }
        return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
    } else {
        return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) IMessage(sx.blah.discord.handle.obj.IMessage) UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 25 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project Shadbot by Shadorc.

the class GuildMemberListener method sendAutoMsg.

private void sendAutoMsg(IGuild guild, Long channelID, String msg) {
    if (channelID == null || msg == null) {
        return;
    }
    IChannel messageChannel = guild.getChannelByID(channelID);
    if (messageChannel == null) {
        return;
    }
    BotUtils.sendMessage(msg, messageChannel);
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel)

Aggregations

IChannel (sx.blah.discord.handle.obj.IChannel)44 IGuild (sx.blah.discord.handle.obj.IGuild)7 IRole (sx.blah.discord.handle.obj.IRole)7 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)7 SQLException (java.sql.SQLException)6 IUser (sx.blah.discord.handle.obj.IUser)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 CommandObject (com.github.vaerys.commands.CommandObject)3 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 UserObject (com.github.vaerys.masterobjects.UserObject)3 CCommandObject (com.github.vaerys.objects.CCommandObject)3 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IOException (java.io.IOException)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3