diff --git a/tlapbot/__init__.py b/tlapbot/__init__.py
index 47535ba..3823598 100644
--- a/tlapbot/__init__.py
+++ b/tlapbot/__init__.py
@@ -17,7 +17,9 @@ def create_app(test_config=None):
from . import db
from . import owncast_webhooks
+ from . import owncast_redeem_dashboard
app.register_blueprint(owncast_webhooks.bp)
+ app.register_blueprint(owncast_redeem_dashboard.bp)
db.init_app(app)
def proxy_job():
diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py
index b37656c..c4490cc 100644
--- a/tlapbot/owncast_helpers.py
+++ b/tlapbot/owncast_helpers.py
@@ -31,9 +31,11 @@ def use_points(db, user_id, points):
(points, user_id,)
)
db.commit()
+ return True
except Error as e:
print("Error occured using points:", e.args[0])
print("From user:", user_id, " amount of points:", points)
+ return False
def give_points_to_chat(db):
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients'
@@ -89,4 +91,24 @@ def send_chat(message):
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
r = requests.post(url, headers=headers, json={"body": message})
- return r.json()
\ No newline at end of file
+ return r.json()
+
+def add_to_redeem_queue(db, user_id, redeem_name):
+ try:
+ cursor = db.execute(
+ "INSERT INTO redeem_queue(redeem, redeemer_id) VALUES(?, ?)",
+ (redeem_name, user_id)
+ )
+ db.commit()
+ except Error as e:
+ print("Error occured adding to redeem queue:", e.args[0])
+ print("To user:", user_id, " with redeem:", redeem_name)
+
+def whole_redeem_queue(db):
+ try:
+ cursor = db.execute(
+ "SELECT * from redeem_queue"
+ )
+ return cursor.fetchall()
+ except Error as e:
+ print("Error occured printing redeem queue:", e.args[0])
\ No newline at end of file
diff --git a/tlapbot/owncast_redeem_dashboard.py b/tlapbot/owncast_redeem_dashboard.py
new file mode 100644
index 0000000..eead5c2
--- /dev/null
+++ b/tlapbot/owncast_redeem_dashboard.py
@@ -0,0 +1,14 @@
+from flask import render_template, Blueprint
+from tlapbot.db import get_db
+from tlapbot.owncast_helpers import whole_redeem_queue
+
+bp = Blueprint('redeem_dashboard', __name__)
+
+@bp.route('/dashboard',methods=['GET'])
+def dashboard():
+ queue = whole_redeem_queue(get_db())
+ number_of_drinks = 0
+ for row in queue:
+ if row[2] == "drink":
+ number_of_drinks += 1
+ return render_template('dashboard.html', queue=queue, number_of_drinks=number_of_drinks)
\ No newline at end of file
diff --git a/tlapbot/owncast_webhooks.py b/tlapbot/owncast_webhooks.py
index 1570b2d..a9d6a51 100644
--- a/tlapbot/owncast_webhooks.py
+++ b/tlapbot/owncast_webhooks.py
@@ -36,10 +36,14 @@ def owncast_webhook():
send_chat(message)
elif "!drink" in data["eventData"]["body"]:
points = read_users_points(db, user_id)
- if points is not None:
- if points > 60:
- use_points(db, user_id, 60)
- send_chat("Enjoy your DRINK........... sips")
+ if points is not None and points > 60:
+ if use_points(db, user_id, 60):
+ add_to_redeem_queue(db, user_id, "drink")
+ elif "!queue" in data["eventData"]["body"]:
+ queue = whole_redeem_queue(db)
+ print("ID | timestamp | redeem | redeemer_id ")
+ for row in queue:
+ print(row[0], " ", row[1], " ", row[2], " ", row[3])
# else: # DEBUG: give points for message
# give_points_to_chat(db)
return data
\ No newline at end of file
diff --git a/tlapbot/templates/dashboard.html b/tlapbot/templates/dashboard.html
new file mode 100644
index 0000000..1c4c0f1
--- /dev/null
+++ b/tlapbot/templates/dashboard.html
@@ -0,0 +1,31 @@
+
+
+
+ Redeems Dashboard
+
+
+
+
+ Number of drinks: |
+ {{ number_of_drinks }} |
+
+
+
+
+
+
+ time |
+ redeem |
+ redeemer |
+
+
+ {% for row in queue %}
+
+ {{ row[1] }} |
+ {{ row[2] }} |
+ {{ row[3] }} |
+
+ {% endfor %}
+
+
+
\ No newline at end of file