diff --git a/discord_bot.log b/discord_bot.log index 01bc5f8..031d523 100644 --- a/discord_bot.log +++ b/discord_bot.log @@ -27099,3 +27099,176 @@ Max Tokens: 1000 2025-02-11 20:10:39 - ERROR - discord_bot - run_bot:363 - Error stopping bot: Event loop stopped before Future completed. 2025-02-11 20:10:39 - INFO - discord_bot - stop:299 - Shutdown complete 2025-02-11 20:10:39 - INFO - discord_bot - run_bot:366 - Bot shutdown complete +2025-02-11 20:11:59 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:11:59 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:11:59 - INFO - discord_bot - validate_config:290 - Vision API Configuration: +Model: meta-llama/llama-3.2-90b-vision-instruct:free +Base URL: https://openrouter.ai/api/v1/chat/completions +Timeout: 30.0 +Max Tokens: 1000 +2025-02-11 20:11:59 - WARNING - discord_bot - validate_config:326 - GLHF API is not fully configured. API features will be disabled. +2025-02-11 20:11:59 - INFO - discord_bot - validate_config:356 - Configuration validated successfully +2025-02-11 20:11:59 - INFO - discord_bot - load_state:40 - Queue state loaded from file - Pending messages: 0 +2025-02-11 20:11:59 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:12:02 - INFO - discord_bot - on_ready:156 - CobraSilver#8886 has connected to Discord! +2025-02-11 20:12:02 - INFO - discord_bot - init_db:184 - Initializing database schema... +2025-02-11 20:12:02 - INFO - discord_bot - _init_connection:96 - Database connection initialized with optimized settings +2025-02-11 20:12:02 - INFO - discord_bot - init_db:201 - Users table created/verified +2025-02-11 20:12:02 - INFO - discord_bot - init_db:216 - Threads table created/verified +2025-02-11 20:12:02 - INFO - discord_bot - init_db:236 - Messages table created/verified +2025-02-11 20:12:02 - INFO - discord_bot - init_db:271 - All indices created/verified +2025-02-11 20:12:02 - INFO - discord_bot - init_db:274 - Database schema initialized successfully +2025-02-11 20:12:02 - INFO - discord_bot - start:38 - API manager started +2025-02-11 20:12:02 - INFO - discord_bot - on_ready:172 - Started API health check loop +2025-02-11 20:12:03 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:12:03 - INFO - discord_bot - _process_queue:207 - Queue processor 6bc98aa8 starting +2025-02-11 20:12:03 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:12:14 - INFO - discord_bot - shutdown:306 - Received SIGINT +2025-02-11 20:12:14 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:12:14 - WARNING - discord_bot - _process_queue:329 - Queue processor 6bc98aa8 exited - Processed: 1859, Failed: 46 +2025-02-11 20:12:14 - INFO - discord_bot - shutdown:306 - Received SIGTERM +2025-02-11 20:12:14 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:12:14 - INFO - discord_bot - shutdown:46 - API manager shutdown +2025-02-11 20:12:14 - INFO - discord_bot - stop:276 - Stopped API health check loop +2025-02-11 20:12:14 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:12:14 - DEBUG - discord_bot - _close_connection:107 - Database connection closed +2025-02-11 20:12:14 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:12:14 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:12:14 - INFO - discord_bot - run_bot:366 - Bot shutdown complete +2025-02-11 20:16:46 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:16:46 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:16:47 - INFO - discord_bot - validate_config:290 - Vision API Configuration: +Model: meta-llama/llama-3.2-90b-vision-instruct:free +Base URL: https://openrouter.ai/api/v1/chat/completions +Timeout: 30.0 +Max Tokens: 1000 +2025-02-11 20:16:47 - WARNING - discord_bot - validate_config:326 - GLHF API is not fully configured. API features will be disabled. +2025-02-11 20:16:47 - INFO - discord_bot - validate_config:356 - Configuration validated successfully +2025-02-11 20:16:47 - INFO - discord_bot - load_state:40 - Queue state loaded from file - Pending messages: 0 +2025-02-11 20:16:47 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:16:50 - INFO - discord_bot - on_ready:156 - CobraSilver#8886 has connected to Discord! +2025-02-11 20:16:50 - INFO - discord_bot - init_db:184 - Initializing database schema... +2025-02-11 20:16:50 - INFO - discord_bot - _init_connection:96 - Database connection initialized with optimized settings +2025-02-11 20:16:50 - INFO - discord_bot - init_db:201 - Users table created/verified +2025-02-11 20:16:50 - INFO - discord_bot - init_db:216 - Threads table created/verified +2025-02-11 20:16:50 - INFO - discord_bot - init_db:236 - Messages table created/verified +2025-02-11 20:16:50 - INFO - discord_bot - init_db:271 - All indices created/verified +2025-02-11 20:16:50 - INFO - discord_bot - init_db:274 - Database schema initialized successfully +2025-02-11 20:16:50 - INFO - discord_bot - start:38 - API manager started +2025-02-11 20:16:50 - INFO - discord_bot - on_ready:172 - Started API health check loop +2025-02-11 20:16:51 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:16:51 - INFO - discord_bot - _process_queue:207 - Queue processor 640ebc33 starting +2025-02-11 20:16:51 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:16:54 - INFO - discord_bot - shutdown:306 - Received SIGINT +2025-02-11 20:16:54 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:16:54 - WARNING - discord_bot - _process_queue:329 - Queue processor 640ebc33 exited - Processed: 1859, Failed: 46 +2025-02-11 20:16:54 - INFO - discord_bot - shutdown:306 - Received SIGTERM +2025-02-11 20:16:54 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:16:54 - INFO - discord_bot - shutdown:46 - API manager shutdown +2025-02-11 20:16:54 - INFO - discord_bot - stop:276 - Stopped API health check loop +2025-02-11 20:16:54 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:16:54 - DEBUG - discord_bot - _close_connection:107 - Database connection closed +2025-02-11 20:16:54 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:16:54 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:16:54 - INFO - discord_bot - run_bot:366 - Bot shutdown complete +2025-02-11 20:19:42 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:19:42 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:19:43 - INFO - discord_bot - validate_config:290 - Vision API Configuration: +Model: meta-llama/llama-3.2-90b-vision-instruct:free +Base URL: https://openrouter.ai/api/v1/chat/completions +Timeout: 30.0 +Max Tokens: 1000 +2025-02-11 20:19:43 - WARNING - discord_bot - validate_config:326 - GLHF API is not fully configured. API features will be disabled. +2025-02-11 20:19:43 - INFO - discord_bot - validate_config:356 - Configuration validated successfully +2025-02-11 20:19:43 - INFO - discord_bot - load_state:40 - Queue state loaded from file - Pending messages: 0 +2025-02-11 20:19:43 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:19:46 - INFO - discord_bot - on_ready:156 - CobraSilver#8886 has connected to Discord! +2025-02-11 20:19:46 - INFO - discord_bot - init_db:184 - Initializing database schema... +2025-02-11 20:19:46 - INFO - discord_bot - _init_connection:96 - Database connection initialized with optimized settings +2025-02-11 20:19:46 - INFO - discord_bot - init_db:201 - Users table created/verified +2025-02-11 20:19:46 - INFO - discord_bot - init_db:216 - Threads table created/verified +2025-02-11 20:19:46 - INFO - discord_bot - init_db:236 - Messages table created/verified +2025-02-11 20:19:46 - INFO - discord_bot - init_db:271 - All indices created/verified +2025-02-11 20:19:46 - INFO - discord_bot - init_db:274 - Database schema initialized successfully +2025-02-11 20:19:46 - INFO - discord_bot - start:38 - API manager started +2025-02-11 20:19:46 - INFO - discord_bot - on_ready:172 - Started API health check loop +2025-02-11 20:19:46 - INFO - discord_bot - shutdown:306 - Received SIGINT +2025-02-11 20:19:46 - INFO - discord_bot - shutdown:306 - Received SIGTERM +2025-02-11 20:19:46 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:19:46 - INFO - discord_bot - shutdown:46 - API manager shutdown +2025-02-11 20:19:46 - INFO - discord_bot - stop:276 - Stopped API health check loop +2025-02-11 20:19:46 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:19:46 - DEBUG - discord_bot - _close_connection:107 - Database connection closed +2025-02-11 20:19:46 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:19:46 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:19:46 - INFO - discord_bot - run_bot:366 - Bot shutdown complete +2025-02-11 20:21:35 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:21:35 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:21:35 - INFO - discord_bot - validate_config:290 - Vision API Configuration: +Model: meta-llama/llama-3.2-90b-vision-instruct:free +Base URL: https://openrouter.ai/api/v1/chat/completions +Timeout: 30.0 +Max Tokens: 1000 +2025-02-11 20:21:35 - WARNING - discord_bot - validate_config:326 - GLHF API is not fully configured. API features will be disabled. +2025-02-11 20:21:35 - INFO - discord_bot - validate_config:356 - Configuration validated successfully +2025-02-11 20:21:35 - INFO - discord_bot - load_state:40 - Queue state loaded from file - Pending messages: 0 +2025-02-11 20:21:35 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:21:38 - INFO - discord_bot - on_ready:156 - CobraSilver#8886 has connected to Discord! +2025-02-11 20:21:38 - INFO - discord_bot - init_db:184 - Initializing database schema... +2025-02-11 20:21:38 - INFO - discord_bot - _init_connection:96 - Database connection initialized with optimized settings +2025-02-11 20:21:38 - INFO - discord_bot - init_db:201 - Users table created/verified +2025-02-11 20:21:38 - INFO - discord_bot - init_db:216 - Threads table created/verified +2025-02-11 20:21:38 - INFO - discord_bot - init_db:236 - Messages table created/verified +2025-02-11 20:21:38 - INFO - discord_bot - init_db:271 - All indices created/verified +2025-02-11 20:21:38 - INFO - discord_bot - init_db:274 - Database schema initialized successfully +2025-02-11 20:21:38 - INFO - discord_bot - start:38 - API manager started +2025-02-11 20:21:38 - INFO - discord_bot - on_ready:172 - Started API health check loop +2025-02-11 20:21:38 - INFO - discord_bot - shutdown:306 - Received SIGINT +2025-02-11 20:21:38 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:21:38 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:21:38 - INFO - discord_bot - shutdown:46 - API manager shutdown +2025-02-11 20:21:38 - INFO - discord_bot - stop:276 - Stopped API health check loop +2025-02-11 20:21:38 - INFO - discord_bot - shutdown:306 - Received SIGTERM +2025-02-11 20:21:38 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:21:38 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:21:38 - INFO - discord_bot - run_bot:366 - Bot shutdown complete +2025-02-11 20:22:23 - ERROR - asyncio - default_exception_handler:1864 - Task was destroyed but it is pending! +task: wait_for=<_GatheringFuture finished result=[CancelledError(''), CancelledError('')]>> +2025-02-11 20:23:19 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:23:19 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:23:19 - INFO - discord_bot - validate_config:290 - Vision API Configuration: +Model: meta-llama/llama-3.2-90b-vision-instruct:free +Base URL: https://openrouter.ai/api/v1/chat/completions +Timeout: 30.0 +Max Tokens: 1000 +2025-02-11 20:23:19 - WARNING - discord_bot - validate_config:326 - GLHF API is not fully configured. API features will be disabled. +2025-02-11 20:23:19 - INFO - discord_bot - validate_config:356 - Configuration validated successfully +2025-02-11 20:23:19 - INFO - discord_bot - load_state:40 - Queue state loaded from file - Pending messages: 0 +2025-02-11 20:23:19 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:23:22 - INFO - discord_bot - on_ready:156 - CobraSilver#8886 has connected to Discord! +2025-02-11 20:23:22 - INFO - discord_bot - init_db:184 - Initializing database schema... +2025-02-11 20:23:22 - INFO - discord_bot - _init_connection:96 - Database connection initialized with optimized settings +2025-02-11 20:23:22 - INFO - discord_bot - init_db:201 - Users table created/verified +2025-02-11 20:23:22 - INFO - discord_bot - init_db:216 - Threads table created/verified +2025-02-11 20:23:22 - INFO - discord_bot - init_db:236 - Messages table created/verified +2025-02-11 20:23:22 - INFO - discord_bot - init_db:271 - All indices created/verified +2025-02-11 20:23:22 - INFO - discord_bot - init_db:274 - Database schema initialized successfully +2025-02-11 20:23:22 - INFO - discord_bot - start:38 - API manager started +2025-02-11 20:23:22 - INFO - discord_bot - on_ready:172 - Started API health check loop +2025-02-11 20:23:23 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:23:23 - INFO - discord_bot - _process_queue:207 - Queue processor 9e0b5f34 starting +2025-02-11 20:23:23 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:24:23 - INFO - discord_bot - _process_queue:295 - Queue processor 9e0b5f34 heartbeat - Active: True, Queue size: 0, Processing: 0, Total processed: 1859 +2025-02-11 20:24:23 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:24:27 - INFO - discord_bot - shutdown:306 - Received SIGINT +2025-02-11 20:24:27 - DEBUG - discord_bot - save_state:62 - Queue state saved - Pending messages: 0 +2025-02-11 20:24:27 - WARNING - discord_bot - _process_queue:329 - Queue processor 9e0b5f34 exited - Processed: 1859, Failed: 46 +2025-02-11 20:24:27 - INFO - discord_bot - shutdown:306 - Received SIGTERM +2025-02-11 20:24:27 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:24:27 - INFO - discord_bot - shutdown:46 - API manager shutdown +2025-02-11 20:24:27 - INFO - discord_bot - stop:276 - Stopped API health check loop +2025-02-11 20:24:27 - INFO - discord_bot - stop:254 - Initiating shutdown... +2025-02-11 20:24:27 - DEBUG - discord_bot - _close_connection:107 - Database connection closed +2025-02-11 20:24:27 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:24:27 - INFO - discord_bot - stop:299 - Shutdown complete +2025-02-11 20:24:27 - INFO - discord_bot - run_bot:366 - Bot shutdown complete diff --git a/discord_glhf/bot.py b/discord_glhf/bot.py index 5915aab..8823356 100644 --- a/discord_glhf/bot.py +++ b/discord_glhf/bot.py @@ -192,11 +192,10 @@ class DiscordBot: await internal_site.start() logger.info("Internal API server started") - # Start HTTP server for backend prompts - http_port = int(os.getenv('WEB_PORT', '8080')) - self.http_server = HTTPServer(self.event_handler) - await self.http_server.start(port=http_port) - logger.info(f"Web server started on port {http_port}") + # Initialize and start web interface + from discord_glhf.web.app import init_app + self.web_app = init_app(self.event_handler) + logger.info("Web interface initialized with event handler") # Set bot status activity = Game(name="with roller coasters") diff --git a/discord_glhf/discord_bot.log b/discord_glhf/discord_bot.log new file mode 100644 index 0000000..d947ec3 --- /dev/null +++ b/discord_glhf/discord_bot.log @@ -0,0 +1,4 @@ +2025-02-11 20:23:21 - INFO - discord_bot - :211 - Using database path: conversation_history.db +2025-02-11 20:23:21 - INFO - discord_bot - load_responses:250 - Loaded responses from file +2025-02-11 20:23:21 - DEBUG - asyncio - __init__:64 - Using selector: KqueueSelector +2025-02-11 20:23:21 - INFO - hypercorn.error - info:106 - Running on http://0.0.0.0:8080 (CTRL + C to quit) diff --git a/discord_glhf/handlers/__pycache__/event_handler.cpython-313.pyc b/discord_glhf/handlers/__pycache__/event_handler.cpython-313.pyc index 288f2cc..c96c0f0 100644 Binary files a/discord_glhf/handlers/__pycache__/event_handler.cpython-313.pyc and b/discord_glhf/handlers/__pycache__/event_handler.cpython-313.pyc differ diff --git a/discord_glhf/handlers/event_handler.py b/discord_glhf/handlers/event_handler.py index 9dd54cd..48aceaa 100644 --- a/discord_glhf/handlers/event_handler.py +++ b/discord_glhf/handlers/event_handler.py @@ -44,6 +44,69 @@ class EventHandler: # Replace all mention formats with the proper mention return re.sub(pattern, mention, response) + async def send_prompt_to_channel(self, prompt: str, channel_id: int) -> None: + """Send a prompt to the specified channel.""" + try: + channel = self.bot.get_channel(channel_id) + if not channel: + logger.error(f"Could not find channel {channel_id}") + return + + # Build context for the API call + messages = [ + { + "role": "system", + "content": SYSTEM_PROMPT, + "metadata": { + "bot_owner_id": str(BOT_OWNER_ID), + "current_user": { + "user_id": "0" # System user + } + } + }, + { + "role": "user", + "content": prompt, + "context": { + "timeout_env": "GLHF_TIMEOUT" + } + } + ] + + # Get response from API + response = await self.api_manager.get_completion(messages) + if not response: + logger.error("No response received from API") + return + + # Parse tool calls and get processed response + tool_calls, final_response, mentioned_users = self.tool_handler.parse_tool_calls( + response, channel_id=channel_id + ) + + # Execute tool calls + for tool_name, args in tool_calls: + try: + if tool_name == "create_embed": + await self.tool_handler.create_embed( + channel=channel, content=args["content"] + ) + elif tool_name == "create_thread": + await self.tool_handler.create_thread( + channel.id, args["name"] + ) + except Exception as e: + logger.error(f"Error executing tool {tool_name}: {e}") + + # Send the response + if final_response: + logger.info(f"Bot response to prompt: {final_response}") + await self.message_handler.safe_send(channel, final_response) + + except Exception as e: + logger.error(f"Error processing prompt: {e}") + raise + async def handle_reaction(self, payload: RawReactionActionEvent) -> None: """Handle reaction events on bot messages.""" # Ignore our own reactions diff --git a/discord_glhf/start.sh b/discord_glhf/start.sh index a5bce32..03bc901 100755 --- a/discord_glhf/start.sh +++ b/discord_glhf/start.sh @@ -4,7 +4,11 @@ # Function to stop background processes on exit cleanup() { echo "Stopping processes..." + if [ ! -z "$WEB_PID" ]; then + kill $WEB_PID 2>/dev/null + fi kill $(jobs -p) 2>/dev/null + wait exit } @@ -25,7 +29,11 @@ sleep 2 # Start the web interface echo "Starting web interface on port ${WEB_PORT}..." cd $(dirname "$0") -PYTHONPATH=/Volumes/macminissd/Projects/discord_glhf /Users/talor/Projects/discord_glhf/.venv/bin/python3 web/app.py +# Run web interface with proper Python path and virtualenv +PYTHONPATH=/Volumes/macminissd/Projects/discord_glhf /Users/talor/Projects/discord_glhf/.venv/bin/python3 web/app.py & +WEB_PID=$! +# Wait a moment for web interface to start +sleep 2 # This will be caught by the trap wait \ No newline at end of file diff --git a/discord_glhf/web/app.py b/discord_glhf/web/app.py index 609763b..c34807b 100644 --- a/discord_glhf/web/app.py +++ b/discord_glhf/web/app.py @@ -1,55 +1,71 @@ #!/usr/bin/env python3 """Web interface for sending prompts to the Discord bot.""" -from flask import Flask, render_template, request, jsonify -import requests +from quart import Quart, render_template, request, jsonify import os from pathlib import Path -app = Flask(__name__) -app.template_folder = str(Path(__file__).parent / 'templates') +def async_route(f): + @wraps(f) + def wrapped(*args, **kwargs): + return asyncio.run(f(*args, **kwargs)) + return wrapped -# Get configuration from environment variables -API_PORT = int(os.getenv('HTTP_PORT', '8000')) -BACKEND_API_KEY = os.getenv('BACKEND_API_KEY') +from discord_glhf.config import AUTO_RESPONSE_CHANNEL_ID + +app = Quart(__name__) +app.template_folder = str(Path(__file__).parent / 'templates') +event_handler = None + +def init_app(bot_event_handler): + """Initialize the app with the bot's event handler.""" + global event_handler + event_handler = bot_event_handler + return app @app.route('/') -def index(): +async def index(): """Render the main interface.""" - return render_template('index.html') + return await render_template('index.html') @app.route('/api/prompt', methods=['POST']) -def send_prompt(): +async def send_prompt(): """Handle prompt submission.""" try: + if not event_handler: + return jsonify({'error': 'Bot not initialized'}), 503 + data = request.get_json() if not data or 'prompt' not in data: return jsonify({'error': 'Missing prompt'}), 400 - # Forward the request to the bot's HTTP server - headers = {'Content-Type': 'application/json'} - if BACKEND_API_KEY: - headers['X-API-Key'] = BACKEND_API_KEY - - response = requests.post( - 'http://127.0.0.1:8000/api/prompt', # Use fixed internal API port - json=data, - headers=headers - ) - - return response.json(), response.status_code + channel_id = data.get('channel_id', AUTO_RESPONSE_CHANNEL_ID) + await event_handler.send_prompt_to_channel(data['prompt'], channel_id) + return jsonify({'status': 'processing'}), 200 except Exception as e: return jsonify({'error': str(e)}), 500 def run_webserver(port=5000): """Run the web server.""" - app.run(host='0.0.0.0', port=port, debug=True) + import hypercorn.asyncio + from hypercorn.config import Config -def run(): - """Run the web server.""" - port = int(os.getenv('WEB_PORT', '5000')) - app.run(host='0.0.0.0', port=port) + config = Config() + config.bind = [f"0.0.0.0:{port}"] + config.use_reloader = True -if __name__ == '__main__': - run() \ No newline at end of file + import asyncio + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + loop.run_until_complete(hypercorn.asyncio.serve(app, config)) + except KeyboardInterrupt: + pass + finally: + loop.close() + +if __name__ == "__main__": + from discord_glhf.config import AUTO_RESPONSE_CHANNEL_ID + port = int(os.getenv('WEB_PORT', '8080')) + run_webserver(port) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 26fadf4..9289287 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ dependencies = [ "promptic>=2.3.1", "python-dotenv>=1.0.1", "pyyaml>=6.0.2", + "quart>=0.20.0", "requests>=2.32.3", "tenacity>=9.0.0", "termcolor>=2.5.0", diff --git a/queue_state.json b/queue_state.json index 823ba3b..e1d79dc 100644 --- a/queue_state.json +++ b/queue_state.json @@ -1,9 +1,9 @@ { "total_processed": 1859, "failed_messages": 46, - "last_processed_time": 1739322639.0875552, + "last_processed_time": 1739323467.1755688, "user_queues": {}, - "last_save": 1739322639.087557, + "last_save": 1739323467.1755688, "processor_id": null, "active": false, "pending_messages": [], diff --git a/uv.lock b/uv.lock index 75e6ede..8e15ece 100644 --- a/uv.lock +++ b/uv.lock @@ -10,6 +10,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/fa/ea/23e756ec1fea0c685149304dda954b3b3932d6d06afbf42a66a2e6dc2184/aioconsole-0.8.1-py3-none-any.whl", hash = "sha256:e1023685cde35dde909fbf00631ffb2ed1c67fe0b7058ebb0892afbde5f213e5", size = 43324 }, ] +[[package]] +name = "aiofiles" +version = "24.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0b/03/a88171e277e8caa88a4c77808c20ebb04ba74cc4681bf1e9416c862de237/aiofiles-24.1.0.tar.gz", hash = "sha256:22a075c9e5a3810f0c2e48f3008c94d68c65d763b9b03857924c99e57355166c", size = 30247 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a5/45/30bb92d442636f570cb5651bc661f52b610e2eec3f891a5dc3a4c3667db0/aiofiles-24.1.0-py3-none-any.whl", hash = "sha256:b4ec55f4195e3eb5d7abd1bf7e061763e864dd4954231fb8539a0ef8bb8260e5", size = 15896 }, +] + [[package]] name = "aiohappyeyeballs" version = "2.4.4" @@ -299,6 +308,7 @@ dependencies = [ { name = "promptic" }, { name = "python-dotenv" }, { name = "pyyaml" }, + { name = "quart" }, { name = "requests" }, { name = "tenacity" }, { name = "termcolor" }, @@ -321,6 +331,7 @@ requires-dist = [ { name = "promptic", specifier = ">=2.3.1" }, { name = "python-dotenv", specifier = ">=1.0.1" }, { name = "pyyaml", specifier = ">=6.0.2" }, + { name = "quart", specifier = ">=0.20.0" }, { name = "requests", specifier = ">=2.32.3" }, { name = "tenacity", specifier = ">=9.0.0" }, { name = "termcolor", specifier = ">=2.5.0" }, @@ -423,6 +434,28 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/95/04/ff642e65ad6b90db43e668d70ffb6736436c7ce41fcc549f4e9472234127/h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761", size = 58259 }, ] +[[package]] +name = "h2" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "hpack" }, + { name = "hyperframe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/1b/38/d7f80fd13e6582fb8e0df8c9a653dcc02b03ca34f4d72f34869298c5baf8/h2-4.2.0.tar.gz", hash = "sha256:c8a52129695e88b1a0578d8d2cc6842bbd79128ac685463b887ee278126ad01f", size = 2150682 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d0/9e/984486f2d0a0bd2b024bf4bc1c62688fcafa9e61991f041fb0e2def4a982/h2-4.2.0-py3-none-any.whl", hash = "sha256:479a53ad425bb29af087f3458a61d30780bc818e4ebcf01f0b536ba916462ed0", size = 60957 }, +] + +[[package]] +name = "hpack" +version = "4.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/2c/48/71de9ed269fdae9c8057e5a4c0aa7402e8bb16f2c6e90b3aa53327b113f8/hpack-4.1.0.tar.gz", hash = "sha256:ec5eca154f7056aa06f196a557655c5b009b382873ac8d1e66e79e87535f1dca", size = 51276 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/07/c6/80c95b1b2b94682a72cbdbfb85b81ae2daffa4291fbfa1b1464502ede10d/hpack-4.1.0-py3-none-any.whl", hash = "sha256:157ac792668d995c657d93111f46b4535ed114f0c9c8d672271bbec7eae1b496", size = 34357 }, +] + [[package]] name = "httpcore" version = "1.0.7" @@ -469,6 +502,30 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/61/8c/fbdc0a88a622d9fa54e132d7bf3ee03ec602758658a2db5b339a65be2cfe/huggingface_hub-0.27.0-py3-none-any.whl", hash = "sha256:8f2e834517f1f1ddf1ecc716f91b120d7333011b7485f665a9a412eacb1a2a81", size = 450537 }, ] +[[package]] +name = "hypercorn" +version = "0.17.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h11" }, + { name = "h2" }, + { name = "priority" }, + { name = "wsproto" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/7e/3a/df6c27642e0dcb7aff688ca4be982f0fb5d89f2afd3096dc75347c16140f/hypercorn-0.17.3.tar.gz", hash = "sha256:1b37802ee3ac52d2d85270700d565787ab16cf19e1462ccfa9f089ca17574165", size = 44409 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0e/3b/dfa13a8d96aa24e40ea74a975a9906cfdc2ab2f4e3b498862a57052f04eb/hypercorn-0.17.3-py3-none-any.whl", hash = "sha256:059215dec34537f9d40a69258d323f56344805efb462959e727152b0aa504547", size = 61742 }, +] + +[[package]] +name = "hyperframe" +version = "6.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/02/e7/94f8232d4a74cc99514c13a9f995811485a6903d48e5d952771ef6322e30/hyperframe-6.1.0.tar.gz", hash = "sha256:f630908a00854a7adeabd6382b43923a4c4cd4b821fcb527e6ab9e15382a3b08", size = 26566 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/48/30/47d0bf6072f7252e6521f3447ccfa40b421b6824517f82854703d0f5a98b/hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5", size = 13007 }, +] + [[package]] name = "idna" version = "3.10" @@ -776,6 +833,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9e/c3/059298687310d527a58bb01f3b1965787ee3b40dce76752eda8b44e9a2c5/pexpect-4.9.0-py2.py3-none-any.whl", hash = "sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523", size = 63772 }, ] +[[package]] +name = "priority" +version = "2.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f5/3c/eb7c35f4dcede96fca1842dac5f4f5d15511aa4b52f3a961219e68ae9204/priority-2.0.0.tar.gz", hash = "sha256:c965d54f1b8d0d0b19479db3924c7c36cf672dbf2aec92d43fbdaf4492ba18c0", size = 24792 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5e/5f/82c8074f7e84978129347c2c6ec8b6c59f3584ff1a20bc3c940a3e061790/priority-2.0.0-py3-none-any.whl", hash = "sha256:6f8eefce5f3ad59baf2c080a664037bb4725cd0a790d53d59ab4059288faf6aa", size = 8946 }, +] + [[package]] name = "prompt-toolkit" version = "3.0.48" @@ -919,6 +985,26 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", size = 156446 }, ] +[[package]] +name = "quart" +version = "0.20.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "aiofiles" }, + { name = "blinker" }, + { name = "click" }, + { name = "flask" }, + { name = "hypercorn" }, + { name = "itsdangerous" }, + { name = "jinja2" }, + { name = "markupsafe" }, + { name = "werkzeug" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/1d/9d/12e1143a5bd2ccc05c293a6f5ae1df8fd94a8fc1440ecc6c344b2b30ce13/quart-0.20.0.tar.gz", hash = "sha256:08793c206ff832483586f5ae47018c7e40bdd75d886fee3fabbdaa70c2cf505d", size = 63874 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/e9/cc28f21f52913adf333f653b9e0a3bf9cb223f5083a26422968ba73edd8d/quart-0.20.0-py3-none-any.whl", hash = "sha256:003c08f551746710acb757de49d9b768986fd431517d0eb127380b656b98b8f1", size = 77960 }, +] + [[package]] name = "referencing" version = "0.35.1" @@ -1184,6 +1270,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl", hash = "sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e", size = 224498 }, ] +[[package]] +name = "wsproto" +version = "1.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065", size = 53425 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226 }, +] + [[package]] name = "yarl" version = "1.18.3"