Exemple #1
0
    async def on_message_delete(self, msg: discord.Message):
        # don't handle message deletion elsewhere
        if not isinstance(msg.channel, discord.TextChannel):
            return

        # do not process bulk message deletes, or message censors (the censor cog does that already)
        # TODO: do this but cleanly, maybe paste website?
        if await self.bulk_deletes.check_batch(
                msg.id) or await self.censored_messages.check(message_id=msg.id
                                                              ):
            return

        # if this channel isn't publicly visible or deletes shouldn't be tracked, bail
        if (not await is_publicly_visible(self.bot, msg.channel) or await
                self.bot.config_is_set(msg.guild, 'modlog_notrack_deletes')):
            return

        # if the author was a bot and we aren't configured to allow bots, return
        if msg.author.bot and not await self.bot.config_is_set(
                msg.guild, 'modlog_filter_allow_bot'):
            return

        # format attachment list
        attachments = 'no attachments' if not msg.attachments else f'{len(msg.attachments)} attachment(s): ' + \
            ', '.join(f'{a.filename}, {filesize(a.size)}' for a in msg.attachments)

        content = utils.prevent_codeblock_breakout(
            utils.truncate(msg.content, 1500))
        fmt = (
            f'\U0001f6ae Message by {describe(msg.author)} deleted in {msg.channel.mention}: ```\n{content}\n``` '
            f'({attachments}, {len(msg.embeds)} embed(s)')
        await self.log(msg.guild, fmt)
Exemple #2
0
    async def on_command_completion(self, ctx: DogbotContext):
        if not ctx.guild:
            return

        cmd = utils.prevent_codeblock_breakout(ctx.message.content)
        await self.log(
            ctx.guild,
            (f'\N{WRENCH} Command invoked by {describe(ctx.author)} in '
             f'{describe(ctx.message.channel, mention=True)}:\n```{cmd}```'))
Exemple #3
0
    async def on_message_edit(self, before: discord.Message,
                              after: discord.Message):
        # if message author was a bot, or the embeds were added by discord, bail
        if before.author.bot or before.content == after.content:
            return

        # if this channel isn't publicly visible or we aren't tracking edits, bail
        if (not await is_publicly_visible(self.bot, before.channel) or await
                self.bot.config_is_set(before.guild, 'modlog_notrack_edits')):
            return

        # truncate :blobsweats:
        m_before = utils.prevent_codeblock_breakout(
            utils.truncate(before.content, 900))
        m_after = utils.prevent_codeblock_breakout(
            utils.truncate(after.content, 900))

        # format
        fmt = (
            f'\N{MEMO} Message by {describe(before.author)} in {describe(before.channel, mention=True)} edited: '
            f'```\n{m_before}\n``` to ```\n{m_after}\n```')
        await self.log(before.guild, fmt)
Exemple #4
0
def postprocess_message_content(content):
    return utils.prevent_codeblock_breakout(content.replace('\x00', ''))