Tlapbot/tlapbot/redeems_handler.py

42 lines
1.7 KiB
Python
Raw Normal View History

from flask import current_app
from tlapbot.db import get_db
2022-10-12 15:35:36 +02:00
from tlapbot.owncast_helpers import (use_points, add_to_redeem_queue,
2022-10-17 18:37:49 +02:00
add_to_counter, read_users_points, send_chat)
2022-10-13 13:29:38 +02:00
def handle_redeem(message, user_id):
split_message = message[1:].split(maxsplit=1)
redeem = split_message[0]
if len(split_message) == 1:
note = None
else:
note = split_message[1]
if redeem in current_app.config['REDEEMS']:
2022-10-12 15:35:36 +02:00
db = get_db()
price = current_app.config['REDEEMS'][redeem]["price"]
redeem_type = current_app.config['REDEEMS'][redeem]["type"]
points = read_users_points(db, user_id)
if points is not None and points >= price:
if redeem_type == "counter":
add_to_counter(db, redeem)
use_points(db, user_id, price)
send_chat(f"{redeem} redeemed for {price} points.")
elif redeem_type == "list":
add_to_redeem_queue(db, user_id, redeem)
use_points(db, user_id, price)
send_chat(f"{redeem} redeemed for {price} points.")
elif redeem_type == "note":
if note is not None:
add_to_redeem_queue(db, user_id, redeem, note)
use_points(db, user_id, price)
2022-10-13 14:09:12 +02:00
send_chat(f"{redeem} redeemed for {price} points.")
else:
send_chat(f"Cannot redeem {redeem}, no note included.")
else:
send_chat(f"{redeem} not redeemed because of an error.")
else:
send_chat(f"Can't redeem {redeem}, you don't have enough points.")
else:
2022-10-17 18:37:49 +02:00
send_chat("Can't redeem, redeem not found.")