async def on_raw_message_delete(self, payload): guild = self.bot.get_guild(payload.guild_id or 0) if guild is None: return proxy = self.bot.get_guild_proxy(guild) logging_config = await proxy.config.get('logging') if logging_config is None or not logging_config.log_deleted_messages: return content = 'Message deleted in <#{}>.'.format(payload.channel_id) modlog = await proxy.get_modlog() msg = payload.cached_message embed = embed_utils.message_to_embed(msg or payload.message_id) embed.color = discord.Color.dark_red() if msg is None: await modlog.send(content=content, embed=embed) return elif msg.author.bot: return content = 'Message by {} deleted in {}.'.format( msg.author.mention, msg.channel.mention) if len(msg.attachments) > 0: attachments = (attach.url for attach in msg.attachments) field = format.vertical_list(attachments) embed.add_field(name='Attachments', value=field) await modlog.send(content=content, embed=embed)
async def apply_rule(self, rule, message, reasons): if message.guild is None: return tasks = [] action_taken = "" mention_mod = rule.notify_moderator reasons_block = f"\n```\n{format.vertical_list(reasons)}\n```" guild = message.guild if rule.notify_moderator: action_taken = "Message filter found notable message:" if rule.delete_message: permissions = message.channel.permissions_for(guild.me) if permissions.manage_messages: if rule.notify_moderator: action_taken = "Message filter deleted message:" dm = (f"[{guild.name}] Your message was deleted for " f"the following reasons: {reasons_block}") async def delete(): await message.delete() if not message.author.bot and \ message.author != self.bot.user: await message.author.send(dm) tasks.append(delete()) else: mention_mod = True action_taken = (f"Attempted to delete, but don't have " f"`Manage Messages` in " f"{message.channel.mention}.") if rule.additional_actions: actions = [] for action_template in rule.additional_actions: action = proto.Action() action.CopyFrom(action_template) action.guild_id = guild.id action.user_id = message.author.id if not action.HasField('reason'): action.reason = f"Triggered message filter: '{rule.name}'" actions.append(action) tasks.append(self.bot.action_manager.sequentially_execute(actions)) if mention_mod or action_taken: text = action_taken + reasons_block if mention_mod: _, mention_text = await utils.mention_random_online_mod( self.bot, guild) text = mention_text + " " + text embed = embed_utils.message_to_embed(message) tasks.append(guild.modlog.send(content=text, embed=embed)) try: await asyncio.gather(*tasks) except discord.Forbidden: pass
async def on_message_edit(self, before, after): guild = before.guild if guild is None: return config = guild.config.logging.edited_messages channel = guild.get_channel(config.output_channel_id) if not should_log(before.channel.id, config) or \ channel is None or before.author.bot: return content = (f'Message by {before.author.mention} edited in ' f'{before.channel.mention}.') embed = embed_utils.message_to_embed(before) embed.description = None embed.color = discord.Color.dark_orange() embed.add_field(name="Before", value=before.content) embed.add_field(name="After", value=after.content) await channel.send(content=content, embed=embed)
async def on_raw_message_delete(self, payload): guild = self.bot.get_guild(payload.guild_id or 0) if guild is None: return config = guild.config.logging.deleted_messages channel = guild.get_channel(config.output_channel_id) if not should_log(payload.channel_id, config) or channel is None: return content = f'Message deleted in <#{payload.channel_id}>.' msg = payload.cached_message embed = embed_utils.message_to_embed(msg or payload.message_id) embed.color = discord.Color.dark_red() if msg is not None: if msg.author.bot: return content = (f'Message by {msg.author.mention} deleted in ' f'{msg.channel.mention}.') if len(msg.attachments) > 0: attachments = (attach.url for attach in msg.attachments) field = format.vertical_list(attachments) embed.add_field(name='Attachments', value=field) await channel.send(content=content, embed=embed)