From 3e1c7fd0b0ef1cb27e4b193c39b24cad3f88454f Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Sun, 4 May 2025 20:03:41 -0500 Subject: [PATCH] Add web_app.py --- web_app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 web_app.py diff --git a/web_app.py b/web_app.py new file mode 100644 index 0000000..979e167 --- /dev/null +++ b/web_app.py @@ -0,0 +1,21 @@ +from flask import Flask, request, jsonify +from irc_bot import bot +from config import API_TOKEN + +appV3 = Flask(__name__) + +# Handle incoming chatbox messages +@appV3.route("/incoming", methods=["POST"]) +def incoming(): + auth_header = request.headers.get("Authorization", "") + if auth_header != f"Bearer {API_TOKEN}": + return jsonify({"error": "Unauthorized"}), 401 + + data = request.get_json() + user = data.get("username") + text = data.get("text") + if not user or not text: + return jsonify({"error": "Invalid data"}), 400 + + bot.send_to_channel(f"[CHATBOX] {user}: {text}") + return jsonify({"success": True}), 200