first commit
This commit is contained in:
BIN
bot/commands/__pycache__/example.cpython-312.pyc
Normal file
BIN
bot/commands/__pycache__/example.cpython-312.pyc
Normal file
Binary file not shown.
63
bot/commands/example.py
Normal file
63
bot/commands/example.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
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)
|
||||
30
bot/commands/medications.py
Normal file
30
bot/commands/medications.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Medications command handler - bot-side hooks for medication management
|
||||
"""
|
||||
|
||||
from bot.command_registry import register_module
|
||||
import ai.parser as ai_parser
|
||||
|
||||
|
||||
async def handle_medication(message, session, parsed):
|
||||
action = parsed.get("action", "unknown")
|
||||
token = session["token"]
|
||||
user_uuid = session["user_uuid"]
|
||||
|
||||
# TODO: wire up API calls per action
|
||||
pass
|
||||
|
||||
|
||||
def validate_medication_json(data):
|
||||
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")
|
||||
return errors
|
||||
|
||||
|
||||
register_module("medication", handle_medication)
|
||||
ai_parser.register_validator("medication", validate_medication_json)
|
||||
30
bot/commands/routines.py
Normal file
30
bot/commands/routines.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Routines command handler - bot-side hooks for routine management
|
||||
"""
|
||||
|
||||
from bot.command_registry import register_module
|
||||
import ai.parser as ai_parser
|
||||
|
||||
|
||||
async def handle_routine(message, session, parsed):
|
||||
action = parsed.get("action", "unknown")
|
||||
token = session["token"]
|
||||
user_uuid = session["user_uuid"]
|
||||
|
||||
# TODO: wire up API calls per action
|
||||
pass
|
||||
|
||||
|
||||
def validate_routine_json(data):
|
||||
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")
|
||||
return errors
|
||||
|
||||
|
||||
register_module("routine", handle_routine)
|
||||
ai_parser.register_validator("routine", validate_routine_json)
|
||||
Reference in New Issue
Block a user