From f2c59eb89e286902f652a070254a2a6a1b443192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20D=C3=B6rflinger?= Date: Tue, 16 Dec 2025 11:35:24 +0100 Subject: [PATCH] Fixed wrong counting, added comment functionality --- ChristmasEvent.py | 42 ++++++++++++++++++++++++++++++++++++++---- christmas_event.db | Bin 49152 -> 57344 bytes config.py | 2 ++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ChristmasEvent.py b/ChristmasEvent.py index b7fcd01..f487d46 100755 --- a/ChristmasEvent.py +++ b/ChristmasEvent.py @@ -29,6 +29,12 @@ class DatabaseManager: ) ''') + self.cursor.execute(''' + CREATE TABLE IF NOT EXISTS commented_users ( + username TEXT PRIMARY KEY + ) + ''') + # Wishes table self.cursor.execute(''' CREATE TABLE IF NOT EXISTS wishes ( @@ -71,6 +77,22 @@ class DatabaseManager: except sqlite3.IntegrityError: return False + def add_commented_user(self, username): + try: + self.cursor.execute("INSERT INTO commented_users VALUES (?)", + (username, )) + self.conn.commit() + return True + except sqlite3.IntegrityError: + return False + + def get_commented_users(self, username): + try: + self.cursor.execute("SELECT * FROM commented_users WHERE username=?", (username,)) + return self.cursor.fetchone() + except sqlite3.IntegrityError: + return None + def save_wish(self, sender, recipient, message): """Inserts or Replaces a wish""" self.cursor.execute("SELECT username FROM participants WHERE username = ?", (recipient,)) @@ -166,8 +188,8 @@ class SafetyFilter: class ChristmasBot: - # Store the last updated data to prevent unneeded updates. - last_updated_data = [] + # Store the last updated overall count of wishes. + last_updated_count = 0 def __init__(self): print("🎄 Initializing Christmas Helper...") @@ -214,14 +236,18 @@ class ChristmasBot: if now - self.last_dashboard_update < config.update_post_interval: return data = self.db.get_forest_data() + overall_count = 0 + if data: + for username, count in data: + overall_count += count - if len(self.last_updated_data) == len(data) or len(data) == 0: + if overall_count == self.last_updated_count: # Nothing changed. print(f"No change in dashboard, last checked {datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')}...", end="\r") return print("📝 Updating Forest Dashboard...") - self.last_updated_data = data + self.last_updated_count = overall_count body = "# 🎄 The Christmas Forest 🎄\n\n" body += "### How to Participate:\n" body += "1. Send a DM to u/{}\n".format(config.username) @@ -354,6 +380,14 @@ class ChristmasBot: self.db.clear_conversation(sender) print(f"💾 Wish saved for {target.lower()}") + if self.db.get_commented_users(target.lower()): + print("User already existed before, no need to update") + else: + print("New user, add comment") + self.db.add_commented_user(target.lower()) + submission = self.reddit.submission(id=config.master_post_id) + submission.add_comment(config.comment_base_text.format(username=target.lower())) + if state == "CONFIRM_REPLACE": message.reply(f"✅ Your wish for u/{target.lower()} has been **updated**! 🎄") print(f"{sender} has updated their wish for u/{target.lower()} to **{content}**.") diff --git a/christmas_event.db b/christmas_event.db index f10c22e494e559cbe23c090750532a836e0c6b01..38712ba0b0e6a89a80827b924bd25bc05b939fbd 100644 GIT binary patch delta 574 zcmZo@U~V|TJV9D8n1O+T4~SuaeWH%BaxjBlxEC+~4+d_o`waY6{QG%N@bmJP@g(tD zb1&l2<+{(Eyso3YWdBrz!`H90>wH#M&$H6^~ZIJKx4jmzsCOXBlV%j1hnO4HJK*q9WHGZIsbz=S9ZlW}TANornkW`3S-QDSDEu92~!i6}FZ z@nl6m;RHS=Ce_5u_~eYllK7O;lvH5&vG8#+sg@_^-!Q;PC4Q{qcflS{bx4*^~8!N9+feZ!U9ZP4 zD8Q`Bh-@O~Qw8s$RFnvAF+ T#39J6&WPe_R$gXBPK2`oZu_N@ delta 71 zcmZoTz}(QlJV9D8h=GBD2Z&*SZK95`d=P_P)&*Yv9}Jw_ix~K=`1kXk;OFHn<4NMR T=3d03yID~{g?sZN?zk-g^Cu6c diff --git a/config.py b/config.py index 1b9a195..3e179e4 100644 --- a/config.py +++ b/config.py @@ -20,6 +20,8 @@ check_interval=60 #Interval in seconds to update the dashboard if something changed update_post_interval=300 +comment_base_text="(Pinging in comment, as no more than 3 pings per post)\n\nYou got messages: u/{username}" + megathread_username="droid_tect" megathread_password="lwwh1b-9gK-Ds_o"