Ejemplo n.º 1
0
    def tempmute(self, event, user, duration, reason=None):
        member = event.guild.get_member(user)
        if member:
            self.can_act_on(event, member.id)
            if not event.config.mute_role:
                raise CommandFail('mute is not setup on this server')

            if event.config.mute_role in member.roles:
                raise CommandFail(u'{} is already muted'.format(member.user))

            expire_dt = parse_duration(duration)

            # Reset the infraction task so we make sure it runs after this new infraction
            self.inf_task.set_next_schedule(expire_dt)

            # Create the infraction
            Infraction.tempmute(self, event, member, reason, expire_dt)

            if event.config.confirm_actions:
                event.msg.reply(
                    maybe_string(
                        reason,
                        u':ok_hand: {u} is now muted for {t} (`{o}`)',
                        u':ok_hand: {u} is now muted for {t}',
                        u=member.user,
                        t=humanize.naturaldelta(expire_dt - datetime.utcnow()),
                    ))
        else:
            raise CommandFail('invalid user')
Ejemplo n.º 2
0
    def violate(self, violation):
        key = 'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event)
        last_violated = int(rdb.get(key) or 0)
        rdb.setex(
            'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event),
            int(time.time()), 60)

        if not last_violated > time.time() - 10:
            self.call('ModLogPlugin.log_action_ext',
                      Actions.SPAM,
                      violation.event.guild.id,
                      v=violation)

            punishment = violation.check.punishment or violation.rule.punishment
            punishment_duration = violation.check.punishment_duration or violation.rule.punishment_duration

            if punishment == PunishmentType.MUTE:
                Infraction.mute(
                    self,
                    violation.event,
                    violation.member,
                    'Spam Detected',
                )
            elif punishment == PunishmentType.TEMPMUTE:
                Infraction.tempmute(
                    self, violation.event, violation.member, 'Spam Detected',
                    datetime.utcnow() + timedelta(seconds=punishment_duration))
            elif punishment == PunishmentType.KICK:
                Infraction.kick(self, violation.event, violation.member,
                                'Spam Detected')
            elif punishment == PunishmentType.TEMPBAN:
                Infraction.tempban(
                    self, violation.event, violation.member, 'Spam Detected',
                    datetime.utcnow() + timedelta(seconds=punishment_duration))
            elif punishment == PunishmentType.BAN:
                Infraction.ban(self, violation.event, violation.member,
                               'Spam Detected', violation.event.guild)

            # Clean messages if requested
            if punishment != PunishmentType.NONE and violation.rule.clean:
                msgs = Message.select(Message.id, Message.channel_id).where(
                    (Message.guild_id == violation.event.guild.id)
                    & (Message.author_id == violation.member.id)
                    & (Message.timestamp > (datetime.utcnow() - timedelta(
                        seconds=violation.rule.clean_duration)))).limit(
                            violation.rule.clean_count).tuples()

                channels = defaultdict(list)
                for mid, chan in msgs:
                    channels[chan].append(mid)

                for channel, messages in list(channels.items()):
                    channel = self.state.channels.get(channel)
                    if not channel:
                        continue

                    channel.delete_messages(messages)
Ejemplo n.º 3
0
    def tempmute(self, event, user, duration=None, reason=None):
        if not duration and reason:
            duration = parse_duration(reason.split(' ')[0], safe=True)
            if duration:
                if ' ' in reason:
                    reason = reason.split(' ', 1)[-1]
                else:
                    reason = None
        elif duration:
            duration = parse_duration(duration)

        member = event.guild.get_member(user)
        if member:
            self.can_act_on(event, member.id)
            if not event.config.mute_role:
                raise CommandFail('mute is not setup on this server')

            if event.config.mute_role in member.roles:
                raise CommandFail(u'{} is already muted'.format(member.user))

            # If we have a duration set, this is a tempmute
            if duration:
                # Create the infraction
                Infraction.tempmute(self, event, member, reason, duration)
                self.queue_infractions()

                self.confirm_action(event, maybe_string(
                    reason,
                    u':ok_hand: {u} is now muted for {t} (`{o}`)',
                    u':ok_hand: {u} is now muted for {t}',
                    u=member.user,
                    t=humanize.naturaldelta(duration - datetime.utcnow()),
                ))
            else:
                existed = False
                # If the user is already muted check if we can take this from a temp
                #  to perma mute.
                if event.config.mute_role in member.roles:
                    existed = Infraction.clear_active(event, member.id, [Infraction.Types.TEMPMUTE])

                    # The user is 100% muted and not tempmuted at this point, so lets bail
                    if not existed:
                        raise CommandFail(u'{} is already muted'.format(member.user))

                Infraction.mute(self, event, member, reason)

                existed = u' [was temp-muted]' if existed else ''
                self.confirm_action(event, maybe_string(
                    reason,
                    u':ok_hand: {u} is now muted (`{o}`)' + existed,
                    u':ok_hand: {u} is now muted' + existed,
                    u=member.user,
                ))
        else:
            raise CommandFail('invalid user')
