import redis from flask import Flask, request, jsonify from config import API_TOKEN, REDIS_PW r = redis.Redis(host='localhost', port=6969, password=REDIS_PW, db=0) 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 msg = f"[CHAT] {user}: {text}" try: r.publish("chatbox_to_irc", msg) print(f"[REDIS] Published: {msg}") except Exception as e: print(f"[-] Redis publish failed: {e}") return jsonify({"error": "Redis error"}), 500 return jsonify({"success": True}), 200