-
Notifications
You must be signed in to change notification settings - Fork 0
Investigate monitoring loop and improve development infrastructure #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
272ffdf
f569241
9f7ff72
43da7d4
6f9f46a
aaafe92
a4a2931
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Console Interface Limited Commands | ||
|
|
||
| **Priority**: 2 **Type**: bug **Status**: open **Created**: 2025-07-05 | ||
| **Updated**: 2025-07-05 | ||
|
|
||
| ## Description | ||
|
|
||
| The local development console interface only supports a subset of Discord bot | ||
| commands due to hardcoded command mapping instead of using Discord.py's command | ||
| processing system. | ||
|
|
||
| ## Reproduction Steps | ||
|
|
||
| 1. Start local development: `python local_dev.py` | ||
| 2. Try commands like `!poll_rate 5` or `!help` | ||
| 3. Observe "Unknown command" errors | ||
| 4. Only `!add`, `!list`, `!check`, `!remove` work partially | ||
|
|
||
| ## Expected vs Actual Behavior | ||
|
|
||
| - **Expected**: All Discord bot commands should work in console interface | ||
| - **Actual**: Only 5 commands are hardcoded and mapped, others fail with | ||
| "Unknown command" | ||
|
|
||
| ## Technical Details | ||
|
|
||
| ### Root Cause | ||
|
|
||
| The console interface in `src/local_dev/console_discord.py` has an architecture | ||
| mismatch: | ||
|
|
||
| 1. **Hardcoded command mapping**: Only these commands are manually mapped: | ||
|
|
||
| ```python | ||
| if command.startswith("!add"): | ||
| await self.command_handler.add_location(fake_message, *command.split()[1:]) | ||
| elif command.startswith("!list"): | ||
| await self.command_handler.list_targets(fake_message) | ||
| # etc... | ||
| ``` | ||
|
|
||
| 2. **Bypasses Discord.py framework**: Should use `bot.process_commands()` | ||
| instead | ||
| 3. **Method name mismatches**: Calls `show_help()` but real method is | ||
| `help_command()` | ||
|
|
||
| ### Missing Commands | ||
|
|
||
| - `!poll_rate` - Set polling frequency | ||
| - `!notifications` - Configure notification types | ||
| - `!export` - Export configuration | ||
| - `!monitor_health` - Show monitoring health | ||
| - All other commands in `src/cogs/command_handler.py` | ||
|
|
||
| ### Current Error Examples | ||
|
|
||
| ``` | ||
| [CONSOLE] ERROR - ❌ Error processing command '!help': 'CommandHandler' object has no attribute 'show_help' | ||
| [CONSOLE] INFO - [BOT] ❓ Unknown command. Available: !add, !list, !check, !remove, !help | ||
| ``` | ||
|
|
||
| ## Proposed Solution | ||
|
|
||
| ### Option 1: Use Discord.py Command Processing (Recommended) | ||
|
|
||
| Refactor console interface to use `bot.process_commands()`: | ||
|
|
||
| ```python | ||
| async def _process_bot_command(self, command: str): | ||
| """Process command through Discord.py's command system""" | ||
| try: | ||
| # Create proper fake message object | ||
| fake_message = FakeMessage(command) | ||
| fake_message.author = FakeUser() | ||
| fake_message.channel = FakeChannel() | ||
| fake_message.guild = FakeGuild() | ||
|
|
||
| # Process through Discord.py command system | ||
| await self.bot.process_commands(fake_message) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"❌ Error processing command '{command}': {e}") | ||
| ``` | ||
|
|
||
| ### Option 2: Auto-generate Command Mapping | ||
|
|
||
| Dynamically discover and map all commands from loaded cogs: | ||
|
|
||
| ```python | ||
| def _build_command_mapping(self): | ||
| """Build command mapping from all loaded cogs""" | ||
| self.command_mapping = {} | ||
| for cog_name, cog in self.bot.cogs.items(): | ||
| for command in cog.get_commands(): | ||
| self.command_mapping[command.name] = command | ||
| ``` | ||
|
|
||
| ## Acceptance Criteria | ||
|
|
||
| - [ ] All Discord bot commands work in console interface | ||
| - [ ] No hardcoded command mapping required | ||
| - [ ] Error handling consistent with Discord bot | ||
| - [ ] Special console commands (`.quit`, `.status`, etc.) still work | ||
| - [ ] Proper fake Discord context objects provided | ||
|
|
||
| ## Impact | ||
|
|
||
| - **Development workflow**: Limited testing capabilities for configuration | ||
| commands | ||
| - **Debugging**: Cannot test poll rate changes, notification settings via | ||
| console | ||
| - **User experience**: Confusing that documented commands don't work | ||
|
|
||
| ## Notes | ||
|
|
||
| - Monitoring loop itself works correctly - this is only a console interface | ||
| issue | ||
| - Commands work fine in actual Discord environment | ||
| - Console interface was designed for basic testing, needs expansion for full | ||
| functionality | ||
|
|
||
| ## Related Files | ||
|
|
||
| - `src/local_dev/console_discord.py` - Main console interface | ||
| - `src/cogs/command_handler.py` - All Discord commands | ||
| - `docs/LOCAL_DEVELOPMENT.md` - Documentation of console commands |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,15 @@ | |||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| if __name__ == "__main__": | ||||||||||||
| import asyncio | ||||||||||||
| from src.local_dev.local_dev import main | ||||||||||||
|
|
||||||||||||
| main() | ||||||||||||
| try: | ||||||||||||
| asyncio.run(main()) | ||||||||||||
| except KeyboardInterrupt: | ||||||||||||
| print("\n👋 Goodbye!") | ||||||||||||
| except Exception as e: | ||||||||||||
| print(f"❌ Fatal error: {e}") | ||||||||||||
|
Comment on lines
+20
to
+21
|
||||||||||||
| except Exception as e: | |
| print(f"❌ Fatal error: {e}") | |
| except Exception: | |
| import traceback | |
| traceback.print_exc() |
Copilot
AI
Jul 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing sys inside the exception block is unconventional; move this import to the top of the file to comply with standard import practices.
| import sys |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||
| # Script to send commands to the local development bot | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Parse arguments | ||||||||||||||||||||||||||||||
| AUTO_START=true | ||||||||||||||||||||||||||||||
| COMMAND="" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| while [[ $# -gt 0 ]]; do | ||||||||||||||||||||||||||||||
| case $1 in | ||||||||||||||||||||||||||||||
| --no-auto-start) | ||||||||||||||||||||||||||||||
| AUTO_START=false | ||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||
| *) | ||||||||||||||||||||||||||||||
| COMMAND="$1" | ||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if [ -z "$COMMAND" ]; then | ||||||||||||||||||||||||||||||
| echo "Usage: ./send_command.sh [--no-auto-start] <command>" | ||||||||||||||||||||||||||||||
| echo "Examples:" | ||||||||||||||||||||||||||||||
| echo " ./send_command.sh '!list'" | ||||||||||||||||||||||||||||||
| echo " ./send_command.sh '.status'" | ||||||||||||||||||||||||||||||
| echo " ./send_command.sh '.trigger'" | ||||||||||||||||||||||||||||||
| echo " ./send_command.sh '!check'" | ||||||||||||||||||||||||||||||
| echo " ./send_command.sh --no-auto-start '!list' # Don't start bot automatically" | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+28
|
||||||||||||||||||||||||||||||
| echo "Usage: ./send_command.sh [--no-auto-start] <command>" | |
| echo "Examples:" | |
| echo " ./send_command.sh '!list'" | |
| echo " ./send_command.sh '.status'" | |
| echo " ./send_command.sh '.trigger'" | |
| echo " ./send_command.sh '!check'" | |
| echo " ./send_command.sh --no-auto-start '!list' # Don't start bot automatically" | |
| echo "Usage: $(basename "$0") [--no-auto-start] <command>" | |
| echo "Examples:" | |
| echo " $(basename "$0") '!list'" | |
| echo " $(basename "$0") '.status'" | |
| echo " $(basename "$0") '.trigger'" | |
| echo " $(basename "$0") '!check'" | |
| echo " $(basename "$0") --no-auto-start '!list' # Don't start bot automatically" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving
import asyncio(and thefrom src.local_dev.local_dev import main) to the top of the file so that all imports are grouped at module level for consistency.