V2.1.0
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
.env
|
.env
|
||||||
config/*
|
config/*
|
||||||
|
tests.py
|
||||||
|
|||||||
@@ -35,3 +35,4 @@ o846f5z
|
|||||||
5jubgcs
|
5jubgcs
|
||||||
5judtbe
|
5judtbe
|
||||||
5jugfpj
|
5jugfpj
|
||||||
|
5jv66nh
|
||||||
|
|||||||
@@ -49,3 +49,22 @@
|
|||||||
1rqbf4n
|
1rqbf4n
|
||||||
1rqbf4n
|
1rqbf4n
|
||||||
1rqbf4n
|
1rqbf4n
|
||||||
|
1rqcduj
|
||||||
|
1rqcma5
|
||||||
|
1rqcm8p
|
||||||
|
1rqcr1v
|
||||||
|
1rqct6y
|
||||||
|
1rqcr0o
|
||||||
|
1rqct5q
|
||||||
|
1rqcvk4
|
||||||
|
1rqcvit
|
||||||
|
1rqd94l
|
||||||
|
1rqd966
|
||||||
|
1rqd97c
|
||||||
|
1rqd98i
|
||||||
|
1rqd99u
|
||||||
|
1rqd9aw
|
||||||
|
1rqd9cc
|
||||||
|
1rqd9ds
|
||||||
|
1rqd966
|
||||||
|
1rqd9aw
|
||||||
|
|||||||
+69
-17
@@ -247,44 +247,96 @@ class ModReplyBot:
|
|||||||
def tag_post_watcher():
|
def tag_post_watcher():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
# Check new submissions
|
||||||
for submission in self.subreddit.stream.submissions(skip_existing=True):
|
for submission in self.subreddit.stream.submissions(skip_existing=True):
|
||||||
flair = (submission.link_flair_text or '').strip().lower()
|
flair = (submission.link_flair_text or '').strip().lower()
|
||||||
title = submission.title.strip()
|
title = submission.title.strip()
|
||||||
# Extract tags from title in square brackets
|
|
||||||
import re
|
import re
|
||||||
title_tags = re.findall(r'\[(.*?)\]', title)
|
title_tags = re.findall(r'\[(.*?)\]', title)
|
||||||
title_tags_lower = [t.strip().lower() for t in title_tags]
|
title_tags_lower = [t.strip().lower() for t in title_tags]
|
||||||
print(f"[TAG WATCH] Post {submission.id}: title='{title}', flair='{flair}', title_tags={title_tags_lower}")
|
print(f"[TAG WATCH] Post {submission.id}: title='{title}', flair='{flair}', title_tags={title_tags_lower}")
|
||||||
matched_tag = None
|
matched_tag = None
|
||||||
# Check flair first
|
|
||||||
if flair in self.tag_comments:
|
if flair in self.tag_comments:
|
||||||
matched_tag = flair
|
matched_tag = flair
|
||||||
else:
|
else:
|
||||||
# Check each tag in title
|
|
||||||
for tag in title_tags_lower:
|
for tag in title_tags_lower:
|
||||||
if tag in self.tag_comments:
|
if tag in self.tag_comments:
|
||||||
matched_tag = tag
|
matched_tag = tag
|
||||||
break
|
break
|
||||||
if matched_tag:
|
# Comment on all posts with matching tags
|
||||||
# Only comment if not already actioned
|
if matched_tag and (submission.id not in self.commented_posts):
|
||||||
if submission.id not in self.commented_posts:
|
status = self.tag_statuses.get(matched_tag, 'enabled')
|
||||||
status = self.tag_statuses.get(matched_tag, 'enabled')
|
comment_text = self.tag_comments[matched_tag]
|
||||||
comment_text = self.tag_comments[matched_tag]
|
flair_id = self.tag_flair_ids.get(matched_tag, '')
|
||||||
flair_id = self.tag_flair_ids.get(matched_tag, '')
|
if flair_id:
|
||||||
if flair_id:
|
try:
|
||||||
try:
|
submission.flair.select(flair_id)
|
||||||
submission.flair.select(flair_id)
|
print(f"[TAG WATCH] Set flair '{flair_id}' for post {submission.id}")
|
||||||
print(f"[TAG WATCH] Set flair '{flair_id}' for post {submission.id}")
|
except Exception as e:
|
||||||
except Exception as e:
|
print(f"[TAG WATCH] Error setting flair '{flair_id}' for post {submission.id}: {e}")
|
||||||
print(f"[TAG WATCH] Error setting flair '{flair_id}' for post {submission.id}: {e}")
|
print(f"Auto-commenting on post {submission.id} with tag '{matched_tag}'")
|
||||||
print(f"Auto-commenting on post {submission.id} with tag '{matched_tag}'")
|
self.comment_only(submission, comment_text)
|
||||||
self.comment_only(submission, comment_text)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Tag post watcher error: {e}")
|
print(f"Tag post watcher error: {e}")
|
||||||
import time
|
import time
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
|
||||||
|
def modqueue_watcher():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("[MODQUEUE DEBUG] Entering modqueue loop...")
|
||||||
|
modqueue_posts = list(self.subreddit.mod.modqueue(limit=100))
|
||||||
|
print(f"[MODQUEUE DEBUG] Fetched {len(modqueue_posts)} posts from modqueue.")
|
||||||
|
for submission in modqueue_posts:
|
||||||
|
flair = (submission.link_flair_text or '').strip().lower()
|
||||||
|
title = submission.title.strip()
|
||||||
|
import re
|
||||||
|
title_tags = re.findall(r'\[(.*?)\]', title)
|
||||||
|
title_tags_lower = [t.strip().lower() for t in title_tags]
|
||||||
|
# Debug print all relevant attributes
|
||||||
|
print(f"[MODQUEUE DEBUG] Post {submission.id}: title='{title}', flair='{flair}', title_tags={title_tags_lower}, author={submission.author}, removed_by_category={getattr(submission, 'removed_by_category', None)}, banned_by={getattr(submission, 'banned_by', None)}, mod_reason_title={getattr(submission, 'mod_reason_title', None)}, spam={getattr(submission, 'spam', None)}, removed={getattr(submission, 'removed', None)}")
|
||||||
|
matched_tag = None
|
||||||
|
if flair in self.tag_comments:
|
||||||
|
matched_tag = flair
|
||||||
|
else:
|
||||||
|
for tag in title_tags_lower:
|
||||||
|
if tag in self.tag_comments:
|
||||||
|
matched_tag = tag
|
||||||
|
break
|
||||||
|
# Detect filtered/removed posts
|
||||||
|
is_filtered = False
|
||||||
|
if getattr(submission, 'removed_by_category', None):
|
||||||
|
is_filtered = True
|
||||||
|
if getattr(submission, 'banned_by', None):
|
||||||
|
is_filtered = True
|
||||||
|
if getattr(submission, 'mod_reason_title', None):
|
||||||
|
is_filtered = True
|
||||||
|
if getattr(submission, 'spam', None):
|
||||||
|
is_filtered = True
|
||||||
|
if getattr(submission, 'removed', None):
|
||||||
|
is_filtered = True
|
||||||
|
if is_filtered:
|
||||||
|
print(f"[MODQUEUE WATCH] Post {submission.id} is filtered/removed.")
|
||||||
|
# Comment only on filtered/removed posts with matching tags
|
||||||
|
if matched_tag and is_filtered and (submission.id not in self.commented_posts):
|
||||||
|
status = self.tag_statuses.get(matched_tag, 'enabled')
|
||||||
|
comment_text = self.tag_comments[matched_tag]
|
||||||
|
flair_id = self.tag_flair_ids.get(matched_tag, '')
|
||||||
|
if flair_id:
|
||||||
|
try:
|
||||||
|
submission.flair.select(flair_id)
|
||||||
|
print(f"[MODQUEUE WATCH] Set flair '{flair_id}' for post {submission.id}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[MODQUEUE WATCH] Error setting flair '{flair_id}' for post {submission.id}: {e}")
|
||||||
|
print(f"Auto-commenting on filtered/removed post {submission.id} with tag '{matched_tag}' from modqueue")
|
||||||
|
self.comment_only(submission, comment_text)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Modqueue watcher error: {e}")
|
||||||
|
import time
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
threading.Thread(target=tag_post_watcher, daemon=True).start()
|
threading.Thread(target=tag_post_watcher, daemon=True).start()
|
||||||
|
threading.Thread(target=modqueue_watcher, daemon=True).start()
|
||||||
|
|
||||||
# Keep main thread alive
|
# Keep main thread alive
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user