Compare commits

..

6 Commits

4 changed files with 12 additions and 3 deletions

View File

@ -329,7 +329,8 @@ REDEEMS={
``` ```
#### File format #### File format
`redeems.py` is a config file with just a `REDEEMS` key, that assigns a dictionary of redeems to it. `redeems.py` is a config file with just a `REDEEMS` key, that assigns a dictionary of redeems to it.
Each dictionary entry is a redeem, and the dictionary keys are strings that decides the chat command for the redeem. Each dictionary entry is a redeem, and the dictionary keys are strings that decide the chat command for the redeem.
The redeem names shouldn't have spaces in them.
The value is another dictionary that needs to have an entry for `"type"` and The value is another dictionary that needs to have an entry for `"type"` and
an entry for `"price"` for non-milestones or `"goal"` for milestones. an entry for `"price"` for non-milestones or `"goal"` for milestones.
Optionally, each redeem can also have `"info"` and `"category"` entries. Optionally, each redeem can also have `"info"` and `"category"` entries.

View File

@ -35,6 +35,13 @@ def create_app(test_config=None):
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)
for redeem, _ in app.config['REDEEMS']:
if ' ' in redeem:
app.logger.warning(f"Redeem {redeem} has spaces in its name.")
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

View File

@ -37,7 +37,6 @@ def owncast_webhook():
display_name = data["eventData"]["user"]["displayName"] display_name = data["eventData"]["user"]["displayName"]
current_app.logger.debug(f'New chat message from {display_name}:') current_app.logger.debug(f'New chat message from {display_name}:')
current_app.logger.debug(f'{data["eventData"]["rawBody"]}') current_app.logger.debug(f'{data["eventData"]["rawBody"]}')
current_app.logger.debug(f'{data["eventData"]["body"]}')
if data["eventData"]["rawBody"].startswith(f"{prefix}help"): if data["eventData"]["rawBody"].startswith(f"{prefix}help"):
send_help() send_help()
elif data["eventData"]["rawBody"].startswith(f"{prefix}points"): elif data["eventData"]["rawBody"].startswith(f"{prefix}points"):

View File

@ -32,9 +32,11 @@ def handle_redeem(message, user_id):
elif not note: elif not note:
send_chat(f"Cannot redeem {redeem}, no amount of points specified.") send_chat(f"Cannot redeem {redeem}, no amount of points specified.")
elif not note.isdigit(): elif not note.isdigit():
send_chat(f"Cannot redeem {redeem}, amount of points is not an integer.") send_chat(f"Cannot redeem {redeem}, amount of points is not a positive integer.")
elif int(note) > points: elif int(note) > points:
send_chat(f"Can't redeem {redeem}, you're donating more points than you have.") send_chat(f"Can't redeem {redeem}, you're donating more points than you have.")
elif int(note) == 0:
send_chat(f"Can't donate zero points.")
elif add_to_milestone(db, user_id, redeem, int(note)): elif add_to_milestone(db, user_id, redeem, int(note)):
send_chat(f"Succesfully donated to {redeem} milestone!") send_chat(f"Succesfully donated to {redeem} milestone!")
if check_apply_milestone_completion(db, redeem): if check_apply_milestone_completion(db, redeem):