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