From 56e800fd9d53160aff9e7b466f6adc76b55967a1 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Sun, 9 Oct 2022 06:49:08 -0700 Subject: [PATCH] move basedbot to actions as well --- files/helpers/actions.py | 31 +++++++++++++++++++++++++++++++ files/routes/comments.py | 32 +------------------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 43979b966..6eb4313c3 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -278,4 +278,35 @@ def execute_longpostbot(c, level, body, body_html, parent_submission, v): g.db.add(longpostbot) g.db.flush() n = Notification(comment_id=c2.id, user_id=v.id) + g.db.add(n) + +def execute_basedbot(c, level, body, parent_submission, parent_post, v): + pill = based_regex.match(body) + if level == 1: basedguy = get_account(parent_post.author_id) + else: basedguy = get_account(c.parent_comment.author_id) + basedguy.basedcount += 1 + if pill: + if basedguy.pills: basedguy.pills += f", {pill.group(1)}" + else: basedguy.pills += f"{pill.group(1)}" + g.db.add(basedguy) + + body2 = f"@{basedguy.username}'s Based Count has increased by 1. Their Based Count is now {basedguy.basedcount}." + if basedguy.pills: body2 += f"\n\nPills: {basedguy.pills}" + + body_based_html = sanitize(body2) + c_based = Comment(author_id=BASEDBOT_ID, + parent_submission=parent_submission, + distinguish_level=6, + parent_comment_id=c.id, + level=level+1, + is_bot=True, + body_html=body_based_html, + top_comment_id=c.top_comment_id, + ghost=c.ghost + ) + + g.db.add(c_based) + g.db.flush() + + n = Notification(comment_id=c_based.id, user_id=v.id) g.db.add(n) \ No newline at end of file diff --git a/files/routes/comments.py b/files/routes/comments.py index e6729e03c..3bb7bdf91 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -345,37 +345,7 @@ def comment(v): g.db.add(choice) if SITE == 'pcmemes.net' and c.body.lower().startswith("based"): - pill = based_regex.match(body) - - if level == 1: basedguy = get_account(parent_post.author_id) - else: basedguy = get_account(c.parent_comment.author_id) - basedguy.basedcount += 1 - if pill: - if basedguy.pills: basedguy.pills += f", {pill.group(1)}" - else: basedguy.pills += f"{pill.group(1)}" - g.db.add(basedguy) - - body2 = f"@{basedguy.username}'s Based Count has increased by 1. Their Based Count is now {basedguy.basedcount}." - if basedguy.pills: body2 += f"\n\nPills: {basedguy.pills}" - - body_based_html = sanitize(body2) - - c_based = Comment(author_id=BASEDBOT_ID, - parent_submission=parent_submission, - distinguish_level=6, - parent_comment_id=c.id, - level=level+1, - is_bot=True, - body_html=body_based_html, - top_comment_id=c.top_comment_id, - ghost=c.ghost - ) - - g.db.add(c_based) - g.db.flush() - - n = Notification(comment_id=c_based.id, user_id=v.id) - g.db.add(n) + execute_basedbot(c, level, body, parent_submission, parent_post, v) if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in c.body.lower() and parent_post.sub != 'chudrama':