From ed794045309cd61679bb9f1d038ec6f15a8a5b2e Mon Sep 17 00:00:00 2001 From: Lili Date: Mon, 26 Sep 2022 10:50:37 +0200 Subject: [PATCH] remove old/unnecessary checks --- tlapbot/owncast_webhooks.py | 71 ++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/tlapbot/owncast_webhooks.py b/tlapbot/owncast_webhooks.py index 2aa0e9b..28da72d 100644 --- a/tlapbot/owncast_webhooks.py +++ b/tlapbot/owncast_webhooks.py @@ -20,45 +20,36 @@ def owncast_webhook(): old_names = data["eventData"]["user"]["previousNames"] change_display_name(db, user_id, new_name) elif data["type"] == "CHAT": - if data["eventData"]["visible"]: - user_id = data["eventData"]["user"]["id"] - display_name = data["eventData"]["user"]["displayName"] - print("New chat message:") - print(f'from {display_name}:') - print(f'{data["eventData"]["body"]}') - if "!help" in data["eventData"]["body"]: - message = """Tlapbot commands: - !points to see your points. - !drink to redeem a pitíčko for 60 points. - That's it for now.""" - send_chat(message) - elif "!points" in data["eventData"]["body"]: - if not user_exists(db, user_id): - add_user_to_database(db, user_id, display_name) - points = read_users_points(db, user_id) - message = "{}'s points: {}".format(display_name, points) - send_chat(message) - elif "!drink" in data["eventData"]["body"]: - points = read_users_points(db, user_id) - if points is not None and points >= 60: - if use_points(db, user_id, 60): - add_to_redeem_queue(db, user_id, "drink") - send_chat("Pitíčko redeemed for 60 points.") - else: - send_chat("Pitíčko not redeemed because of an error.") + user_id = data["eventData"]["user"]["id"] + display_name = data["eventData"]["user"]["displayName"] + print(f'New chat message from {display_name}:') + print(f'{data["eventData"]["body"]}') + if "!help" in data["eventData"]["body"]: + message = """Tlapbot commands: + !points to see your points. + !drink to redeem a pitíčko for 60 points. + That's it for now.""" + send_chat(message) + elif "!points" in data["eventData"]["body"]: + if not user_exists(db, user_id): + add_user_to_database(db, user_id, display_name) + points = read_users_points(db, user_id) + message = "{}'s points: {}".format(display_name, points) + send_chat(message) + elif "!drink" in data["eventData"]["body"]: + points = read_users_points(db, user_id) + if points is not None and points >= 60: + if use_points(db, user_id, 60): + add_to_redeem_queue(db, user_id, "drink") + send_chat("Pitíčko redeemed for 60 points.") else: - send_chat("Can't redeem pitíčko, you don't have enough points.") - elif "!name_update" in data["eventData"]["body"]: - # Forces name update in case bot didn't catch the NAME_CHANGE - # event. Theoretically only needed when bot was off. - change_display_name(db, user_id, display_name) - elif "!clear" in data["eventData"]["body"]: - clear_redeem_queue(db) - elif "!queue" in data["eventData"]["body"]: - queue = pretty_redeem_queue(db) - print("timestamp | redeem | redeemer") - for row in queue: - print(row[0], " ", row[1], " ", row[2]) - # else: # DEBUG: give points for message - # give_points_to_chat(db) + send_chat("Pitíčko not redeemed because of an error.") + else: + send_chat("Can't redeem pitíčko, you don't have enough points.") + elif "!name_update" in data["eventData"]["body"]: + # Forces name update in case bot didn't catch the NAME_CHANGE + # event. Theoretically only needed when bot was off. + change_display_name(db, user_id, display_name) + elif "!clear" in data["eventData"]["body"]: + clear_redeem_queue(db) return data \ No newline at end of file