move active category check

from __init__.py to being done runtime in functions
This commit is contained in:
Lili (Tlapka) 2023-03-28 13:02:50 +02:00
parent d372ed6e6b
commit 739438f28b
4 changed files with 20 additions and 7 deletions

View File

@ -24,10 +24,6 @@ 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_CATEGORIES'])
)
# Make logging work for gunicorn-ran instances of tlapbot.
if app.config['GUNICORN']:

View File

@ -176,6 +176,21 @@ def all_active_milestones(db):
all_active_milestones.append((name, progress, goal))
return all_active_milestones
def all_active_redeems(db):
redeems = current_app.config['REDEEMS']
all_active_redeems = {}
for redeem_name, redeem_dict in redeems.items():
if redeem_dict.get('category', None):
for category in redeem_dict['category']:
if category in current_app.config['ACTIVE_CATEGORIES']:
all_active_redeems[redeem_name] = redeem_dict
break
else:
all_active_redeems[redeem_name] = redeem_dict
return all_active_redeems
def pretty_redeem_queue(db):
try:
cursor = db.execute(

View File

@ -2,7 +2,7 @@ from flask import current_app
from tlapbot.db import get_db
from tlapbot.owncast_requests import send_chat
from tlapbot.redeems import (add_to_redeem_queue, add_to_counter, add_to_milestone,
check_apply_milestone_completion, milestone_complete)
check_apply_milestone_completion, milestone_complete, is_redeem_active)
from tlapbot.owncast_helpers import use_points, read_users_points, remove_emoji
@ -17,6 +17,8 @@ def handle_redeem(message, user_id):
if redeem not in current_app.config['REDEEMS']:
send_chat("Can't redeem, redeem not found.")
return
if not is_redeem_active(redeem):
send_chat("Can't redeem, redeem is currently not active.")
db = get_db()
price = current_app.config['REDEEMS'][redeem]["price"]

View File

@ -1,6 +1,6 @@
from flask import render_template, Blueprint, request, current_app
from tlapbot.db import get_db
from tlapbot.redeems import all_active_counters, all_active_milestones, pretty_redeem_queue
from tlapbot.redeems import all_active_counters, all_active_milestones, all_active_redeems, pretty_redeem_queue
from tlapbot.owncast_helpers import read_all_users_with_username
from datetime import datetime, timezone
@ -20,7 +20,7 @@ def dashboard():
queue=pretty_redeem_queue(db),
counters=all_active_counters(db),
milestones=all_active_milestones(db),
redeems=current_app.config['REDEEMS'],
redeems=all_active_redeems(db),
prefix=current_app.config['PREFIX'],
passive=current_app.config['PASSIVE'],
username=username,