Search in sources :

Example 36 with IChannel

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

the class ArtHandler method unPin.

public static void unPin(CommandObject command) {
    IChannel channel = command.guild.getChannelByType(ChannelSetting.ART);
    List<Long> pins = command.guild.channelData.getPinnedMessages();
    // exit if channel is wrong
    if (channel == null || !command.channel.get().equals(channel))
        return;
    // exit if message isn't pinned
    if (!command.message.get().isPinned())
        return;
    for (long l : pins) {
        if (command.message.longID == l && command.message.author.longID == command.user.longID) {
            RequestBuffer.request(() -> channel.unpin(command.message.get()));
            RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_REMOVE_PIN)));
            IReaction reaction = command.message.getReationByName(Constants.EMOJI_ADD_PIN);
            for (IUser user : reaction.getUsers()) {
                RequestBuffer.request(() -> command.message.get().removeReaction(user, reaction));
            }
            checkList(command);
            return;
        }
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IUser(sx.blah.discord.handle.obj.IUser) IReaction(sx.blah.discord.handle.obj.IReaction)

Example 37 with IChannel

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

the class ArtHandler method pinMessage.

public static void pinMessage(CommandObject command, UserObject reacted, UserObject owner) {
    IChannel channelIDS = command.guild.getChannelByType(ChannelSetting.ART);
    List<TrackLikes> likes = command.guild.channelData.getLikes();
    List<Long> pins = command.guild.channelData.getPinnedMessages();
    // exit if not pinning art
    if (!command.guild.config.artPinning)
        return;
    // exit if the art is already pinned
    if (command.message.get().isPinned())
        return;
    // exit if message owner is a bot
    if (owner.get().isBot())
        return;
    // exit if message has already been unpinned.
    IReaction reaction = command.message.getReationByName(Constants.EMOJI_REMOVE_PIN);
    if (reaction != null && reaction.getUserReacted(command.client.bot.get())) {
        RequestBuffer.request(() -> command.message.get().removeReaction(reacted.get(), Utility.getReaction(Constants.EMOJI_ADD_PIN))).get();
        return;
    }
    // exit if user has art pinning denied.
    ProfileObject profile = reacted.getProfile(command.guild);
    if (profile != null && profile.getSettings().contains(UserSetting.DENY_ART_PINNING))
        return;
    // exit if there is no art channel
    if (channelIDS == null)
        return;
    // exit if this is not the art channel
    if (channelIDS.getLongID() != command.channel.longID)
        return;
    // exit if there is no art to be found
    if (!checkAttachments(command) && !checkMessage(command))
        return;
    try {
        // pin message
        RequestBuffer.request(() -> command.channel.get().pin(command.message.get())).get();
        // debug builder
        String name;
        if (checkAttachments(command)) {
            name = "ATTACHMENT_PIN";
        } else {
            name = "MESSAGE_PIN";
        }
        String args;
        args = command.message.getContent();
        for (IMessage.Attachment a : command.message.getAttachments()) {
            args += " <" + a.getUrl() + ">";
        }
        if (command.message.getContent() == null || command.message.getContent().isEmpty()) {
            args = args.replace("  ", "");
        }
        command.guild.sendDebugLog(command, "ART_PINNED", name, args);
        // end debug
        // add to ping
        pins.add(command.message.longID);
        // add pin response
        RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_ADD_PIN)));
        if (command.guild.config.likeArt && command.guild.config.modulePixels) {
            // add heart
            RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_LIKE_PIN)));
            // add to list
            likes.add(new TrackLikes(command.message.longID));
        }
        String response;
        if (!command.guild.config.autoArtPinning) {
            if (owner.longID == reacted.longID) {
                response = "> **" + reacted.displayName + "** Has pinned their";
            } else {
                response = "> **" + reacted.displayName + "** Has pinned **" + owner.displayName + "'s**";
            }
            response += " art by reacting with the \uD83D\uDCCC emoji.";
        } else {
            response = "> I have pinned **" + owner.displayName + "'s** art.";
        }
        if (command.guild.config.likeArt && command.guild.config.modulePixels) {
            response += "\nYou can now react with a \u2764 emoji to give the user some pixels.";
        }
        IMessage pinResponse = RequestHandler.sendMessage(response, command.channel).get();
        Thread thread = new Thread(() -> {
            try {
                logger.trace("Deleting in 2 minutes.");
                Thread.sleep(2 * 60 * 1000);
                RequestHandler.deleteMessage(pinResponse);
            } catch (InterruptedException e) {
            // do nothing
            }
        });
        checkList(command);
        thread.start();
        return;
    } catch (DiscordException e) {
        if (e.getErrorMessage().contains("already pinned")) {
            return;
        } else {
            Utility.sendStack(e);
        }
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) ProfileObject(com.github.vaerys.objects.ProfileObject) TrackLikes(com.github.vaerys.objects.TrackLikes) DiscordException(sx.blah.discord.util.DiscordException) IReaction(sx.blah.discord.handle.obj.IReaction)

Example 38 with IChannel

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

the class CCHandler method handleCommand.

