SeaCogs/logger/logger.py

52 lines
1.9 KiB
Python
Raw Normal View History

2024-05-24 03:04:40 -04:00
from datetime import UTC, datetime
2024-05-24 02:55:52 -04:00
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:
2024-05-24 03:03:04 -04:00
if payload.guild_id:
guild = self.bot.get_guild(payload.guild_id)
if guild is None:
return
else:
2024-05-24 02:55:52 -04:00
return
2024-05-24 03:03:04 -04:00
if await self.bot.cog_disabled_in_guild(self, guild):
2024-05-24 02:55:52 -04:00
return
2024-05-24 03:03:04 -04:00
if payload.channel_id in await config.guild(guild).message_ignored_channels():
2024-05-24 03:01:04 -04:00
return
2024-05-24 02:55:52 -04:00
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
2024-05-24 02:55:52 -04:00
author = payload.cached_message.author
2024-05-24 03:03:04 -04:00
c = await config.guild(guild).message_delete_channel()
2024-05-24 02:55:52 -04:00
if c:
channel = self.bot.get_channel(c)
if channel:
2024-05-24 03:04:40 -04:00
embed = discord.Embed(color=discord.Color.from_str(value="#ff470f"), timestamp=datetime.now(tz=UTC))
embed.set_author(name=f"{author.name}", icon_url=author.display_avatar.url)
embed.description = bold(text=f"Message sent by {author.mention} deleted in {payload.cached_message.channel.mention}\n", escape_formatting=False) + content
embed.set_footer(text=f"Author: {author.id} | Message ID: {payload.message_id}", icon_url=guild.icon.url)
2024-05-24 02:55:52 -04:00
await channel.send(embed=embed)