Search in sources :

Example 1 with OffenderObject

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

the class SpamHandler method checkMentionCount.

public static boolean checkMentionCount(CommandObject command) {
    IMessage message = command.message.get();
    GuildConfig guildconfig = command.guild.config;
    IUser author = command.user.get();
    List<IRole> oldRoles = command.user.roles;
    IGuild guild = command.guild.get();
    List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.IGNORE_SPAM);
    if (channels.contains(command.channel.get()))
        return false;
    if (GuildHandler.testForPerms(command, Permissions.MENTION_EVERYONE))
        return false;
    if (message.toString().contains("@everyone") || message.toString().contains("@here")) {
        return false;
    }
    if (guildconfig.maxMentions) {
        if (message.getMentions().size() > 8) {
            RequestHandler.deleteMessage(message);
            int i = 0;
            boolean offenderFound = false;
            for (OffenderObject o : guildconfig.getOffenders()) {
                if (author.getLongID() == o.getID()) {
                    guildconfig.addOffence(o.getID());
                    command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "OFFENCE_ADDED", message.getMentions().size() + " Mentions");
                    offenderFound = true;
                    i++;
                    if (o.getCount() >= Globals.maxWarnings) {
                        String report = "> %s has been muted for repeat offences of spamming mentions.";
                        RequestHandler.roleManagement(author, guild, guildconfig.getMutedRoleID(), true);
                        command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "MUTE", o.getCount() + " Offences");
                        command.client.get().getDispatcher().dispatch(new UserRoleUpdateEvent(guild, author, oldRoles, command.user.get().getRolesForGuild(guild)));
                        // add strike in modnote
                        command.user.getProfile(command.guild).addSailModNote(String.format(report, author.mention()), command, false);
                        // send admin notification
                        RequestHandler.sendMessage(String.format(report, author.mention()), command.channel.get());
                    }
                }
            }
            if (!offenderFound) {
                guildconfig.addOffender(new OffenderObject(author.getLongID()));
            }
            String response = "> <mentionAdmin>, " + author.mention() + "  has attempted to post more than " + guildconfig.getMaxMentionLimit() + " Mentions in a single message in " + command.channel.mention + ".";
            IRole roleToMention = command.guild.getRoleByID(guildconfig.getRoleToMentionID());
            if (roleToMention != null) {
                response = response.replaceAll("<mentionAdmin>", roleToMention.mention());
            } else {
                response = response.replaceAll("<mentionAdmin>", "Admin");
            }
            RequestHandler.sendMessage(response, command.channel.get());
            return true;
        }
    }
    return false;
}
Also used : UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) OffenderObject(com.github.vaerys.objects.OffenderObject) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Aggregations

OffenderObject (com.github.vaerys.objects.OffenderObject)1 GuildConfig (com.github.vaerys.pogos.GuildConfig)1 UserRoleUpdateEvent (sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent)1