testing2
Browse files
app.py
CHANGED
@@ -11,7 +11,8 @@ import requests # Ensure 'requests' is installed
|
|
11 |
from discord import Embed
|
12 |
from discord.ext import commands
|
13 |
from gradio_client import Client
|
14 |
-
from gradio_client.exceptions import AppError
|
|
|
15 |
|
16 |
# **Fetch Discord Bot Token from Environment Variable**
|
17 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
@@ -241,22 +242,47 @@ async def on_command_error(ctx: commands.Context, error):
|
|
241 |
|
242 |
|
243 |
async def handle_root(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
return web.Response(text="DarkMuse GOES VROOOOM", status=200)
|
245 |
|
246 |
|
247 |
async def start_web_server():
|
|
|
|
|
|
|
248 |
app = web.Application()
|
249 |
app.router.add_get('/', handle_root)
|
250 |
runner = web.AppRunner(app)
|
251 |
await runner.setup()
|
252 |
-
site = web.TCPSite(runner, '0.0.0.0',
|
253 |
await site.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
|
256 |
-
# Run the bot
|
257 |
if __name__ == '__main__':
|
258 |
try:
|
259 |
-
|
260 |
-
|
|
|
261 |
except Exception as e:
|
262 |
-
logger.exception(f"Failed to run the bot: {e}")
|
|
|
11 |
from discord import Embed
|
12 |
from discord.ext import commands
|
13 |
from gradio_client import Client
|
14 |
+
from gradio_client.exceptions import AppError
|
15 |
+
from aiohttp import web # Import aiohttp for the web server
|
16 |
|
17 |
# **Fetch Discord Bot Token from Environment Variable**
|
18 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
|
|
242 |
|
243 |
|
244 |
async def handle_root(request):
|
245 |
+
"""
|
246 |
+
Handler for the root URL. Responds with a simple text message.
|
247 |
+
|
248 |
+
Args:
|
249 |
+
request (aiohttp.web.Request): The incoming HTTP request.
|
250 |
+
|
251 |
+
Returns:
|
252 |
+
aiohttp.web.Response: The HTTP response.
|
253 |
+
"""
|
254 |
return web.Response(text="DarkMuse GOES VROOOOM", status=200)
|
255 |
|
256 |
|
257 |
async def start_web_server():
|
258 |
+
"""
|
259 |
+
Initializes and starts the aiohttp web server on port 80.
|
260 |
+
"""
|
261 |
app = web.Application()
|
262 |
app.router.add_get('/', handle_root)
|
263 |
runner = web.AppRunner(app)
|
264 |
await runner.setup()
|
265 |
+
site = web.TCPSite(runner, '0.0.0.0', 80) # Change to 80 for HTTP
|
266 |
await site.start()
|
267 |
+
logger.info("Web server started on port 80")
|
268 |
+
|
269 |
+
|
270 |
+
async def main():
|
271 |
+
"""
|
272 |
+
Main entry point to run both the Discord bot and the web server concurrently.
|
273 |
+
"""
|
274 |
+
# Start the web server
|
275 |
+
await start_web_server()
|
276 |
+
|
277 |
+
# Start the Discord bot
|
278 |
+
await bot.start(DISCORD_BOT_TOKEN)
|
279 |
|
280 |
|
281 |
+
# Run the bot and the web server concurrently
|
282 |
if __name__ == '__main__':
|
283 |
try:
|
284 |
+
asyncio.run(main())
|
285 |
+
except KeyboardInterrupt:
|
286 |
+
logger.info("Shutting down bot and web server...")
|
287 |
except Exception as e:
|
288 |
+
logger.exception(f"Failed to run the bot and web server: {e}")
|