def kick(self, event, user, reason=None): member = event.guild.get_member(user) if member: self.can_act_on(event, member.id) if event.config.notify_action_on and event.config.notify_action_on.kicks: try: event.guild.get_member(user.id).user.open_dm( ).send_message( 'You have been **Kicked** from the guild **{}** for `{}`' .format(event.guild.name, reason or 'no reason')) except: pass else: pass Infraction.kick(self, event, member, reason) self.confirm_action( event, maybe_string( reason, u':ok_hand: kicked {u} (`{o}`)', u':ok_hand: kicked {u}', u=member.user, )) 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.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 mkick(self, event, args): members = [] failed_ids = [] for user_id in args.users: member = event.guild.get_member(user_id) if not member: #TODO: this sucks, batch these # raise CommandFail('failed to kick {}, user not found'.format(user_id)) failed_ids.append(member) continue if not self.can_act_on(event, member, throw=False): # raise CommandFail('failed to kick {}, invalid permissions'.format(user_id)) failed_ids.append(member) continue members.append(member) msg = event.msg.reply('Ok, kick {} users for `{}`?'.format( len(members), args.reason or 'no reason')) msg.chain(False).\ add_reaction(GREEN_TICK_EMOJI).\ add_reaction(RED_TICK_EMOJI) try: mra_event = self.wait_for_event( 'MessageReactionAdd', message_id=msg.id, conditional=lambda e: (e.emoji.id in (GREEN_TICK_EMOJI_ID, RED_TICK_EMOJI_ID) and e. user_id == event.author.id)).get(timeout=10) except gevent.Timeout: return finally: msg.delete() if mra_event.emoji.id != GREEN_TICK_EMOJI_ID: return for member in members: if event.config.notify_action_on: if event.config.notify_action_on.kicks: try: member.user.open_dm().send_message( 'You have been **Kicked** from the guild **{}** for `{}`' .format(event.guild.name, reason or 'no reason')) except: pass else: pass else: pass Infraction.kick(self, event, member, args.reason) raise CommandSuccess( 'kicked {} users. Was unable to remove {} users.'.format( len(members), len(failed_ids)))
def kick(self, event, user, reason=None): member = event.guild.get_member(user) if member: self.can_act_on(event, member.id) Infraction.kick(self, event, member, reason) self.confirm_action(event, maybe_string( reason, u':ok_hand: kicked {u} (`{o}`)', u':ok_hand: kicked {u}', u=member.user, )) else: raise CommandFail('invalid user')
def kick(self, event, user, reason=None): member = event.guild.get_member(user) if member: Infraction.kick(self, event, member, reason) if event.config.confirm_actions: event.msg.reply( maybe_string( reason, u':ok_hand: kicked {u} (`{o}`)', u':ok_hand: kicked {u}', u=member.user, )) else: raise CommandFail('invalid user')
def mkick(self, event, args): members = [] for user_id in args.users: member = event.guild.get_member(user_id) if not member: # TODO: this sucks, batch these raise CommandFail( 'failed to kick {}, user not found'.format(user_id)) if not self.can_act_on(event, member.id, throw=False): raise CommandFail( 'failed to kick {}, invalid permissions'.format(user_id)) members.append(member) msg = event.msg.reply('Ok, kick {} users for `{}`?'.format( len(members), args.reason or 'no reason')) msg.chain(False).\ add_reaction(GREEN_TICK_EMOJI).\ add_reaction(RED_TICK_EMOJI_REACT) try: mra_event = self.wait_for_event( 'MessageReactionAdd', message_id=msg.id, conditional=lambda e: (e.emoji.id in (GREEN_TICK_EMOJI_ID, RED_TICK_EMOJI_ID) and e. user_id == event.author.id)).get( timeout=event.config.confirm_actions_expiry) except gevent.Timeout: return finally: msg.delete() if mra_event.emoji.id != GREEN_TICK_EMOJI_ID: return for member in members: Infraction.kick(self, event, member, args.reason) raise CommandSuccess('kicked {} users'.format(len(members)))
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)