SeaCogs/logger/logger.py

52 lines
1.8 KiB
Python

import time
import discord
from redbot.core import commands
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import bold
from .config import config, register_config
class Logger(commands.Cog):
def __init__(self, bot: Red) -> None:
self.bot: Red = bot
register_config()
@commands.Cog.listener()
async def on_raw_message_delete(self, payload: discord.RawMessageDeleteEvent) -> None:
if payload.guild_id:
guild = self.bot.get_guild(payload.guild_id)
if guild is None:
return
else:
return
if await self.bot.cog_disabled_in_guild(self, guild):
return
if payload.channel_id in await config.guild(guild).message_ignored_channels():
return
if payload.cached_message:
if payload.cached_message.author.bot:
return
if len(payload.cached_message.content) > 3898:
content = payload.cached_message.content[:3900] + "..."
else:
content = payload.cached_message.content
author = payload.cached_message.author
c = await config.guild(guild).message_delete_channel()
if c:
channel = self.bot.get_channel(c)
if channel:
embed = discord.Embed(color=discord.Color.from_str(value="#ff470f"))
embed.set_author(name=f"{author.display_name} - Deleted Message", icon_url=author.display_avatar.url)
embed.description = bold(text=f"Message sent by {author.mention} deleted in {payload.cached_message.channel.mention}") + content
embed.set_footer(text=f"Author: {author.id} | Message ID: {payload.message_id}")
embed.timestamp = time.time()
await channel.send(embed=embed)