From 27812b9480d1e01cd67bfd02b722dfac18a1fdcf Mon Sep 17 00:00:00 2001 From: Lili Date: Thu, 12 Jan 2023 14:23:32 +0100 Subject: [PATCH] add first implementation of redeem categories --- tlapbot/__init__.py | 8 ++++++-- tlapbot/default_config.py | 1 + tlapbot/owncast_helpers.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tlapbot/__init__.py b/tlapbot/__init__.py index fecd9be..e1c619f 100644 --- a/tlapbot/__init__.py +++ b/tlapbot/__init__.py @@ -3,8 +3,8 @@ import logging from flask import Flask from apscheduler.schedulers.background import BackgroundScheduler from tlapbot.db import get_db -from tlapbot.owncast_helpers import is_stream_live, give_points_to_chat - +from tlapbot.owncast_helpers import (is_stream_live, give_points_to_chat, + remove_inactive_redeems) def create_app(test_config=None): app = Flask(__name__, instance_relative_config=True) @@ -24,6 +24,10 @@ def create_app(test_config=None): app.config.from_object('tlapbot.default_redeems') app.config.from_pyfile('config.py', silent=True) app.config.from_pyfile('redeems.py', silent=True) + app.config.from_mapping( + REDEEMS=remove_inactive_redeems(app.config['REDEEMS'], + app.config['ACTIVE_TYPES']) + ) # Make logging work for gunicorn-ran instances of tlapbot. if app.config['GUNICORN']: diff --git a/tlapbot/default_config.py b/tlapbot/default_config.py index 88553f4..42aa861 100644 --- a/tlapbot/default_config.py +++ b/tlapbot/default_config.py @@ -4,5 +4,6 @@ OWNCAST_INSTANCE_URL='http://localhost:8080' POINTS_CYCLE_TIME=600 POINTS_AMOUNT_GIVEN=10 LIST_REDEEMS=False +ACTIVE_TYPES=[] GUNICORN=False PREFIX='!' \ No newline at end of file diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py index d1e6b3c..3430f15 100644 --- a/tlapbot/owncast_helpers.py +++ b/tlapbot/owncast_helpers.py @@ -235,5 +235,11 @@ def remove_emoji(message): ) -def remove_inactive_redeems(redeems): - +def is_redeem_active(redeem, active_categories): + if "category" in redeem[1] and redeem[1]["category"] not in active_categories: + return False + return True + + +def remove_inactive_redeems(redeems, active_categories): + return dict(filter(lambda redeem: is_redeem_active(redeem, active_categories), redeems.items())) \ No newline at end of file