- Fix bare imports in core/ modules to use fully-qualified paths (core.users, core.postgres) - Fix scheduler/daemon.py importing os before use - Fix verifyLoginToken returning truthy 401 on failure (security: invalid tokens were passing auth checks) - Fix api/routes/example.py passing literal True as userUUID instead of decoded JWT sub - Switch all services to python -m invocation so /app is always on sys.path - Remove orphaned sys.path.insert hacks from bot.py, commands/example.py, routes/example.py - Change API port mapping from 5000 to 8080 - Add config/.env and root .env for docker-compose variable substitution Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
"""
|
|
Example command module - Copy this pattern for your domain.
|
|
|
|
This module demonstrates:
|
|
1. Registering a handler with the command registry
|
|
2. Using the AI parser with custom prompts
|
|
3. Making API calls
|
|
"""
|
|
|
|
from bot.command_registry import register_module
|
|
import ai.parser as ai_parser
|
|
|
|
|
|
async def handle_example(message, session, parsed):
|
|
"""
|
|
Handler for 'example' interaction type.
|
|
|
|
Args:
|
|
message: Discord message object
|
|
session: {token, user_uuid, username}
|
|
parsed: Parsed JSON from AI parser
|
|
"""
|
|
action = parsed.get("action", "unknown")
|
|
token = session["token"]
|
|
user_uuid = session["user_uuid"]
|
|
|
|
if action == "check":
|
|
await message.channel.send(
|
|
f"Checking example items for {session['username']}..."
|
|
)
|
|
elif action == "add":
|
|
item_name = parsed.get("item_name", "unnamed")
|
|
await message.channel.send(f"Adding example item: **{item_name}**")
|
|
else:
|
|
await message.channel.send(f"Unknown example action: {action}")
|
|
|
|
|
|
def validate_example_json(data):
|
|
"""Validate parsed JSON for example commands. Return list of errors."""
|
|
errors = []
|
|
|
|
if not isinstance(data, dict):
|
|
return ["Response must be a JSON object"]
|
|
|
|
if "error" in data:
|
|
return []
|
|
|
|
if "action" not in data:
|
|
errors.append("Missing required field: action")
|
|
|
|
action = data.get("action")
|
|
|
|
if action == "add" and "item_name" not in data:
|
|
errors.append("Missing required field for add: item_name")
|
|
|
|
return errors
|
|
|
|
|
|
# Register the module
|
|
register_module("example", handle_example)
|
|
|
|
# Register the validator
|
|
ai_parser.register_validator("example", validate_example_json)
|