Ejemplo n.º 4
0
    def violate(self, violation):
        key = 'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event)
        last_violated = int(rdb.get(key) or 0)
        rdb.setex(
            'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event),
            int(time.time()), 60)

        if not last_violated > time.time() - 10:
            self.bot.plugins.get('ModLogPlugin').log_action_ext(
                Actions.SPAM_DEBUG, violation.event, v=violation)

            with self.bot.plugins.get(
                    'CorePlugin').send_control_message() as embed:
                embed.title = '{} Violated'.format(violation.label)
                embed.color = 0xfdfd96
                embed.description = violation.msg
                embed.add_field(name='Guild',
                                value=violation.event.guild.name,
                                inline=True)
                embed.add_field(name='Guild ID',
                                value=violation.event.guild.id,
                                inline=True)
                embed.add_field(name=ZERO_WIDTH_SPACE,
                                value=ZERO_WIDTH_SPACE,
                                inline=True)
                embed.add_field(name='User',
                                value=unicode(violation.member),
                                inline=True)
                embed.add_field(name='User ID',
                                value=violation.event.member.id,
                                inline=True)
                embed.add_field(name=ZERO_WIDTH_SPACE,
                                value=ZERO_WIDTH_SPACE,
                                inline=True)

            punishment = violation.check.punishment or violation.rule.punishment
            punishment_duration = violation.check.punishment_duration or violation.rule.punishment_duration

            if punishment == PunishmentType.MUTE:
                Infraction.mute(self, violation.event, violation.member,
                                'Spam Detected')
            elif punishment == PunishmentType.TEMPMUTE:
                Infraction.tempmute(
                    self, violation.event, violation.member, 'Spam Detected',
                    datetime.utcnow() + timedelta(seconds=punishment_duration))
            elif punishment == PunishmentType.KICK:
                Infraction.kick(self, violation.event, violation.member,
                                'Spam Detected')
            elif punishment == PunishmentType.TEMPBAN:
                Infraction.tempban(
                    self, violation.event, violation.member, 'Spam Detected',
                    datetime.utcnow() + timedelta(seconds=punishment_duration))
            elif punishment == PunishmentType.BAN:
                Infraction.ban(self, violation.event, violation.member,
                               'Spam Detected', violation.event.guild)

            # Clean messages if requested
            if punishment != PunishmentType.NONE and violation.rule.clean:
                msgs = Message.select(Message.id, Message.channel_id).where(
                    (Message.guild_id == violation.event.guild.id)
                    & (Message.author_id == violation.member.id)
                    & (Message.timestamp > (datetime.utcnow() - timedelta(
                        seconds=violation.rule.clean_duration)))).limit(
                            violation.rule.clean_count).tuples()

                channels = defaultdict(list)
                for mid, chan in msgs:
                    channels[chan].append(mid)

                for channel, messages in channels.items():
                    channel = self.state.channels.get(channel)
                    if not channel:
                        continue

                    channel.delete_messages(messages)
