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