From 82d9088c18f50aa714ea0f71459cbcdf72e73489 Mon Sep 17 00:00:00 2001 From: Lili Date: Mon, 13 Mar 2023 15:22:40 +0100 Subject: [PATCH] first version of passive mode seems to work fine --- tlapbot/default_config.py | 1 + tlapbot/owncast_redeem_dashboard.py | 1 + tlapbot/owncast_webhooks.py | 45 +++++++-------- tlapbot/templates/dashboard.html | 85 ++++++++++++++++------------- 4 files changed, 72 insertions(+), 60 deletions(-) diff --git a/tlapbot/default_config.py b/tlapbot/default_config.py index ce2526e..150d7d7 100644 --- a/tlapbot/default_config.py +++ b/tlapbot/default_config.py @@ -3,6 +3,7 @@ OWNCAST_ACCESS_TOKEN='' OWNCAST_INSTANCE_URL='http://localhost:8080' POINTS_CYCLE_TIME=600 POINTS_AMOUNT_GIVEN=10 +PASSIVE=False LIST_REDEEMS=False ACTIVE_CATEGORIES=[] GUNICORN=False diff --git a/tlapbot/owncast_redeem_dashboard.py b/tlapbot/owncast_redeem_dashboard.py index 6007787..ce29742 100644 --- a/tlapbot/owncast_redeem_dashboard.py +++ b/tlapbot/owncast_redeem_dashboard.py @@ -21,6 +21,7 @@ def dashboard(): counters=all_counters(db), redeems=current_app.config['REDEEMS'], prefix=current_app.config['PREFIX'], + passive=current_app.config['PASSIVE'], username=username, users=users, utc_timezone=utc_timezone) diff --git a/tlapbot/owncast_webhooks.py b/tlapbot/owncast_webhooks.py index ac0060b..77b22da 100644 --- a/tlapbot/owncast_webhooks.py +++ b/tlapbot/owncast_webhooks.py @@ -30,26 +30,27 @@ def owncast_webhook(): if data["eventData"]["user"]["authenticated"]: remove_duplicate_usernames(db, user_id, new_name) elif data["type"] == "CHAT": - prefix = current_app.config['PREFIX'] - user_id = data["eventData"]["user"]["id"] - display_name = data["eventData"]["user"]["displayName"] - current_app.logger.debug(f'New chat message from {display_name}:') - current_app.logger.debug(f'{data["eventData"]["body"]}') - if data["eventData"]["body"].startswith(f"{prefix}help"): - send_help() - elif data["eventData"]["body"].startswith(f"{prefix}points"): - points = read_users_points(db, user_id) - if points is None: - send_chat("Error reading points.") - else: - send_chat(f"{display_name}'s points: {points}") - elif data["eventData"]["body"].startswith(f"{prefix}name_update"): - # Forces name update in case bot didn't catch the NAME_CHANGE - # event. Also removes saved usernames from users with same name - # if user is authenticated. - change_display_name(db, user_id, display_name) - if data["eventData"]["user"]["authenticated"]: - remove_duplicate_usernames(db, user_id, display_name) - elif data["eventData"]["body"].startswith(prefix): - handle_redeem(data["eventData"]["body"], user_id) + if not current_app.config['PASSIVE']: + prefix = current_app.config['PREFIX'] + user_id = data["eventData"]["user"]["id"] + display_name = data["eventData"]["user"]["displayName"] + current_app.logger.debug(f'New chat message from {display_name}:') + current_app.logger.debug(f'{data["eventData"]["body"]}') + if data["eventData"]["body"].startswith(f"{prefix}help"): + send_help() + elif data["eventData"]["body"].startswith(f"{prefix}points"): + points = read_users_points(db, user_id) + if points is None: + send_chat("Error reading points.") + else: + send_chat(f"{display_name}'s points: {points}") + elif data["eventData"]["body"].startswith(f"{prefix}name_update"): + # Forces name update in case bot didn't catch the NAME_CHANGE + # event. Also removes saved usernames from users with same name + # if user is authenticated. + change_display_name(db, user_id, display_name) + if data["eventData"]["user"]["authenticated"]: + remove_duplicate_usernames(db, user_id, display_name) + elif data["eventData"]["body"].startswith(prefix): + handle_redeem(data["eventData"]["body"], user_id) return data diff --git a/tlapbot/templates/dashboard.html b/tlapbot/templates/dashboard.html index 74d8a35..0c6a874 100644 --- a/tlapbot/templates/dashboard.html +++ b/tlapbot/templates/dashboard.html @@ -10,7 +10,9 @@
+ {% if not passive %} + {% endif %}
@@ -32,46 +34,53 @@ {% endif %} - {% if counters %} - - - - - - - {% for counter in counters %} - - - - - {% endfor %} -
Active counters
{{ counter[0] }} {{ counter[1] }}
+ {% if passive %} +

Tlapbot is currently in passive mode.

+

You can't make any redeems, but you will receive points for watching.

{% endif %} - {% if queue %} - - - - - - - - - - - - - {% for row in queue %} - - - - - {% if row[2] %} - - {% endif %} - - {% endfor %} -
Recent redeems
TimeRedeemRedeemerNote
{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}{{ row[1] }}{{ row[3] }}{{ row[2] }}
+ {% if not passive %} + {% if counters %} + + + + + + + {% for counter in counters %} + + + + + {% endfor %} +
Active counters
{{ counter[0] }} {{ counter[1] }}
+ {% endif %} + + {% if queue %} + + + + + + + + + + + + + {% for row in queue %} + + + + + {% if row[2] %} + + {% endif %} + + {% endfor %} +
Recent redeems
TimeRedeemRedeemerNote
{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}{{ row[1] }}{{ row[3] }}{{ row[2] }}
+ {% endif %} {% endif %}