Search in sources :

Example 16 with IChannel

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

the class JoinHandler method customJoinMessages.

/**
 * Send A special message to the specified JoinMessage channel that welcomes the user to the server.
 *
 * @param user    The user that joined. ({@link UserObject})
 * @param content The Guild that the user joined. ({@link GuildObject})
 */
public static void customJoinMessages(GuildObject content, IUser user) {
    IChannel channel = content.getChannelByType(ChannelSetting.JOIN_CHANNEL);
    if (channel == null)
        return;
    Random random = new Random();
    List<JoinMessage> joinMessageList = content.channelData.getJoinMessages();
    if (joinMessageList.size() == 0)
        return;
    JoinMessage message = joinMessageList.get(random.nextInt(joinMessageList.size()));
    String response = message.getContent(new CommandObject(content, channel, user));
    RequestHandler.sendMessage(response, channel);
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) Random(java.util.Random) JoinMessage(com.github.vaerys.objects.JoinMessage)

Example 17 with IChannel

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

the class MessageHandler method handleCommand.

// Command Handler
private boolean handleCommand(CommandObject command, String args) {
    List<Command> commands = new ArrayList<>(command.guild.commands);
    IChannel currentChannel = command.channel.get();
    String commandArgs;
    for (Command c : commands) {
        if (c.isCall(args, command)) {
            commandArgs = c.getArgs(args, command);
            // log command
            command.guild.sendDebugLog(command, "COMMAND", c.getCommand(command), c.getArgs(args, command));
            // test if user has permissions
            if (!GuildHandler.testForPerms(command, c.perms)) {
                RequestHandler.sendMessage(command.user.notAllowed, currentChannel);
                return true;
            }
            // check if it is a valid channel
            if (!currentChannel.isPrivate()) {
                if (c.channel != null && !GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
                    List<IChannel> channels = command.guild.getChannelsByType(c.channel);
                    if (channels.size() != 0 && !channels.contains(command.channel.get())) {
                        List<String> list = Utility.getChannelMentions(command.user.getVisibleChannels(channels));
                        RequestHandler.sendMessage(Utility.getChannelMessage(list), command.channel.get());
                        return true;
                    }
                }
            }
            if (c.requiresArgs && (commandArgs == null || commandArgs.isEmpty())) {
                RequestHandler.sendMessage(Utility.getCommandInfo(c, command), currentChannel);
                return true;
            }
            // command logging
            handleLogging(command, c, commandArgs);
            RequestBuffer.request(() -> command.channel.get().setTypingStatus(true)).get();
            // if (!command.channel.getToggles().getTypingStatus()) {
            // command.channel.getToggles().toggleTypingStatus();
            // }
            String response = c.execute(commandArgs, command);
            RequestHandler.sendMessage(response, currentChannel);
            RequestBuffer.request(() -> command.channel.get().setTypingStatus(false)).get();
            return true;
        }
    }
    return false;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) Command(com.github.vaerys.templates.Command) ArrayList(java.util.ArrayList)

Example 18 with IChannel

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

the class ArtHandler method pinLiked.

/**
 * Handles the granting of xp to user's when their art has a :heart: reaction applied to their
 * message that was pinned with the artPinning module.
 *
 * @param command Used to parse in the variables needed to access the guild, channel, message,
 *                and user objects. these objects allows access to the api.
 * @param reacted the user that added a reaction.
 * @param owner   the user that owns the message.
 */
public static void pinLiked(CommandObject command, UserObject reacted, UserObject owner) {
    List<IChannel> channelIDS = command.guild.getChannelsByType(ChannelSetting.ART);
    // exit if not pinning art
    if (!command.guild.config.artPinning)
        return;
    // exit if pixels is off
    if (!command.guild.config.modulePixels)
        return;
    // exit if xp gain is off
    if (!command.guild.config.xpGain)
        return;
    // exit if liking art is off
    if (!command.guild.config.likeArt)
        return;
    // exit if message owner is a bot
    if (owner.get().isBot())
        return;
    // exit if there is no art channel
    if (channelIDS.size() == 0)
        return;
    // exit if this is not the art channel
    if (channelIDS.get(0).getLongID() != command.channel.longID)
        return;
    // you cant give yourself pixels via your own art
    if (owner.longID == reacted.longID)
        return;
    // exit if not pinned art
    if (!command.guild.channelData.getPinnedMessages().contains(command.message.longID))
        return;
    TrackLikes messageLikes = command.guild.channelData.getLiked(command.message.longID);
    // some thing weird happened if this is null unless its a legacy pin
    if (messageLikes == null)
        return;
    // cant like the same thing more than once
    if (messageLikes.getUsers().contains(reacted.longID))
        return;
    ProfileObject profile = owner.getProfile(command.guild);
    // exit if profile doesn't exist
    if (profile == null)
        return;
    // exit if the user should not gain pixels
    if (profile.getSettings().contains(UserSetting.NO_XP_GAIN) || profile.getSettings().contains(UserSetting.DENIED_XP))
        return;
    logger.trace(reacted.displayName + " just gave " + owner.displayName + " some pixels for liking their art.");
    // grant user xp for their nice art.
    profile.addXP(5, command.guild.config);
    messageLikes.getUsers().add(reacted.longID);
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) TrackLikes(com.github.vaerys.objects.TrackLikes) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 19 with IChannel

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

