|
@@ -1,7 +1,7 @@
|
|
|
-from flask import flash, render_template, Blueprint, current_app, redirect, request, url_for, session, g
|
|
|
|
|
|
|
+from flask import flash, render_template, Blueprint, current_app, redirect, request, url_for, session, g, send_from_directory
|
|
|
from datetime import timezone
|
|
from datetime import timezone
|
|
|
from ownchatbot.db import get_db, reread_goals, reread_votes, rem_vote, reset_vote, reset_goal, clear_fulfilled_rewards, clear_reward_queue, rem_cool, rem_from_queue
|
|
from ownchatbot.db import get_db, reread_goals, reread_votes, rem_vote, reset_vote, reset_goal, clear_fulfilled_rewards, clear_reward_queue, rem_cool, rem_from_queue
|
|
|
-from ownchatbot.reward_handlers import all_active_votes, all_active_goals, all_active_rewards, get_queue, fulfill_reward, save_rewards, activate_category, deactivate_category, refund_reward, reread_categories, save_config
|
|
|
|
|
|
|
+from ownchatbot.reward_handlers import all_active_votes, all_active_goals, all_active_rewards, get_queue, fulfill_reward, save_rewards, activate_category, deactivate_category, refund_reward, reread_categories, save_config, save_alerts, del_alert_file
|
|
|
from ownchatbot.user_handlers import get_all_users, get_all_users_by_name, refund_points, adjust_points, change_email, get_email_code, del_email_code, save_todolist, save_todocss
|
|
from ownchatbot.user_handlers import get_all_users, get_all_users_by_name, refund_points, adjust_points, change_email, get_email_code, del_email_code, save_todolist, save_todocss
|
|
|
from ownchatbot.bot_messages import save_announce
|
|
from ownchatbot.bot_messages import save_announce
|
|
|
from ownchatbot.owncast_com import send_private_chat
|
|
from ownchatbot.owncast_com import send_private_chat
|
|
@@ -12,6 +12,7 @@ import random
|
|
|
import pkce
|
|
import pkce
|
|
|
import requests
|
|
import requests
|
|
|
from functools import wraps
|
|
from functools import wraps
|
|
|
|
|
+import os
|
|
|
|
|
|
|
|
ocb = Blueprint('web_panels', __name__)
|
|
ocb = Blueprint('web_panels', __name__)
|
|
|
|
|
|
|
@@ -106,6 +107,7 @@ def mgmt():
|
|
|
todolist_items = current_app.config['LIST']
|
|
todolist_items = current_app.config['LIST']
|
|
|
todo_css = current_app.config['CSS']
|
|
todo_css = current_app.config['CSS']
|
|
|
active_tab = request.args.get('activeTab')
|
|
active_tab = request.args.get('activeTab')
|
|
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
settings_info = [
|
|
settings_info = [
|
|
|
access_id,
|
|
access_id,
|
|
|
points_interval,
|
|
points_interval,
|
|
@@ -138,6 +140,7 @@ def mgmt():
|
|
|
settings_info=settings_info,
|
|
settings_info=settings_info,
|
|
|
items=todolist_items,
|
|
items=todolist_items,
|
|
|
todo_css=todo_css,
|
|
todo_css=todo_css,
|
|
|
|
|
+ alerts_dict=alerts_dict,
|
|
|
activeTab=active_tab)
|
|
activeTab=active_tab)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -496,18 +499,21 @@ def set_viewer_email():
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/activate/<category>', methods=['GET', 'POST'])
|
|
@ocb.route('/mgmt/activate/<category>', methods=['GET', 'POST'])
|
|
|
|
|
+@requires_login
|
|
|
def activate(category):
|
|
def activate(category):
|
|
|
activate_category(category)
|
|
activate_category(category)
|
|
|
return redirect(url_for('web_panels.mgmt', activeTab='categories'))
|
|
return redirect(url_for('web_panels.mgmt', activeTab='categories'))
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/deactivate/<category>', methods=['GET', 'POST'])
|
|
@ocb.route('/mgmt/deactivate/<category>', methods=['GET', 'POST'])
|
|
|
|
|
+@requires_login
|
|
|
def deactivate(category):
|
|
def deactivate(category):
|
|
|
deactivate_category(category)
|
|
deactivate_category(category)
|
|
|
return redirect(url_for('web_panels.mgmt', activeTab='categories'))
|
|
return redirect(url_for('web_panels.mgmt', activeTab='categories'))
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/delcat/<cat_name>/<cat_act>', methods=['GET', 'POST'])
|
|
@ocb.route('/mgmt/delcat/<cat_name>/<cat_act>', methods=['GET', 'POST'])
|
|
|
|
|
+@requires_login
|
|
|
def delcat(cat_name, cat_act):
|
|
def delcat(cat_name, cat_act):
|
|
|
active_categories = current_app.config['ACTIVE_CAT']
|
|
active_categories = current_app.config['ACTIVE_CAT']
|
|
|
inactive_categories = current_app.config['INACTIVE_CAT']
|
|
inactive_categories = current_app.config['INACTIVE_CAT']
|
|
@@ -525,6 +531,7 @@ def delcat(cat_name, cat_act):
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/reset/<reward_name>/<reward_type>', methods=['GET', 'POST']) # Reset votes and goals to zero
|
|
@ocb.route('/mgmt/reset/<reward_name>/<reward_type>', methods=['GET', 'POST']) # Reset votes and goals to zero
|
|
|
|
|
+@requires_login
|
|
|
def reset(reward_name, reward_type):
|
|
def reset(reward_name, reward_type):
|
|
|
if reward_type == "goal":
|
|
if reward_type == "goal":
|
|
|
reset_goal(reward_name)
|
|
reset_goal(reward_name)
|
|
@@ -540,18 +547,21 @@ def rereadv():
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/clearfulfilled', methods=['GET', 'POST'])
|
|
@ocb.route('/mgmt/clearfulfilled', methods=['GET', 'POST'])
|
|
|
|
|
+@requires_login
|
|
|
def clearfulfilled():
|
|
def clearfulfilled():
|
|
|
clear_fulfilled_rewards()
|
|
clear_fulfilled_rewards()
|
|
|
return redirect(url_for('web_panels.mgmtqueue'))
|
|
return redirect(url_for('web_panels.mgmtqueue'))
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/clearqueue', methods=['GET', 'POST'])
|
|
@ocb.route('/mgmt/clearqueue', methods=['GET', 'POST'])
|
|
|
|
|
+@requires_login
|
|
|
def clear_queue():
|
|
def clear_queue():
|
|
|
clear_reward_queue()
|
|
clear_reward_queue()
|
|
|
return redirect(url_for('web_panels.mgmtqueue'))
|
|
return redirect(url_for('web_panels.mgmtqueue'))
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/addtodocss', methods=['POST'])
|
|
@ocb.route('/mgmt/addtodocss', methods=['POST'])
|
|
|
|
|
+@requires_login
|
|
|
def add_todo_css():
|
|
def add_todo_css():
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
|
new_css = request.form.get('todo_css')
|
|
new_css = request.form.get('todo_css')
|
|
@@ -567,6 +577,7 @@ def add_todo_css():
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/addtodoitem', methods=['POST'])
|
|
@ocb.route('/mgmt/addtodoitem', methods=['POST'])
|
|
|
|
|
+@requires_login
|
|
|
def add_todo_item():
|
|
def add_todo_item():
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
|
todolist_items = current_app.config['LIST']
|
|
todolist_items = current_app.config['LIST']
|
|
@@ -580,6 +591,7 @@ def add_todo_item():
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/cross/<int:item_id>')
|
|
@ocb.route('/mgmt/cross/<int:item_id>')
|
|
|
|
|
+@requires_login
|
|
|
def cross(item_id):
|
|
def cross(item_id):
|
|
|
todolist_items = current_app.config['LIST']
|
|
todolist_items = current_app.config['LIST']
|
|
|
if 0 <= item_id < len(todolist_items):
|
|
if 0 <= item_id < len(todolist_items):
|
|
@@ -590,6 +602,7 @@ def cross(item_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/uncross/<int:item_id>')
|
|
@ocb.route('/mgmt/uncross/<int:item_id>')
|
|
|
|
|
+@requires_login
|
|
|
def uncross(item_id):
|
|
def uncross(item_id):
|
|
|
todolist_items = current_app.config['LIST']
|
|
todolist_items = current_app.config['LIST']
|
|
|
if 0 <= item_id < len(todolist_items):
|
|
if 0 <= item_id < len(todolist_items):
|
|
@@ -600,6 +613,7 @@ def uncross(item_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/mgmt/clearlist')
|
|
@ocb.route('/mgmt/clearlist')
|
|
|
|
|
+@requires_login
|
|
|
def clear_list():
|
|
def clear_list():
|
|
|
todolist_items = current_app.config['LIST']
|
|
todolist_items = current_app.config['LIST']
|
|
|
todolist_items = [] # Clear the list
|
|
todolist_items = [] # Clear the list
|
|
@@ -608,6 +622,55 @@ def clear_list():
|
|
|
return redirect(url_for('web_panels.mgmt', activeTab='todolist'))
|
|
return redirect(url_for('web_panels.mgmt', activeTab='todolist'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@ocb.route('/mgmt/alertupload/<alert_type>', methods=['POST'])
|
|
|
|
|
+@requires_login
|
|
|
|
|
+def alert_upload(alert_type):
|
|
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
|
|
+ alert_file = request.files[alert_type]
|
|
|
|
|
+ if alert_type in alerts_dict.keys(): # If the alert already exists, delete the existing alert file
|
|
|
|
|
+ old_file = alerts_dict[alert_type.upper()]
|
|
|
|
|
+ current_app.logger.info(f'{alert_type} already set.')
|
|
|
|
|
+ if del_alert_file(old_file):
|
|
|
|
|
+ pass
|
|
|
|
|
+ filepath = os.path.join(current_app.config['ALERTS_FOLDER'], alert_file.filename)
|
|
|
|
|
+ alert_file.save(filepath)
|
|
|
|
|
+ alerts_dict[alert_type] = alert_file.filename
|
|
|
|
|
+ if save_alerts(alerts_dict): # Save new alerts.py
|
|
|
|
|
+ return redirect(url_for('web_panels.mgmt', activeTab='alerts'))
|
|
|
|
|
+
|
|
|
|
|
+ return redirect(url_for('web_panels.mgmt', activeTab='alerts'))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@ocb.route('/mgmt/delalert/<alert_type>')
|
|
|
|
|
+@requires_login
|
|
|
|
|
+def del_alert(alert_type):
|
|
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
|
|
+ try:
|
|
|
|
|
+ alert_file = alerts_dict[alert_type]
|
|
|
|
|
+ alerts_dict.pop(alert_type)
|
|
|
|
|
+ if save_alerts(alerts_dict):
|
|
|
|
|
+ current_app.logger.info(f'Removed {alert_type} from alerts.py.')
|
|
|
|
|
+ if del_alert_file(alert_file):
|
|
|
|
|
+ pass
|
|
|
|
|
+ except KeyError:
|
|
|
|
|
+ current_app.logger.info(f'No {alert_type} alert set. Nothing to do.')
|
|
|
|
|
+ return redirect(url_for('web_panels.mgmt', activeTab='alerts'))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@ocb.route('/alerts/<alert_name>') # Route for alerts overlay
|
|
|
|
|
+def alerts(alert_name):
|
|
|
|
|
+ return send_from_directory(current_app.config['ALERTS_FOLDER'], alert_name)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@ocb.route('/ocbalert/<alert_type>') # Route for alerts overlay
|
|
|
|
|
+def ocb_alerts(alert_type):
|
|
|
|
|
+ alert_type = alert_type.upper()
|
|
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
|
|
+ alert_name = alerts_dict[alert_type]
|
|
|
|
|
+ return render_template('ocbalert.html',
|
|
|
|
|
+ alert_name=alert_name)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@ocb.route('/goals', methods=['GET']) # Route for goals overlay
|
|
@ocb.route('/goals', methods=['GET']) # Route for goals overlay
|
|
|
def goals():
|
|
def goals():
|
|
|
db = get_db()
|
|
db = get_db()
|