refactor(pairing): move /pairing from BaseChannel to CommandRouter
/pairing is now a first-class built-in command dispatched through CommandRouter, just like /status, /model, /dream, etc. Benefits: - WebUI automatically shows /pairing in the slash command palette (because builtin_command_palette() feeds /api/commands). - All channels (Telegram, Discord, WebSocket, etc.) use the same dispatch path for /pairing; no more channel-level interception. - The command still only works for already-authorised users because is_allowed() gates message ingestion before the bus. Changes: - Add handle_pairing_command() to nanobot.pairing.store — pure function callable from CLI, CommandRouter, and tests. - Add cmd_pairing to nanobot.command.builtin and register in BUILTIN_COMMAND_SPECS + register_builtin_commands(). - Remove BaseChannel._handle_pairing_command() and the /pairing interception logic from _handle_message(). - Clean up unused pairing imports from base.py. - Add unit tests for handle_pairing_command and cmd_pairing dispatch.
This commit is contained in:
@@ -96,6 +96,13 @@ BUILTIN_COMMAND_SPECS: tuple[BuiltinCommandSpec, ...] = (
|
||||
"List available slash commands.",
|
||||
"circle-help",
|
||||
),
|
||||
BuiltinCommandSpec(
|
||||
"/pairing",
|
||||
"Manage pairing",
|
||||
"List, approve, deny or revoke pairing requests.",
|
||||
"shield",
|
||||
"[list|approve <code>|deny <code>|revoke <user_id>]",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -539,6 +546,19 @@ async def cmd_history(ctx: CommandContext) -> OutboundMessage:
|
||||
)
|
||||
|
||||
|
||||
async def cmd_pairing(ctx: CommandContext) -> OutboundMessage:
|
||||
"""List, approve, deny or revoke pairing requests."""
|
||||
from nanobot.pairing import handle_pairing_command
|
||||
|
||||
reply = handle_pairing_command(ctx.msg.channel, ctx.args)
|
||||
return OutboundMessage(
|
||||
channel=ctx.msg.channel,
|
||||
chat_id=ctx.msg.chat_id,
|
||||
content=reply,
|
||||
metadata={"_pairing_command": True},
|
||||
)
|
||||
|
||||
|
||||
async def cmd_help(ctx: CommandContext) -> OutboundMessage:
|
||||
"""Return available slash commands."""
|
||||
return OutboundMessage(
|
||||
@@ -577,3 +597,5 @@ def register_builtin_commands(router: CommandRouter) -> None:
|
||||
router.exact("/dream-restore", cmd_dream_restore)
|
||||
router.prefix("/dream-restore ", cmd_dream_restore)
|
||||
router.exact("/help", cmd_help)
|
||||
router.exact("/pairing", cmd_pairing)
|
||||
router.prefix("/pairing ", cmd_pairing)
|
||||
|
||||
Reference in New Issue
Block a user