updates
This commit is contained in:
@@ -5,4 +5,5 @@ COPY requirements.txt .
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY bot.py .
|
COPY bot.py .
|
||||||
COPY config.py .
|
COPY config.py .
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
CMD ["python", "bot.py"]
|
CMD ["python", "bot.py"]
|
||||||
|
|||||||
@@ -66,23 +66,59 @@ def chat_message_watcher(reddit, subreddit_name):
|
|||||||
with open(chat_requests_file, 'a', encoding='utf-8') as f:
|
with open(chat_requests_file, 'a', encoding='utf-8') as f:
|
||||||
f.write(message.id + '\n')
|
f.write(message.id + '\n')
|
||||||
|
|
||||||
if hasattr(message, 'body'):
|
# Check if message has body and author
|
||||||
message_body = message.body.lower()
|
if not hasattr(message, 'body'):
|
||||||
# Check if sender is a moderator
|
continue
|
||||||
|
|
||||||
author = getattr(message, 'author', None)
|
author = getattr(message, 'author', None)
|
||||||
if author and author in subreddit.moderator():
|
if not author:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check if sender is a moderator
|
||||||
|
try:
|
||||||
|
is_mod = author in subreddit.moderator()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[CHAT WATCH] Error checking if {author} is mod: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not is_mod:
|
||||||
|
continue
|
||||||
|
|
||||||
|
message_body_lower = message.body.lower()
|
||||||
|
print(f"[CHAT WATCH] Moderator '{author}' sent message: {message.body[:100]}")
|
||||||
|
|
||||||
|
# Handle special 'reload-config' command
|
||||||
|
if 'reload-config' in message_body_lower:
|
||||||
|
print(f"[CHAT WATCH] Reload-config command detected.")
|
||||||
|
result = validate_config_from_wiki(reddit, subreddit_name, WIKI_PAGE)
|
||||||
|
if result:
|
||||||
|
print("[CHAT WATCH] Wiki config validated successfully.")
|
||||||
|
reply_text = "Config validated successfully. Config is valid YAML."
|
||||||
|
else:
|
||||||
|
print("[CHAT WATCH] Wiki config validation failed.")
|
||||||
|
reply_text = "Config validation failed. Check the wiki config YAML formatting."
|
||||||
|
try:
|
||||||
|
message.reply(reply_text)
|
||||||
|
print(f"[CHAT WATCH] Replied to message {message.id}.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[CHAT WATCH] Error replying to message {message.id}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
# Load current config to check for triggers
|
# Load current config to check for triggers
|
||||||
config = fetch_config_from_wiki(reddit, subreddit_name, WIKI_PAGE)
|
config = fetch_config_from_wiki(reddit, subreddit_name, WIKI_PAGE)
|
||||||
posts_config = config.get('posts', [])
|
posts_config = config.get('posts', [])
|
||||||
|
|
||||||
|
trigger_found = False
|
||||||
|
|
||||||
# Check if message contains any trigger
|
# Check if message contains any trigger
|
||||||
for post_config in posts_config:
|
for post_config in posts_config:
|
||||||
if not isinstance(post_config, dict):
|
if not isinstance(post_config, dict):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
trigger = post_config.get('trigger', '').lower()
|
trigger = post_config.get('trigger', '').lower()
|
||||||
if trigger and trigger in message_body:
|
if trigger and trigger in message_body_lower:
|
||||||
print(f"[CHAT WATCH] Moderator '{author}' triggered '{trigger}'.")
|
trigger_found = True
|
||||||
|
print(f"[CHAT WATCH] Matched trigger '{trigger}' in message.")
|
||||||
|
|
||||||
# Get posts for this trigger
|
# Get posts for this trigger
|
||||||
trigger_posts = get_trigger_posts(reddit, subreddit_name, WIKI_PAGE, trigger)
|
trigger_posts = get_trigger_posts(reddit, subreddit_name, WIKI_PAGE, trigger)
|
||||||
@@ -97,14 +133,17 @@ def chat_message_watcher(reddit, subreddit_name):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
message.reply(reply_text)
|
message.reply(reply_text)
|
||||||
print(f"[CHAT WATCH] Replied to chat message {message.id}.")
|
print(f"[CHAT WATCH] Replied to message {message.id}.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[CHAT WATCH] Error replying to chat message {message.id}: {e}")
|
print(f"[CHAT WATCH] Error replying to message {message.id}: {e}")
|
||||||
|
|
||||||
# Only process the first matching trigger per message
|
# Only process the first matching trigger per message
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[CHAT WATCH] Chat message watcher error: {e}")
|
print(f"[CHAT WATCH] Chat message watcher error: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
testpostbot:
|
testpostsbot:
|
||||||
image: slfhstd.uk/slfhstd/testpostbot:latest
|
image: slfhstd.uk/slfhstd/testpostsbot:dev
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user