milestone stub + helpers name change
lets hope milestones work
This commit is contained in:
parent
90615ce7c6
commit
07c701de71
|
@ -137,7 +137,7 @@ def change_display_name(db, user_id, new_name):
|
|||
current_app.logger.error(f"To user id: {user_id}, with display name: {new_name}")
|
||||
|
||||
|
||||
def check_counter_exists(db, counter_name):
|
||||
def counter_exists(db, counter_name):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
"SELECT count FROM counters WHERE name = ?",
|
||||
|
@ -156,7 +156,7 @@ def check_counter_exists(db, counter_name):
|
|||
|
||||
|
||||
def add_to_counter(db, counter_name):
|
||||
if check_counter_exists(db, counter_name):
|
||||
if counter_exists(db, counter_name):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
"UPDATE counters SET count = count + 1 WHERE name = ?",
|
||||
|
@ -181,7 +181,31 @@ def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
|||
except Error as e:
|
||||
current_app.logger.error(f"Error occured adding to redeem queue: {e.args[0]}")
|
||||
current_app.logger.error(f"To user: {user_id} with redeem: {redeem_name} with note: {note}")
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def add_to_milestone(db, redeem_name, points):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
"SELECT count, goal FROM milestones WHERE name = ?",
|
||||
(redeem_name,)
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
if row is not None:
|
||||
count = row[0]
|
||||
goal = row[1]
|
||||
result = count + points
|
||||
if result > goal:
|
||||
result = goal
|
||||
cursor = db.execute(
|
||||
"UPDATE milestones SET count = ? WHERE name = ?",
|
||||
(result, redeem_name)
|
||||
)
|
||||
db.commit()
|
||||
return True
|
||||
except (Error, Exception) as e:
|
||||
current_app.logger.error(f"Error occured updating milestone: {e.args[0]}")
|
||||
return False
|
||||
|
||||
|
||||
def all_counters(db):
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from flask import current_app
|
||||
from tlapbot.db import get_db
|
||||
from tlapbot.owncast_helpers import (use_points, add_to_redeem_queue,
|
||||
add_to_counter, read_users_points, send_chat, remove_emoji)
|
||||
add_to_counter, read_users_points, send_chat, remove_emoji,
|
||||
add_to_milestone)
|
||||
|
||||
|
||||
def handle_redeem(message, user_id):
|
||||
|
@ -45,5 +46,14 @@ def handle_redeem(message, user_id):
|
|||
send_chat(f"{redeem} redeemed for {price} points.")
|
||||
else:
|
||||
send_chat(f"Redeeming {redeem} failed.")
|
||||
elif redeem_type == "milestone":
|
||||
if not note:
|
||||
send_chat(f"Cannot redeem {redeem}, no amount of points specified.")
|
||||
elif not note.isdigit():
|
||||
send_chat(f"Cannot redeem {redeem}, amount of points is not an integer.")
|
||||
elif int(note) < points:
|
||||
send_chat(f"Can't redeem {redeem}, you don't have enough points.")
|
||||
else:
|
||||
add_to_milestone(db, redeem, int(note))
|
||||
else:
|
||||
send_chat(f"{redeem} not redeemed, type of redeem not found.")
|
||||
|
|
|
@ -7,6 +7,13 @@ CREATE TABLE IF NOT EXISTS points (
|
|||
points INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE milestones (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
count INTEGER NOT NULL,
|
||||
goal INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE counters (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
|
|
Loading…
Reference in New Issue