Spaces:
Running
Running
Update app/app.py
Browse files- app/app.py +21 -15
app/app.py
CHANGED
@@ -2,9 +2,13 @@
|
|
2 |
from flask import Flask, request, jsonify
|
3 |
import os
|
4 |
import logging
|
|
|
5 |
|
6 |
# Logging konfigurieren
|
7 |
-
logging.basicConfig(
|
|
|
|
|
|
|
8 |
logger = logging.getLogger(__name__)
|
9 |
|
10 |
app = Flask(__name__)
|
@@ -12,21 +16,28 @@ app = Flask(__name__)
|
|
12 |
@app.route("/", methods=["GET"])
|
13 |
def health_check():
|
14 |
logger.info("Health check endpoint called")
|
15 |
-
return jsonify({
|
|
|
|
|
|
|
16 |
|
17 |
@app.route("/interactions", methods=["POST"])
|
18 |
def interactions():
|
|
|
|
|
|
|
|
|
19 |
data = request.json
|
20 |
-
logger.info(f"Received interaction
|
21 |
|
22 |
# Discord Ping Verification
|
23 |
-
if data
|
24 |
logger.info("Responding to ping verification")
|
25 |
return jsonify({"type": 1})
|
26 |
|
27 |
# Slash Command Handler
|
28 |
-
if data
|
29 |
-
command = data
|
30 |
logger.info(f"Received command: {command}")
|
31 |
if command == "settings":
|
32 |
return jsonify({
|
@@ -36,14 +47,9 @@ def interactions():
|
|
36 |
}
|
37 |
})
|
38 |
|
39 |
-
return jsonify({})
|
40 |
-
|
41 |
-
@app.before_request
|
42 |
-
def log_request_info():
|
43 |
-
logger.info(f"Request Method: {request.method}")
|
44 |
-
logger.info(f"Request Path: {request.path}")
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
-
logger.info("Starting Discord bot...")
|
48 |
-
|
49 |
-
|
|
|
2 |
from flask import Flask, request, jsonify
|
3 |
import os
|
4 |
import logging
|
5 |
+
from waitress import serve
|
6 |
|
7 |
# Logging konfigurieren
|
8 |
+
logging.basicConfig(
|
9 |
+
level=logging.INFO,
|
10 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
11 |
+
)
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
app = Flask(__name__)
|
|
|
16 |
@app.route("/", methods=["GET"])
|
17 |
def health_check():
|
18 |
logger.info("Health check endpoint called")
|
19 |
+
return jsonify({
|
20 |
+
"status": "healthy",
|
21 |
+
"message": "Discord bot is running on Hugging Face Spaces!"
|
22 |
+
})
|
23 |
|
24 |
@app.route("/interactions", methods=["POST"])
|
25 |
def interactions():
|
26 |
+
if not request.is_json:
|
27 |
+
logger.warning("Received non-JSON request")
|
28 |
+
return jsonify({"error": "Expected JSON data"}), 400
|
29 |
+
|
30 |
data = request.json
|
31 |
+
logger.info(f"Received interaction: {data.get('type')}")
|
32 |
|
33 |
# Discord Ping Verification
|
34 |
+
if data.get("type") == 1:
|
35 |
logger.info("Responding to ping verification")
|
36 |
return jsonify({"type": 1})
|
37 |
|
38 |
# Slash Command Handler
|
39 |
+
if data.get("type") == 2:
|
40 |
+
command = data.get("data", {}).get("name")
|
41 |
logger.info(f"Received command: {command}")
|
42 |
if command == "settings":
|
43 |
return jsonify({
|
|
|
47 |
}
|
48 |
})
|
49 |
|
50 |
+
return jsonify({"error": "Unknown interaction type"}), 400
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
logger.info("Starting Discord bot on Hugging Face Spaces...")
|
54 |
+
# Für Hugging Face Spaces nutzen wir Waitress statt development server
|
55 |
+
serve(app, host="0.0.0.0", port=8080)
|