the class ChannelStats method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle("Channel Stats");
    ArrayList<String> channelTypes = new ArrayList<>();
    ArrayList<String> channelSettings = new ArrayList<>();
    if (args != null && !args.isEmpty()) {
        for (ChannelSetting s : command.guild.channelSettings) {
            if (s.toString().equalsIgnoreCase(args)) {
                List<IChannel> channels = command.guild.getChannelsByType(s);
                List<String> channelMentions = Utility.getChannelMentions(channels);
                if (channels.size() != 0) {
                    builder.appendField(s.toString(), Utility.listFormatter(channelMentions, true), false);
                    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
                    return null;
                } else {
                    if (s.isSetting()) {
                        return "> Could not find any channels with the **" + s.toString() + "** setting enabled.";
                    } else {
                        return "> Could not find a channel with the **" + s.toString() + "** type enabled.";
                    }
                }
            }
        }
        return "> Could not any channel settings with that name.";
    }
    for (ChannelSettingObject c : command.guild.channelData.getChannelSettings()) {
        if (c.getChannelIDs().contains(command.channel.longID)) {
            for (ChannelSetting setting : Globals.getChannelSettings()) {
                if (c.getType() == setting) {
                    if (setting.isSetting()) {
                        channelSettings.add(c.getType().toString());
                    } else {
                        channelTypes.add(c.getType().toString());
                    }
                }
            }
        }
    }
    if (channelSettings.size() == 0 && channelTypes.size() == 0) {
        return "> I found nothing of value.";
    }
    if (channelTypes.size() != 0) {
        builder.appendField("Types:", Utility.listFormatter(channelTypes, true), false);
    }
    if (channelSettings.size() != 0) {
        builder.appendField("Settings:", Utility.listFormatter(channelSettings, true), false);
    }
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ChannelSetting(com.github.vaerys.enums.ChannelSetting) IChannel(sx.blah.discord.handle.obj.IChannel) ChannelSettingObject(com.github.vaerys.objects.ChannelSettingObject) ArrayList(java.util.ArrayList)

Example 20 with IChannel

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

the class Command method getCommandInfo.

/**
 * Creates a message used to fetch the command's documentations
 *
 * @param command
 * @return
 */
public XEmbedBuilder getCommandInfo(CommandObject command) {
    XEmbedBuilder infoEmbed = new XEmbedBuilder(command);
    // command info
    StringBuilder builder = new StringBuilder();
    builder.append(description(command) + "\n");
    builder.append("**Type: **" + type.toString() + ".");
    // display permissions
    if (perms != null && perms.length != 0) {
        builder.append("\n**Perms: **");
        ArrayList<String> permList = new ArrayList<>(perms.length);
        for (Permissions p : perms) {
            permList.add(Utility.enumToString(p));
        }
        builder.append(Utility.listFormatter(permList, true));
    }
    if (names.length > 1) {
        List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
        aliases.remove(0);
        builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
    }
    List<SubCommandObject> objectList = subCommands.stream().filter(subCommandObject -> GuildHandler.testForPerms(command, subCommandObject.getPermissions())).collect(Collectors.toList());
    if (objectList.size() != 0)
        builder.append("\n" + Command.spacer);
    infoEmbed.withTitle("> Help - " + names()[0]);
    infoEmbed.appendField("**" + getUsage(command) + "**    " + Command.spacer, builder.toString(), true);
    for (SubCommandObject s : objectList) {
        infoEmbed.appendField(s.getCommandUsage(command) + "    " + Command.spacer, s.getHelpDesc(command), true);
    }
    // Handle channels
    List<IChannel> channels = command.guild.getChannelsByType(channel);
    List<String> channelMentions = Utility.getChannelMentions(channels);
    // channel
    if (channelMentions.size() > 0) {
        if (channelMentions.size() == 1) {
            infoEmbed.appendField("Channel ", Utility.listFormatter(channelMentions, true), false);
        } else {
            infoEmbed.appendField("Channels ", Utility.listFormatter(channelMentions, true), false);
        }
    }
    return infoEmbed;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) Arrays(java.util.Arrays) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) SAILType(com.github.vaerys.enums.SAILType) GuildHandler(com.github.vaerys.handlers.GuildHandler) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SubCommandObject(com.github.vaerys.objects.SubCommandObject) List(java.util.List) IChannel(sx.blah.discord.handle.obj.IChannel) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) Permissions(sx.blah.discord.handle.obj.Permissions) Pattern(java.util.regex.Pattern) LinkedList(java.util.LinkedList) Utility(com.github.vaerys.main.Utility) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) ArrayList(java.util.ArrayList) Permissions(sx.blah.discord.handle.obj.Permissions) SubCommandObject(com.github.vaerys.objects.SubCommandObject)

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