Update app/app.py
Browse files- app/app.py +56 -1
app/app.py
CHANGED
@@ -22,10 +22,12 @@ logger = logging.getLogger(__name__)
|
|
22 |
# Konfiguration
|
23 |
PUBLIC_KEY = os.getenv('Public_Key', '').strip()
|
24 |
APPLICATION_ID = os.getenv('Application_ID', '').strip()
|
|
|
25 |
PORT = int(os.getenv('PORT', 7860)) # Hugging Face nutzt standardmäßig Port 7860
|
26 |
|
27 |
app = Flask(__name__)
|
28 |
|
|
|
29 |
try:
|
30 |
verify_key = VerifyKey(bytes.fromhex(PUBLIC_KEY)) if PUBLIC_KEY else None
|
31 |
logger.info("Successfully initialized verify_key")
|
@@ -104,12 +106,65 @@ def health_check_worker():
|
|
104 |
logger.error(f"Health check failed: {str(e)}")
|
105 |
time.sleep(30)
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
if __name__ == "__main__":
|
108 |
logger.info(f"Starting Discord bot on port {PORT}...")
|
109 |
|
110 |
# Starte Health-Check Worker in separatem Thread
|
111 |
health_thread = threading.Thread(target=health_check_worker, daemon=True)
|
112 |
health_thread.start()
|
|
|
|
|
|
|
113 |
|
114 |
# Starte Server
|
115 |
-
serve(app, host="0.0.0.0", port=PORT)
|
|
|
22 |
# Konfiguration
|
23 |
PUBLIC_KEY = os.getenv('Public_Key', '').strip()
|
24 |
APPLICATION_ID = os.getenv('Application_ID', '').strip()
|
25 |
+
BOT_TOKEN = os.getenv('BOT_TOKEN', '').strip()
|
26 |
PORT = int(os.getenv('PORT', 7860)) # Hugging Face nutzt standardmäßig Port 7860
|
27 |
|
28 |
app = Flask(__name__)
|
29 |
|
30 |
+
# Schlüssel zur Überprüfung von Anfragen initialisieren
|
31 |
try:
|
32 |
verify_key = VerifyKey(bytes.fromhex(PUBLIC_KEY)) if PUBLIC_KEY else None
|
33 |
logger.info("Successfully initialized verify_key")
|
|
|
106 |
logger.error(f"Health check failed: {str(e)}")
|
107 |
time.sleep(30)
|
108 |
|
109 |
+
def register_commands():
|
110 |
+
"""Registriere Befehle bei Discord"""
|
111 |
+
url = f"https://discord.com/api/v10/applications/{APPLICATION_ID}/commands"
|
112 |
+
headers = {
|
113 |
+
"Authorization": f"Bot {BOT_TOKEN}"
|
114 |
+
}
|
115 |
+
json = {
|
116 |
+
"name": "settings",
|
117 |
+
"description": "Prüft den Status des Bots",
|
118 |
+
"type": 1
|
119 |
+
}
|
120 |
+
|
121 |
+
response = requests.post(url, headers=headers, json=json)
|
122 |
+
if response.status_code == 200:
|
123 |
+
logger.info("Command successfully registered")
|
124 |
+
else:
|
125 |
+
logger.error(f"Failed to register command: {response.status_code} - {response.json()}")
|
126 |
+
|
127 |
+
def setup_discord_channel_and_role(guild_id):
|
128 |
+
"""Erstellt einen Log-Channel und eine Rolle in der angegebenen Guild"""
|
129 |
+
headers = {
|
130 |
+
"Authorization": f"Bot {BOT_TOKEN}"
|
131 |
+
}
|
132 |
+
|
133 |
+
# Channel erstellen
|
134 |
+
channel_url = f"https://discord.com/api/v10/guilds/{guild_id}/channels"
|
135 |
+
channel_json = {
|
136 |
+
"name": "bot-logs",
|
137 |
+
"type": 0 # Text-Channel
|
138 |
+
}
|
139 |
+
channel_response = requests.post(channel_url, headers=headers, json=channel_json)
|
140 |
+
|
141 |
+
if channel_response.status_code == 201:
|
142 |
+
logger.info("Log-Channel successfully created")
|
143 |
+
else:
|
144 |
+
logger.error(f"Failed to create log-channel: {channel_response.status_code} - {channel_response.json()}")
|
145 |
+
|
146 |
+
# Rolle erstellen
|
147 |
+
role_url = f"https://discord.com/api/v10/guilds/{guild_id}/roles"
|
148 |
+
role_json = {
|
149 |
+
"name": "Bot Commander",
|
150 |
+
"permissions": "8" # Administrator-Rechte
|
151 |
+
}
|
152 |
+
role_response = requests.post(role_url, headers=headers, json=role_json)
|
153 |
+
|
154 |
+
if role_response.status_code == 201:
|
155 |
+
logger.info("Role successfully created")
|
156 |
+
else:
|
157 |
+
logger.error(f"Failed to create role: {role_response.status_code} - {role_response.json()}")
|
158 |
+
|
159 |
if __name__ == "__main__":
|
160 |
logger.info(f"Starting Discord bot on port {PORT}...")
|
161 |
|
162 |
# Starte Health-Check Worker in separatem Thread
|
163 |
health_thread = threading.Thread(target=health_check_worker, daemon=True)
|
164 |
health_thread.start()
|
165 |
+
|
166 |
+
# Registriere Slash-Command
|
167 |
+
register_commands()
|
168 |
|
169 |
# Starte Server
|
170 |
+
serve(app, host="0.0.0.0", port=PORT)
|