fix behavior with 2 commands + new user crashes
issue #5 crash i discovered when testing (users joining when bot is resetting)
This commit is contained in:
parent
9c0e709c63
commit
bafa1eca16
|
@ -13,11 +13,14 @@ bp = Blueprint('owncast_webhooks', __name__)
|
||||||
def owncast_webhook():
|
def owncast_webhook():
|
||||||
data = request.json
|
data = request.json
|
||||||
db = get_db()
|
db = get_db()
|
||||||
if data["type"] == "USER_JOINED":
|
|
||||||
|
# Make sure user is in db before doing anything else.
|
||||||
|
if data["type"] in ["CHAT", "NAME_CHANGED", "USER_JOINED"]:
|
||||||
user_id = data["eventData"]["user"]["id"]
|
user_id = data["eventData"]["user"]["id"]
|
||||||
display_name = data["eventData"]["user"]["displayName"]
|
display_name = data["eventData"]["user"]["displayName"]
|
||||||
# CONSIDER: join points for joining stream
|
|
||||||
add_user_to_database(db, user_id, display_name)
|
add_user_to_database(db, user_id, display_name)
|
||||||
|
|
||||||
|
if data["type"] == "USER_JOINED":
|
||||||
if data["eventData"]["user"]["authenticated"]:
|
if data["eventData"]["user"]["authenticated"]:
|
||||||
remove_duplicate_usernames(db, user_id, display_name)
|
remove_duplicate_usernames(db, user_id, display_name)
|
||||||
elif data["type"] == "NAME_CHANGE":
|
elif data["type"] == "NAME_CHANGE":
|
||||||
|
@ -31,15 +34,12 @@ 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"]["body"]}')
|
current_app.logger.debug(f'{data["eventData"]["body"]}')
|
||||||
if "!help" in data["eventData"]["body"]:
|
if data["eventData"]["body"].startswith("!help"):
|
||||||
send_help()
|
send_help()
|
||||||
elif "!points" in data["eventData"]["body"]:
|
elif data["eventData"]["body"].startswith("!points"):
|
||||||
if not user_exists(db, user_id):
|
|
||||||
add_user_to_database(db, user_id, display_name)
|
|
||||||
points = read_users_points(db, user_id)
|
points = read_users_points(db, user_id)
|
||||||
message = f"{display_name}'s points: {points}"
|
send_chat(f"{display_name}'s points: {points}")
|
||||||
send_chat(message)
|
elif data["eventData"]["body"].startswith("!name_update"):
|
||||||
elif "!name_update" in data["eventData"]["body"]:
|
|
||||||
# Forces name update in case bot didn't catch the NAME_CHANGE
|
# Forces name update in case bot didn't catch the NAME_CHANGE
|
||||||
# event. Also removes saved usernames from users with same name
|
# event. Also removes saved usernames from users with same name
|
||||||
# if user is authenticated.
|
# if user is authenticated.
|
||||||
|
|
Loading…
Reference in New Issue