Updates to config to enable rule diabling and log-only mod.
This commit is contained in:
@@ -8,3 +8,7 @@
|
||||
1rlvfof
|
||||
1rlpiwm
|
||||
1rlpivb
|
||||
1rpysqt
|
||||
1rpyvk2
|
||||
1rpz5j5
|
||||
1rpzgxq
|
||||
|
||||
+30
-2
@@ -45,16 +45,21 @@ class ModBot:
|
||||
config = yaml.safe_load(wiki_content)
|
||||
self.triggers = []
|
||||
self.comments = []
|
||||
self.statuses = []
|
||||
self.tag_comments = {}
|
||||
self.tag_statuses = {}
|
||||
for entry in config.get('triggers', []):
|
||||
self.triggers.append(entry.get('trigger', '').strip())
|
||||
self.comments.append(entry.get('comment', '').strip())
|
||||
self.statuses.append(entry.get('status', 'enabled').strip().lower())
|
||||
for entry in config.get('post_tags', []):
|
||||
tags_str = entry.get('tag', '').strip()
|
||||
comment = entry.get('comment', '').strip()
|
||||
status = entry.get('status', 'enabled').strip().lower()
|
||||
tags = [t.strip().lower() for t in tags_str.split(',') if t.strip()]
|
||||
for tag in tags:
|
||||
self.tag_comments[tag] = comment
|
||||
self.tag_statuses[tag] = status
|
||||
except Exception as e:
|
||||
print(f"Error fetching YAML config from wiki: {e}")
|
||||
|
||||
@@ -143,11 +148,13 @@ class ModBot:
|
||||
print(f"Tags found in title: {tag_matches}")
|
||||
matched_comment = None
|
||||
matched_tag = None
|
||||
matched_status = None
|
||||
for tag in tag_matches:
|
||||
tag_lower = tag.strip().lower()
|
||||
if tag_lower in self.tag_comments:
|
||||
matched_comment = self.tag_comments[tag_lower]
|
||||
matched_tag = tag_lower
|
||||
matched_status = self.tag_statuses.get(tag_lower, 'enabled')
|
||||
break
|
||||
if matched_comment:
|
||||
if submission.id in self.commented_posts:
|
||||
@@ -156,10 +163,18 @@ class ModBot:
|
||||
try:
|
||||
footer = "^I ^am ^a ^bot ^and ^this ^comment ^was ^made ^automatically. ^Message ^the ^Mod ^team ^if ^I'm ^not ^working ^correctly."
|
||||
comment_text = matched_comment.replace("{{author}}", submission.author.name if submission.author else "unknown") + "\n\n" + footer
|
||||
if matched_status == 'enabled':
|
||||
comment = submission.reply(comment_text)
|
||||
comment.mod.distinguish(sticky=True)
|
||||
print(f"Commented on new post {submission.id} with tag [{matched_tag}] (auto)")
|
||||
self.save_commented_post(submission.id)
|
||||
elif matched_status == 'log-only':
|
||||
print(f"Log-only: Did not comment on post {submission.id} with tag [{matched_tag}] (auto)")
|
||||
self.save_commented_post(submission.id)
|
||||
elif matched_status == 'disabled':
|
||||
print(f"Disabled: Did not comment/log for post {submission.id} with tag [{matched_tag}] (auto)")
|
||||
else:
|
||||
print(f"Unknown status '{matched_status}' for post {submission.id} with tag [{matched_tag}] (auto)")
|
||||
except Exception as e:
|
||||
print(f"Error commenting on new post: {e}")
|
||||
else:
|
||||
@@ -172,6 +187,10 @@ class ModBot:
|
||||
words = [w.strip() for w in comment_body.split()]
|
||||
# Only respond if author is a moderator
|
||||
if expected in words and comment.author and comment.author in self.subreddit.moderator():
|
||||
status = self.statuses[idx] if idx < len(self.statuses) else 'enabled'
|
||||
if status == 'disabled':
|
||||
print(f"Trigger '{trigger}' is disabled. Skipping.")
|
||||
continue
|
||||
try:
|
||||
comment.mod.remove()
|
||||
print(f"Removed triggering comment: {comment.id}")
|
||||
@@ -179,15 +198,24 @@ class ModBot:
|
||||
print(f"Error removing comment: {e}")
|
||||
submission = comment.submission
|
||||
self.fetch_yaml_config()
|
||||
self.approve_and_comment(submission, self.comments[idx])
|
||||
self.approve_and_comment(submission, self.comments[idx], status)
|
||||
break
|
||||
|
||||
def approve_and_comment(self, submission, comment_text):
|
||||
def approve_and_comment(self, submission, comment_text, status='enabled'):
|
||||
try:
|
||||
submission.mod.approve()
|
||||
if status == 'enabled':
|
||||
comment = submission.reply(comment_text)
|
||||
comment.mod.distinguish(sticky=True)
|
||||
print(f"Approved and commented on: {submission.id}")
|
||||
self.save_commented_post(submission.id)
|
||||
elif status == 'log-only':
|
||||
print(f"Log-only: Approved but did not comment on: {submission.id}")
|
||||
self.save_commented_post(submission.id)
|
||||
elif status == 'disabled':
|
||||
print(f"Disabled: Did not approve/comment/log for: {submission.id}")
|
||||
else:
|
||||
print(f"Unknown status '{status}' for submission {submission.id}")
|
||||
except Exception as e:
|
||||
print(f"Error approving/commenting: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user