22 lines
647 B
Python
22 lines
647 B
Python
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
|