Ejemplo n.º 5
0
    def violate(self, violation):
        key = 'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event)
        last_violated = int(rdb.get(key) or 0)
        rdb.setex(
            'lv:{e.member.guild_id}:{e.member.id}'.format(e=violation.event),
            int(time.time()), 60)

        if not last_violated > time.time() - 10:
            self.call('ModLogPlugin.log_action_ext',
                      Actions.SPAM_DEBUG,
                      violation.event.guild.id,
                      v=violation)

            with self.bot.plugins.get(
                    'CorePlugin').send_spam_control_message() as embed:
                embed.title = '{} Violated'.format(violation.label)
                embed.color = 0xfdfd96
                embed.description = violation.msg
                embed.add_field(name='Guild',
                                value=violation.event.guild.name,
                                inline=True)
                embed.add_field(name='Guild ID',
                                value=violation.event.guild.id,
                                inline=True)
                embed.add_field(name=ZERO_WIDTH_SPACE,
                                value=ZERO_WIDTH_SPACE,
                                inline=True)
                embed.add_field(name='User',
                                value=unicode(violation.member),
                                inline=True)
                embed.add_field(name='User ID',
                                value=violation.event.member.id,
                                inline=True)
                embed.add_field(name=ZERO_WIDTH_SPACE,
                                value=ZERO_WIDTH_SPACE,
                                inline=True)

            punishment = violation.check.punishment or violation.rule.punishment
            punishment_duration = violation.check.punishment_duration or violation.rule.punishment_duration

            if punishment == PunishmentType.MUTE:
                if violation.rule.punishment_dms:
                    try:
                        infractions, embed = infraction_message(
                            violation.event,
                            violation.member.id,
                            'mute',
                            violation.event.guild.name,
                            str(self.state.me),
                            'Spam Detected',
                            auto=True)
                        dm = self.client.api.users_me_dms_create(
                            violation.member.id)
                        dm.send_message('You\'ve been {} in **{}**.'.format(
                            'muted', violation.event.guild.name),
                                        embed=embed)
                    except APIException:
                        pass

                Infraction.mute(self, violation.event, violation.member,
                                'Spam Detected')
            elif punishment == PunishmentType.TEMPMUTE:
                expiration_date = datetime.utcnow() + timedelta(
                    seconds=punishment_duration)
                if violation.rule.punishment_dms:
                    try:
                        infractions, embed = infraction_message(
                            violation.event,
                            violation.member.id,
                            'tempmute',
                            violation.event.guild.name,
                            str(self.state.me),
                            'Spam Detected',
                            expires=expiration_date,
                            auto=True)
                        dm = self.client.api.users_me_dms_create(
                            violation.member.id)
                        dm.send_message('You\'ve been {} in **{}**.'.format(
                            'temporarily muted', violation.event.guild.name),
                                        embed=embed)
                    except APIException:
                        pass

                Infraction.tempmute(self, violation.event, violation.member,
                                    'Spam Detected', expiration_date)
            elif punishment == PunishmentType.KICK:
                if violation.rule.punishment_dms:
                    try:
                        infractions, embed = infraction_message(
                            violation.event,
                            violation.member.id,
                            'kick',
                            violation.event.guild.name,
                            str(self.state.me),
                            'Spam Detected',
                            auto=True)
                        dm = self.client.api.users_me_dms_create(
                            violation.member.id)
                        dm.send_message('You\'ve been {} from **{}**.'.format(
                            'kicked', violation.event.guild.name),
                                        embed=embed)
                    except APIException:
                        pass

                Infraction.kick(self, violation.event, violation.member,
                                'Spam Detected')
            elif punishment == PunishmentType.TEMPBAN:
                expiration_date = datetime.utcnow() + timedelta(
                    seconds=punishment_duration)
                if violation.rule.punishment_dms:
                    try:
                        infractions, embed = infraction_message(
                            violation.event,
                            violation.member.id,
                            'tempban',
                            violation.event.guild.name,
                            str(self.state.me),
                            'Spam Detected',
                            expires=expiration_date,
                            auto=True)
                        dm = self.client.api.users_me_dms_create(
                            violation.member.id)
                        dm.send_message('You\'ve been {} from **{}**.'.format(
                            'temporarily banned', violation.event.guild.name),
                                        embed=embed)
                    except APIException:
                        pass

                Infraction.tempban(self, violation.event, violation.member,
                                   'Spam Detected', expiration_date)
            elif punishment == PunishmentType.BAN:
                if violation.rule.punishment_dms:
                    try:
                        infractions, embed = infraction_message(
                            violation.event,
                            violation.member.id,
                            'ban',
                            violation.event.guild.name,
                            str(self.state.me),
                            'Spam Detected',
                            auto=True)
                        dm = self.client.api.users_me_dms_create(
                            violation.member.id)
                        dm.send_message('You\'ve been {} from **{}**.'.format(
                            'banned', violation.event.guild.name),
                                        embed=embed)
                    except APIException:
                        pass

                Infraction.ban(self, violation.event, violation.member,
                               'Spam Detected', violation.event.guild)

            # Clean messages if requested
            if punishment != PunishmentType.NONE and violation.rule.clean:
                msgs = Message.select(Message.id, Message.channel_id).where(
                    (Message.guild_id == violation.event.guild.id)
                    & (Message.author_id == violation.member.id)
                    & (Message.timestamp > (datetime.utcnow() - timedelta(
                        seconds=violation.rule.clean_duration)))).limit(
                            violation.rule.clean_count).tuples()

                channels = defaultdict(list)
                for mid, chan in msgs:
                    channels[chan].append(mid)

                for channel, messages in channels.items():
                    channel = self.state.channels.get(channel)
                    if not channel:
                        continue

                    channel.delete_messages(messages)