Spaces:
Sleeping
Sleeping
Download main.py from arpy8/universal-bot-application: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/arpy8/universal-bot-application/resolve/main/main.py
- Command line
-
hf download hf://spaces/arpy8/universal-bot-application/main.py
-
curl -L -o main.py https://huggingface.co/spaces/arpy8/universal-bot-application/resolve/main/main.py
1.66 kB
| import os | |
| import requests | |
| from flask import Flask, request, jsonify | |
| from dotenv import load_dotenv | |
| from rich.console import Console | |
| load_dotenv() | |
| AUTH_TOKEN = os.environ.get('AUTH_TOKEN') | |
| DC_TOKEN = os.environ.get('DC_TOKEN') | |
| app = Flask(__name__) | |
| console = Console() | |
| def before_request(): | |
| if request.method == "POST": | |
| auth_header = request.headers.get("Authorization", "") | |
| if not auth_header.startswith("Bearer ") or auth_header[7:] != AUTH_TOKEN: | |
| return jsonify({"error": "Unauthorized"}), 401 | |
| def index(): | |
| return jsonify({"NOTE": "RAAAAAAHHHHHHHHHH!"}) | |
| def send_data(): | |
| try: | |
| channel_id = request.json.get("id") | |
| message = request.json.get("message") | |
| console.print(f"Sending message: [green on black]{message}[/green on black]") | |
| response = requests.post( | |
| url=f'https://discord.com/api/v10/channels/{str(channel_id)}/messages', | |
| headers={ | |
| 'Authorization': f'Bot {DC_TOKEN}', | |
| 'Content-Type': 'application/json', | |
| }, | |
| json={ | |
| 'content': message, | |
| } | |
| ) | |
| if response.status_code != 200: | |
| return jsonify({"error": "Error sending message"}), 500 | |
| return jsonify({"success": True, "message": "Message sent successfully"}), 200 | |
| except Exception as e: | |
| print("Error sending data:", str(e)) | |
| return jsonify({"error": "Error sending data"}), 500 | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860, debug=True) |