Compare commits
No commits in common. "f1a57c16e4357b3f883bd1fc01ba28124d979db3" and "5e7810eb9f95cdee77ed571b37af5d69d28ffa0b" have entirely different histories.
f1a57c16e4
...
5e7810eb9f
|
@ -4,11 +4,11 @@ from flask import Flask
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from tlapbot.db import get_db
|
from tlapbot.db import get_db
|
||||||
from tlapbot.owncast_requests import is_stream_live, give_points_to_chat
|
from tlapbot.owncast_requests import is_stream_live, give_points_to_chat
|
||||||
|
from tlapbot.redeems import remove_inactive_redeems
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
app = Flask(__name__, instance_relative_config=True)
|
app = Flask(__name__, instance_relative_config=True)
|
||||||
|
|
||||||
# ensure the instance folder exists
|
# ensure the instance folder exists
|
||||||
try:
|
try:
|
||||||
os.makedirs(app.instance_path)
|
os.makedirs(app.instance_path)
|
||||||
|
@ -30,18 +30,19 @@ def create_app(test_config=None):
|
||||||
gunicorn_logger = logging.getLogger('gunicorn.error')
|
gunicorn_logger = logging.getLogger('gunicorn.error')
|
||||||
app.logger.handlers = gunicorn_logger.handlers
|
app.logger.handlers = gunicorn_logger.handlers
|
||||||
app.logger.setLevel(gunicorn_logger.level)
|
app.logger.setLevel(gunicorn_logger.level)
|
||||||
|
|
||||||
# Check for wrong config that would break Tlapbot
|
# Check for wrong config that would break Tlapbot
|
||||||
if len(app.config['PREFIX']) != 1:
|
if len(app.config['PREFIX']) != 1:
|
||||||
raise RuntimeError("Prefix is >1 character. "
|
raise RuntimeError("Prefix is >1 character. "
|
||||||
"Change your config to set 1-character prefix.")
|
"Change your config to set 1-character prefix.")
|
||||||
|
|
||||||
# Check for spaces in redeems (they won't work)
|
# Check for spaces in redeems (they won't work)
|
||||||
for redeem in app.config['REDEEMS']:
|
for redeem in app.config['REDEEMS']:
|
||||||
if ' ' in redeem:
|
if ' ' in redeem:
|
||||||
app.logger.warning(f"Redeem '{redeem}' has spaces in its name.")
|
app.logger.warning(f"Redeem '{redeem}' has spaces in its name.")
|
||||||
app.logger.warning("Redeems with spaces are impossible to redeem.")
|
app.logger.warning("Redeems with spaces are impossible to redeem.")
|
||||||
|
|
||||||
|
|
||||||
# prepare webhooks and redeem dashboard blueprints
|
# prepare webhooks and redeem dashboard blueprints
|
||||||
from . import owncast_webhooks
|
from . import owncast_webhooks
|
||||||
from . import tlapbot_dashboard
|
from . import tlapbot_dashboard
|
||||||
|
@ -57,7 +58,7 @@ def create_app(test_config=None):
|
||||||
app.cli.add_command(db.refresh_milestones_command)
|
app.cli.add_command(db.refresh_milestones_command)
|
||||||
app.cli.add_command(db.reset_milestone_command)
|
app.cli.add_command(db.reset_milestone_command)
|
||||||
app.cli.add_command(db.hard_reset_milestone_command)
|
app.cli.add_command(db.hard_reset_milestone_command)
|
||||||
|
|
||||||
# scheduler job for giving points to users
|
# scheduler job for giving points to users
|
||||||
def proxy_job():
|
def proxy_job():
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
|
|
@ -6,7 +6,6 @@ from flask.cli import with_appcontext
|
||||||
|
|
||||||
from tlapbot.redeems import milestone_complete
|
from tlapbot.redeems import milestone_complete
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
if 'db' not in g:
|
if 'db' not in g:
|
||||||
g.db = sqlite3.connect(
|
g.db = sqlite3.connect(
|
||||||
|
@ -128,7 +127,7 @@ def refresh_milestones():
|
||||||
|
|
||||||
|
|
||||||
def reset_milestone(milestone):
|
def reset_milestone(milestone):
|
||||||
if milestone not in current_app.config['REDEEMS']:
|
if not milestone in current_app.config['REDEEMS']:
|
||||||
print(f"Failed resetting milestone, {milestone} not in redeems file.")
|
print(f"Failed resetting milestone, {milestone} not in redeems file.")
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
@ -148,6 +147,7 @@ def reset_milestone(milestone):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@click.command('init-db')
|
@click.command('init-db')
|
||||||
@with_appcontext
|
@with_appcontext
|
||||||
def init_db_command():
|
def init_db_command():
|
||||||
|
@ -184,7 +184,7 @@ def refresh_and_clear_command():
|
||||||
@click.command('refresh-milestones')
|
@click.command('refresh-milestones')
|
||||||
@with_appcontext
|
@with_appcontext
|
||||||
def refresh_milestones_command():
|
def refresh_milestones_command():
|
||||||
"""Initialize all milestones from the redeems file,
|
"""Initialize all milestones from the redeems file,
|
||||||
delete milestones not in redeem file."""
|
delete milestones not in redeem file."""
|
||||||
if refresh_milestones():
|
if refresh_milestones():
|
||||||
click.echo('Refreshed milestones.')
|
click.echo('Refreshed milestones.')
|
||||||
|
|
|
@ -2,7 +2,6 @@ from flask import current_app
|
||||||
from sqlite3 import Error
|
from sqlite3 import Error
|
||||||
from re import sub
|
from re import sub
|
||||||
|
|
||||||
|
|
||||||
# # # db stuff # # #
|
# # # db stuff # # #
|
||||||
def read_users_points(db, user_id):
|
def read_users_points(db, user_id):
|
||||||
"""Errors out if user doesn't exist."""
|
"""Errors out if user doesn't exist."""
|
||||||
|
@ -98,7 +97,7 @@ def add_user_to_database(db, user_id, display_name):
|
||||||
|
|
||||||
def change_display_name(db, user_id, new_name):
|
def change_display_name(db, user_id, new_name):
|
||||||
try:
|
try:
|
||||||
db.execute(
|
cursor = db.execute(
|
||||||
"UPDATE points SET name = ? WHERE id = ?",
|
"UPDATE points SET name = ? WHERE id = ?",
|
||||||
(new_name, user_id)
|
(new_name, user_id)
|
||||||
)
|
)
|
||||||
|
@ -110,7 +109,7 @@ def change_display_name(db, user_id, new_name):
|
||||||
|
|
||||||
def remove_duplicate_usernames(db, user_id, username):
|
def remove_duplicate_usernames(db, user_id, username):
|
||||||
try:
|
try:
|
||||||
db.execute(
|
cursor = db.execute(
|
||||||
"""UPDATE points
|
"""UPDATE points
|
||||||
SET name = NULL
|
SET name = NULL
|
||||||
WHERE name = ? AND NOT id = ?""",
|
WHERE name = ? AND NOT id = ?""",
|
||||||
|
|
|
@ -45,3 +45,4 @@ def send_chat(message):
|
||||||
current_app.logger.error(f"Check owncast instance url and access key.")
|
current_app.logger.error(f"Check owncast instance url and access key.")
|
||||||
return
|
return
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ def counter_exists(db, counter_name):
|
||||||
def add_to_counter(db, counter_name):
|
def add_to_counter(db, counter_name):
|
||||||
if counter_exists(db, counter_name):
|
if counter_exists(db, counter_name):
|
||||||
try:
|
try:
|
||||||
db.execute(
|
cursor = db.execute(
|
||||||
"UPDATE counters SET count = count + 1 WHERE name = ?",
|
"UPDATE counters SET count = count + 1 WHERE name = ?",
|
||||||
(counter_name,)
|
(counter_name,)
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,7 @@ def add_to_counter(db, counter_name):
|
||||||
|
|
||||||
def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
def add_to_redeem_queue(db, user_id, redeem_name, note=None):
|
||||||
try:
|
try:
|
||||||
db.execute(
|
cursor = db.execute(
|
||||||
"INSERT INTO redeem_queue(redeem, redeemer_id, note) VALUES(?, ?, ?)",
|
"INSERT INTO redeem_queue(redeem, redeemer_id, note) VALUES(?, ?, ?)",
|
||||||
(redeem_name, user_id, note)
|
(redeem_name, user_id, note)
|
||||||
)
|
)
|
||||||
|
@ -159,7 +159,7 @@ def all_active_milestones(db):
|
||||||
return all_active_milestones
|
return all_active_milestones
|
||||||
|
|
||||||
|
|
||||||
def all_active_redeems():
|
def all_active_redeems(db):
|
||||||
redeems = current_app.config['REDEEMS']
|
redeems = current_app.config['REDEEMS']
|
||||||
all_active_redeems = {}
|
all_active_redeems = {}
|
||||||
for redeem_name, redeem_dict in redeems.items():
|
for redeem_name, redeem_dict in redeems.items():
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from tlapbot.db import get_db
|
from tlapbot.db import get_db
|
||||||
from tlapbot.owncast_requests import send_chat
|
from tlapbot.owncast_requests import send_chat
|
||||||
from tlapbot.redeems import (add_to_redeem_queue, add_to_counter, add_to_milestone,
|
from tlapbot.redeems import (add_to_redeem_queue, add_to_counter, add_to_milestone,
|
||||||
check_apply_milestone_completion, milestone_complete, is_redeem_active)
|
check_apply_milestone_completion, milestone_complete, is_redeem_active)
|
||||||
from tlapbot.owncast_helpers import use_points, read_users_points
|
from tlapbot.owncast_helpers import use_points, read_users_points
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ def handle_redeem(message, user_id):
|
||||||
else:
|
else:
|
||||||
send_chat(f"Redeeming milestone {redeem} failed.")
|
send_chat(f"Redeeming milestone {redeem} failed.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# handle redeems with price argument
|
# handle redeems with price argument
|
||||||
price = current_app.config['REDEEMS'][redeem]["price"]
|
price = current_app.config['REDEEMS'][redeem]["price"]
|
||||||
if not points or points < price:
|
if not points or points < price:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from flask import render_template, Blueprint, request, current_app
|
from flask import render_template, Blueprint, request, current_app
|
||||||
from tlapbot.db import get_db
|
from tlapbot.db import get_db
|
||||||
from tlapbot.redeems import all_active_counters, all_active_milestones, all_active_redeems, 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 tlapbot.owncast_helpers import read_all_users_with_username
|
||||||
from datetime import timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
bp = Blueprint('redeem_dashboard', __name__)
|
bp = Blueprint('redeem_dashboard', __name__)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ def dashboard():
|
||||||
queue=pretty_redeem_queue(db),
|
queue=pretty_redeem_queue(db),
|
||||||
counters=all_active_counters(db),
|
counters=all_active_counters(db),
|
||||||
milestones=all_active_milestones(db),
|
milestones=all_active_milestones(db),
|
||||||
redeems=all_active_redeems(),
|
redeems=all_active_redeems(db),
|
||||||
prefix=current_app.config['PREFIX'],
|
prefix=current_app.config['PREFIX'],
|
||||||
passive=current_app.config['PASSIVE'],
|
passive=current_app.config['PASSIVE'],
|
||||||
username=username,
|
username=username,
|
||||||
|
|
Loading…
Reference in New Issue