Update .gitignore to exclude .DS_Store; refactor logging for unauthorized reset attempts and message formatting

This commit is contained in:
pacnpal
2025-02-25 20:17:40 -05:00
parent 937bc18ca7
commit e8f57b976a
2 changed files with 10 additions and 6 deletions

1
.gitignore vendored
View File

@@ -63,3 +63,4 @@ discord_glhf/handlers/event_handler.py
discord_glhf/handlers/__pycache__/__init__.cpython-313.pyc
discord_glhf/handlers/__pycache__/image_handler.cpython-313.pyc
discord_glhf/web/__pycache__/__init__.cpython-313.pyc
.DS_Store

View File

@@ -230,11 +230,13 @@ class EventHandler:
is_allowed = (
message.author.id in RESET_ALLOWED_USERS or
message.author.id == BOT_OWNER_ID or
(hasattr(message.author, 'guild_permissions') and message.author.guild_permissions.administrator)
(hasattr(message.author, 'guild_permissions')
and message.author.guild_permissions.administrator)
)
if not is_allowed:
logger.warning(f"Unauthorized reset attempt by {message.author.name} ({message.author.id})")
logger.warning(
f"Unauthorized reset attempt by {message.author.name} ({message.author.id})")
return
try:
@@ -242,7 +244,8 @@ class EventHandler:
await message.add_reaction("")
# Clear all messages
await self.db_manager.clear_all_messages()
logger.info(f"Personality reset by {message.author.name} ({message.author.id})")
logger.info(
f"Personality reset by {message.author.name} ({message.author.id})")
return
except Exception as e:
logger.error(f"Failed to reset personality: {e}")
@@ -280,7 +283,7 @@ class EventHandler:
user_id=0,
channel_id=message.channel.id
)
current_content = f"{message.author.display_name} ({message.author.name}) (<@{message.author.id}>): {message.content}"
current_content = f"({message.author.name}): {message.content}"
for hist_msg in recent_history:
hist_content = hist_msg.get("content", {}).get("content", "") if isinstance(
hist_msg.get("content"), dict) else hist_msg.get("content", "")
@@ -368,7 +371,7 @@ class EventHandler:
message_uuid = str(uuid.uuid4())
# Format the message with user info
formatted_content = f"{item.message.author.display_name} ({item.message.author.name}) (<@{item.message.author.id}>): {item.prompt}"
formatted_content = f"({item.message.author.name}): {item.prompt}"
# Check if this message is already in history
message_in_history = False