diff --git a/tlapbot/owncastWebhooks.py b/tlapbot/owncastWebhooks.py index 2065ff6..7108629 100644 --- a/tlapbot/owncastWebhooks.py +++ b/tlapbot/owncastWebhooks.py @@ -35,6 +35,12 @@ def addUserToDatabase(user_id, db): print("Error occured adding user to db:", e.args[0]) print("To user:", user_id) +def sendChat(message): # TODO: url to constant? + url = 'http://localhost:8080/api/integrations/chat/send' + headers = {"Authorization": "Bearer " + OWNCAST_ACCESS_TOKEN} + r = requests.post(url, headers=headers, json={"body": message}) + return r.json() + @bp.route('/owncastWebhook',methods=['POST']) def owncastWebhook(): data = request.json @@ -60,7 +66,10 @@ def owncastWebhook(): "SELECT points FROM points WHERE id = ?", (user_id,) ) - print("{}'s points: {}".format(display_name, cursor.fetchone()[0])) + message = "{}'s points: {}".format(display_name, cursor.fetchone()[0]) + print(message) + sendChat(message) + except Error as e: print("Error occured reading points:", e.args[0]) print("To user:", user_id) @@ -76,7 +85,4 @@ def owncastWebhook(): print("Error occured giving DEBUG points:", e.args[0]) print("To user:", user_id) - return data - -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + return data \ No newline at end of file