From 062e1c113edc3461f9d08ae93a0f0b28c171ff50 Mon Sep 17 00:00:00 2001 From: Lili Date: Mon, 10 Oct 2022 15:14:57 +0200 Subject: [PATCH] prepare skeletons for configurable redeems move redeem handling code to redeem handler --- setup.py | 2 +- tlapbot/__init__.py | 2 +- tlapbot/owncast_webhooks.py | 21 ++++++++------------- tlapbot/redeems_handler.py | 5 +++++ 4 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 tlapbot/redeems_handler.py diff --git a/setup.py b/setup.py index 9fe8b0c..2c1c63f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages, setup setup( name='tlapbot', - version='0.5.3', + version='0.6.0a1', packages=find_packages(), include_package_data=True, install_requires=[ diff --git a/tlapbot/__init__.py b/tlapbot/__init__.py index bc19be3..f225bdc 100644 --- a/tlapbot/__init__.py +++ b/tlapbot/__init__.py @@ -20,7 +20,7 @@ def create_app(test_config=None): ) app.config.from_object('tlapbot.default_config') app.config.from_pyfile('config.py') - + app.config.from_pyfile('redeems.py') # prepare webhooks and redeem dashboard blueprints from . import owncast_webhooks diff --git a/tlapbot/owncast_webhooks.py b/tlapbot/owncast_webhooks.py index b53ae26..ad3cb87 100644 --- a/tlapbot/owncast_webhooks.py +++ b/tlapbot/owncast_webhooks.py @@ -1,7 +1,9 @@ -from flask import Flask,request,json,Blueprint +from flask import Flask, request, json, Blueprint from sqlite3 import Error from tlapbot.db import get_db -from tlapbot.owncast_helpers import * +from tlapbot.owncast_helpers import (add_user_to_database, change_display_name, + user_exists, send_chat, read_users_points) +from tlapbot.redeems_handler import handle_redeem bp = Blueprint('owncast_webhooks', __name__) @@ -28,25 +30,18 @@ def owncast_webhook(): !points to see your points. !drink to redeem a pitíčko for 60 points. That's it for now.""" + # TODO: also make this customizable 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) + message = f"{display_name}'s points: {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.") - 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 "!" in data["eventData"]["body"]: + handle_redeem(data["eventData"]["body"]) return data \ No newline at end of file diff --git a/tlapbot/redeems_handler.py b/tlapbot/redeems_handler.py new file mode 100644 index 0000000..a950e58 --- /dev/null +++ b/tlapbot/redeems_handler.py @@ -0,0 +1,5 @@ +from tlapbot.db import get_db +from tlapbot.owncast_helpers import use_points, add_to_redeem_queue + +def handle_redeem() + pass \ No newline at end of file