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)
def tempban(self, event, duration, user, reason=None): member = event.guild.get_member(user) if member: self.can_act_on(event, member.id) expires_dt = parse_duration(duration) Infraction.tempban(self, event, member, reason, expires_dt) self.queue_infractions() self.confirm_action(event, maybe_string( reason, u':ok_hand: temp-banned {u} for {t} (`{o}`)', u':ok_hand: temp-banned {u} for {t}', u=member.user, t=humanize.naturaldelta(expires_dt - datetime.utcnow()), )) else: raise CommandFail('invalid user')
def on_message_create(self, event): if not event.config.DONT_MENTION_B1NZY: return if B1NZY_USER_ID not in event.mentions: return member = event.guild.get_member(event.author) if not member or member.roles: return duration = datetime.utcnow() + timedelta(days=7) Infraction.tempban(self, event, member, 'AUTOBAN - mentioned b1nzy', duration) event.message.reply( u'{} pinged b1nzy for some reason, they are rip now...'.format( member))
def tempban(self, event, duration, user, reason=None): member = event.guild.get_member(user) if member: expires_dt = parse_duration(duration) self.inf_task.set_next_schedule(expires_dt) Infraction.tempban(self, event, member, reason, expires_dt) if event.config.confirm_actions: event.msg.reply( maybe_string( reason, u':ok_hand: temp-banned {u} for {t} (`{o}`)', u':ok_hand: temp-banned {u} for {t}', u=member.user, t=humanize.naturaldelta(expires_dt - datetime.utcnow()), )) else: raise CommandFail('invalid user')
def tempban(self, event, duration, user, reason=None): member = event.guild.get_member(user) if member: self.can_act_on(event, member.id) expires_dt = parse_duration(duration) if event.config.limit_temp.duration_limit_level: if event.user_level <= event.config.limit_temp.duration_limit_level: if expires_dt > parse_duration( event.config.limit_temp.maximum_limited_duration): raise CommandFail( 'You cannot temp ban users for longer than ' + event.config.limit_temp.maximum_limited_duration) if event.config.notify_action_on: if event.config.notify_action_on.bans: try: event.guild.get_member(user.id).user.open_dm( ).send_message( 'You have been **Temporarily Banned** in the guild **{}** for **{}** for `{}`' .format( event.guild.name, humanize.naturaldelta(expires_dt - datetime.utcnow()), reason or 'no reason specified.')) except: pass else: pass else: pass Infraction.tempban(self, event, member, reason, expires_dt) self.queue_infractions() self.confirm_action( event, maybe_string( reason, u':ok_hand: temp-banned {u} for {t} (`{o}`)', u':ok_hand: temp-banned {u} for {t}', u=member.user, t=humanize.naturaldelta(expires_dt - datetime.utcnow()), )) else: raise CommandFail('invalid user')
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)
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)