worky
This commit is contained in:
71
cogs/logger.py
Normal file
71
cogs/logger.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from config import Config
|
||||
import utils
|
||||
|
||||
class ChatLogger(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_delete(self, message: discord.Message):
|
||||
# 1. Validation
|
||||
if message.author.bot: return
|
||||
|
||||
# 2. Build Embed
|
||||
embed = discord.Embed(
|
||||
description=f"**Message sent by {message.author.mention} was deleted**",
|
||||
color=Config.COLOR_DELETE,
|
||||
timestamp=utils.get_timestamp()
|
||||
)
|
||||
|
||||
embed.set_author(
|
||||
name=f"{message.author}",
|
||||
icon_url=message.author.avatar.url if message.author.avatar else None
|
||||
)
|
||||
|
||||
content = message.content if message.content else "[No Text Content]"
|
||||
embed.add_field(name="Deleted Text:", value=utils.truncate(content), inline=False)
|
||||
|
||||
# 3. Secure Image Handling
|
||||
if message.attachments:
|
||||
links = [f"[{att.filename}]({att.proxy_url})" for att in message.attachments]
|
||||
embed.add_field(name="Evidence:", value="\n".join(links), inline=False)
|
||||
embed.set_image(url=message.attachments[0].proxy_url)
|
||||
|
||||
embed.set_footer(text="Caught in 4K") # Optional flavor text
|
||||
|
||||
# 4. Send to the SAME channel
|
||||
await message.channel.send(embed=embed)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_edit(self, before: discord.Message, after: discord.Message):
|
||||
# 1. Validation
|
||||
if before.author.bot: return
|
||||
if before.content == after.content: return
|
||||
|
||||
# 2. Build Embed
|
||||
embed = discord.Embed(
|
||||
description=f"**Message edited by {before.author.mention}** [Jump to Message]({after.jump_url})",
|
||||
color=Config.COLOR_EDIT,
|
||||
timestamp=utils.get_timestamp()
|
||||
)
|
||||
|
||||
embed.set_author(
|
||||
name=f"{before.author}",
|
||||
icon_url=before.author.avatar.url if before.author.avatar else None
|
||||
)
|
||||
|
||||
original = before.content if before.content else "[No Text Content]"
|
||||
# We don't necessarily need the "Edited to" field here since the
|
||||
# actual edited message is visible right above this log, but it's good for history.
|
||||
|
||||
embed.add_field(name="Original:", value=utils.truncate(original), inline=False)
|
||||
|
||||
embed.set_footer(text="Edit History")
|
||||
|
||||
# 3. Send to the SAME channel
|
||||
await before.channel.send(embed=embed)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(ChatLogger(bot))
|
||||
Reference in New Issue
Block a user