move help to own file, rewrite it

for speed and for better info
This commit is contained in:
Lili (Tlapka) 2022-11-07 17:30:40 +01:00
parent ee1eb66567
commit e4850ab89f
2 changed files with 22 additions and 9 deletions

19
tlapbot/help_message.py Normal file
View File

@ -0,0 +1,19 @@
from flask import current_app
from tlapbot.owncast_helpers import send_chat
def send_help():
message = []
message.append("""Tlapbot commands:
!help to see this help message.
!points to see your points.
!name_update to force name update if tlapbot didn't catch it.\n"""
)
if current_app.config['LIST_REDEEMS']:
message.append("Tlapbot redeems:\n")
for redeem, redeem_info in current_app.config['REDEEMS'].items():
if 'info' in redeem_info:
message.append(f"!{redeem} for {redeem_info['price']} points. {redeem_info['info']}\n")
else:
message.append(f"!{redeem} for {redeem_info['price']} points.\n")
send_chat(''.join(message))

View File

@ -3,8 +3,10 @@ from sqlite3 import Error
from tlapbot.db import get_db from tlapbot.db import get_db
from tlapbot.owncast_helpers import (add_user_to_database, change_display_name, from tlapbot.owncast_helpers import (add_user_to_database, change_display_name,
user_exists, send_chat, read_users_points, remove_duplicate_usernames) user_exists, send_chat, read_users_points, remove_duplicate_usernames)
from tlapbot.help_message import send_help
from tlapbot.redeems_handler import handle_redeem from tlapbot.redeems_handler import handle_redeem
bp = Blueprint('owncast_webhooks', __name__) bp = Blueprint('owncast_webhooks', __name__)
@ -31,15 +33,7 @@ def owncast_webhook():
print(f'New chat message from {display_name}:') print(f'New chat message from {display_name}:')
print(f'{data["eventData"]["body"]}') print(f'{data["eventData"]["body"]}')
if "!help" in data["eventData"]["body"]: if "!help" in data["eventData"]["body"]:
message = """Tlapbot commands: send_help()
!help to see this help message.
!points to see your points.
!name_update to force name update if tlapbot didn't catch it.
Tlapbot redeems:\n"""
for redeem, redeem_info in current_app.config['REDEEMS'].items():
message += (f"!{redeem} for {redeem_info['price']} points.\n")
# TODO: also make this customizable
send_chat(message)
elif "!points" in data["eventData"]["body"]: elif "!points" in data["eventData"]["body"]:
if not user_exists(db, user_id): if not user_exists(db, user_id):
add_user_to_database(db, user_id, display_name) add_user_to_database(db, user_id, display_name)