48 lines
1.8 KiB
Python
48 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 not payload.guild_id:
|
|
return
|
|
|
|
if self.bot.cog_disabled_in_guild(self, payload.guild_id):
|
|
return
|
|
|
|
#if payload.channel_id in await config.guild(payload.guild_id).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(payload.guild_id).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)
|