public static void handleCommand(String args, CommandObject command) {
    // cc lockout handling
    SplitFirstObject commandName = new SplitFirstObject(args);
    CCommandObject commandObject = command.guild.customCommands.getCommand(commandName.getFirstWord(), command);
    String ccArgs = commandName.getRest();
    if (ccArgs == null) {
        ccArgs = "";
    }
    if (commandObject == null)
        return;
    List<IChannel> ccDenied = command.guild.getChannelsByType(ChannelSetting.CC_DENIED);
    if (ccDenied.contains(command.channel.get())) {
        RequestHandler.sendMessage("> Custom Command usage has been disabled for this channel.", command.channel);
        return;
    }
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_USE_CCS)) {
        RequestHandler.sendMessage("> Nothing interesting happens. `(ERROR: 403)`", command.channel.get());
        return;
    }
    command.guild.sendDebugLog(command, "CUSTOM_COMMAND", commandObject.getName(command), ccArgs);
    String contents = commandObject.getContents(true);
    // shitpost handling
    if (commandObject.isShitPost() && command.guild.config.shitPostFiltering && !GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
        List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.SHITPOST);
        if (channels.size() != 0 && !channels.contains(command.channel.get())) {
            channels = command.user.getVisibleChannels(channels);
            List<String> channelMentions = Utility.getChannelMentions(channels);
            RequestHandler.sendMessage(Utility.getChannelMessage(channelMentions), command.channel.get());
            return;
        }
    }
    // tag handling
    for (TagObject t : TagList.getType(TagType.CC)) {
        contents = t.handleTag(contents, command, ccArgs);
        if (contents == null)
            return;
    }
    RequestHandler.sendMessage(contents, command.channel.get());
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) TagObject(com.github.vaerys.templates.TagObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 39 with IChannel

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

the class ModuleJoinMessages method stats.

@Override
public String stats(CommandObject command) {
    IChannel channel = command.guild.getChannelByType(ChannelSetting.JOIN_CHANNEL);
    StringHandler builder = new StringHandler();
    if (channel != null) {
        builder.append("Join Channel: " + channel.mention());
    }
    if (!builder.isEmpty())
        builder.append("\n");
    builder.append("Message count: " + command.guild.channelData.getJoinMessages().size());
    return builder.toString();
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 40 with IChannel

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

the class Mute method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject userCall = new SplitFirstObject(args);
    IRole mutedRole = command.guild.getMutedRole();
    UserObject muted = Utility.getUser(command, userCall.getFirstWord(), false, false);
    if (muted == null)
        return "> Could not find user";
    if (muted.getProfile(command.guild) == null)
        muted.addProfile(command.guild);
    if (mutedRole == null)
        return "> Muted role is not configured.";
    // Un mute subtype
    if (UN_MUTE.isSubCommand(command)) {
        if (!muted.roles.contains(mutedRole))
            return "> " + muted.displayName + " is not muted.";
        command.guild.users.unMuteUser(muted.longID, command.guild.longID);
        return "> " + muted.displayName + " was UnMuted.";
    }
    if (muted.longID == command.user.longID)
        return "> Don't try to mute yourself you numpty.";
    if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
        return "> Cannot Mute " + muted.displayName + ". **" + mutedRole.getName() + "** role has a higher hierarchy than me.";
    if (!Utility.testUserHierarchy(command.user.get(), muted.get(), command.guild.get()))
        return "> Cannot Mute/UnMute " + muted.displayName + ". User hierarchy higher than yours.";
    StringHandler reason = new StringHandler(userCall.getRest());
    long timeSecs = Utility.getRepeatTimeValue(reason);
    boolean isStrike = false;
    // if (reason.toString().isEmpty()) return "> Reason Cannot be empty";
    // mute the offender
    command.guild.users.muteUser(muted.longID, timeSecs, command.guild.longID);
    // build the response
    // time value
    String timeValue = "";
    if (timeSecs > 0) {
        timeValue = Utility.formatTime(timeSecs, true);
    }
    if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
        reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
        isStrike = true;
    }
    // setup muted messages
    // name was muted for timevalue;
    String msgFormat = "> **%s** was muted%s";
    // > name was muted for timevalue by mod in channel with `reason`;
    String adminMsg = " by %s in %s with reason `%s`.";
    // name muted with reason `reason` for timevalue in channel;
    String modnote = "Muted by %s. Reason: `%s`. Time: %s. Channel: %s.";
    IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
    if (reason.toString().isEmpty())
        reason.setContent("No reason given");
    // final responses:
    String responseTime = !timeValue.isEmpty() ? " for " + timeValue : "";
    String response = String.format(msgFormat, muted.mention(), responseTime);
    if (adminChannel != null) {
        RequestHandler.sendMessage(response + String.format(adminMsg, command.user.displayName, command.channel.mention, reason), adminChannel);
    }
    muted.getProfile(command.guild).addSailModNote(String.format(modnote, command.user.displayName, reason, timeValue, command.channel.mention), command, isStrike);
    return response + ".";
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) UserObject(com.github.vaerys.masterobjects.UserObject) StringHandler(com.github.vaerys.handlers.StringHandler) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

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