1 Commits

Author SHA1 Message Date
slfhstd 868d2dfc18 2026-03-16 20:09:10 +00:00
+24 -12
View File
@@ -209,9 +209,9 @@ def chat_message_watcher(reddit):
chat_requests_file = os.path.join(DB_DIR, 'chat_wiki_requests.txt') chat_requests_file = os.path.join(DB_DIR, 'chat_wiki_requests.txt')
processed_message_ids = set() processed_message_ids = set()
subreddit = reddit.subreddit(config.SUBREDDIT) subreddit = reddit.subreddit(config.SUBREDDIT)
print("[CHAT] Chat message watcher started") print("[CHAT] Chat message watcher started")
# Load previously processed message IDs # Load previously processed message IDs
if os.path.exists(chat_requests_file): if os.path.exists(chat_requests_file):
try: try:
@@ -220,14 +220,26 @@ def chat_message_watcher(reddit):
processed_message_ids.add(line.strip()) processed_message_ids.add(line.strip())
except Exception as e: except Exception as e:
print(f"[CHAT] Error loading processed message IDs: {e}") print(f"[CHAT] Error loading processed message IDs: {e}")
# Get the latest message timestamp at startup
last_seen_timestamp = None
try:
# Fetch the most recent message (limit=1)
latest = list(reddit.inbox.all(limit=1))
if latest and hasattr(latest[0], 'created_utc'):
last_seen_timestamp = latest[0].created_utc
print(f"[CHAT] Last seen message timestamp at startup: {last_seen_timestamp}")
except Exception as e:
print(f"[CHAT] Error fetching latest message timestamp: {e}")
while True: while True:
try: try:
for message in reddit.inbox.stream(): for message in reddit.inbox.stream():
# Skip if no ID or already processed # Skip if no ID, already processed, or message is older than startup
if not hasattr(message, 'id') or message.id in processed_message_ids: if (not hasattr(message, 'id') or message.id in processed_message_ids or
(last_seen_timestamp is not None and hasattr(message, 'created_utc') and message.created_utc <= last_seen_timestamp)):
continue continue
# Mark as processed # Mark as processed
processed_message_ids.add(message.id) processed_message_ids.add(message.id)
try: try:
@@ -235,16 +247,16 @@ def chat_message_watcher(reddit):
f.write(message.id + '\n') f.write(message.id + '\n')
except Exception as e: except Exception as e:
print(f"[CHAT] Error saving message ID: {e}") print(f"[CHAT] Error saving message ID: {e}")
# Check for reload-config command # Check for reload-config command
if hasattr(message, 'body') and 'reload-config' in message.body.lower(): if hasattr(message, 'body') and 'reload-config' in message.body.lower():
author = getattr(message, 'author', None) author = getattr(message, 'author', None)
# Verify sender is a moderator # Verify sender is a moderator
try: try:
if author and author in subreddit.moderator(): if author and author in subreddit.moderator():
print(f"[CHAT] Moderator '{author}' requested config reload") print(f"[CHAT] Moderator '{author}' requested config reload")
# Reload wiki configuration # Reload wiki configuration
try: try:
wiki_config.fetch_from_wiki() wiki_config.fetch_from_wiki()
@@ -253,18 +265,18 @@ def chat_message_watcher(reddit):
except Exception as e: except Exception as e:
print(f"[CHAT] Failed to reload wiki config: {e}") print(f"[CHAT] Failed to reload wiki config: {e}")
reply_text = f"✗ Failed to reload wiki config: {e}" reply_text = f"✗ Failed to reload wiki config: {e}"
# Reply to the message # Reply to the message
try: try:
message.reply(reply_text) message.reply(reply_text)
print(f"[CHAT] Replied to message {message.id}") print(f"[CHAT] Replied to message {message.id}")
except Exception as e: except Exception as e:
print(f"[CHAT] Error replying to message {message.id}: {e}") print(f"[CHAT] Error replying to message {message.id}: {message.id}: {e}")
else: else:
print(f"[CHAT] Non-moderator '{author}' attempted reload-config (ignored)") print(f"[CHAT] Non-moderator '{author}' attempted reload-config (ignored)")
except Exception as e: except Exception as e:
print(f"[CHAT] Error checking moderator status: {e}") print(f"[CHAT] Error checking moderator status: {e}")
# Check for repost-latest command # Check for repost-latest command
elif hasattr(message, 'body') and 'repost-latest' in message.body.lower(): elif hasattr(message, 'body') and 'repost-latest' in message.body.lower():
author = getattr(message, 'author', None) author = getattr(message, 'author', None)