from flask import Flask, request, Response, copy_current_request_context, jsonify import threading import requests import asyncio import os import json bypass = os.getenv("BYPASS") MAX_REQUESTS_PER_MINUTE = 7 app = Flask("DiscordRocks Instant Chat Proxy") DISCORD_ROCKS_HOST = 'chat.discord.rocks' CHAT_UI_HOST = 'cutycat2000x-instantchat.static.hf.space' @app.route('/', methods=['GET', 'POST']) @app.route("/", methods=['GET', 'POST']) def handle_request(path=""): chat_ui_url = f'https://{DISCORD_ROCKS_HOST}/{path}' ip = request.remote_addr print("IP: "+ip) method = request.method data = request.data params = request.args headers = None didReply = False if method == 'POST': headers = {'Content-Type': 'application/json'} if 'reply' in path: json_data = request.get_json() json_data['bypass'] = bypass data = json.dumps(json_data) response = requests.request(method, chat_ui_url, params=params, data=data, headers=headers) proxied_response = Response(response.content) proxied_response.status_code = response.status_code proxied_response.headers["Content-Type"] = "text/html" return proxied_response if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)