feat: Basic message logger.

This commit is contained in:
2025-08-13 14:39:49 +10:00
parent fcb14b94f6
commit 0f7f0582d3
6 changed files with 672 additions and 0 deletions

28
messagelogger/lib.py Normal file
View File

@@ -0,0 +1,28 @@
import difflib
from io import BytesIO
import discord
def diff_file(before: str, after: str, filename: str = "changes.diff") -> discord.File:
"""
Generates a diff from two strings and returns it as a discord.File.
Args:
before (str): The original string content.
after (str): The modified string content.
filename (str, optional): The name for the output file. Defaults to "changes.diff".
Returns:
discord.File: A file object ready to be sent in a Discord message.
"""
diff_generator = difflib.ndiff(
before.splitlines(),
after.splitlines(),
)
diff_text = "\n".join(diff_generator) or "No changes."
diff_bytes = diff_text.encode('utf-8')
with BytesIO(diff_bytes) as buffer:
buffer.seek(0)
return discord.File(buffer, filename=filename)