``/buddy`` command body. Parsing precedence (matches TS ``buddy.tsx:104-184``): 1. ``help`` / ``-h`` / ``--help`` → help text 2. ``status`` or any ``COMMON_INFO_ARGS`` entry (incl. ``?``) → status 3. ``mute`` / ``unmute`` → toggle + confirmation 4. any other non-empty arg → hel
(args: str, context: CommandContext)
| 85 | |
| 86 | |
| 87 | def buddy_command_call(args: str, context: CommandContext) -> LocalCommandResult: |
| 88 | """``/buddy`` command body. |
| 89 | |
| 90 | Parsing precedence (matches TS ``buddy.tsx:104-184``): |
| 91 | |
| 92 | 1. ``help`` / ``-h`` / ``--help`` → help text |
| 93 | 2. ``status`` or any ``COMMON_INFO_ARGS`` entry (incl. ``?``) → status |
| 94 | 3. ``mute`` / ``unmute`` → toggle + confirmation |
| 95 | 4. any other non-empty arg → help text |
| 96 | 5. empty arg + no companion → hatch |
| 97 | 6. empty arg + companion exists → pet |
| 98 | """ |
| 99 | arg = (args or '').strip().lower() |
| 100 | |
| 101 | # Note: TS routes '?' to INFO (status), NOT HELP — preserve that mapping. |
| 102 | if arg in COMMON_HELP_ARGS: |
| 103 | return LocalCommandResult(type='text', value=_HELP_TEXT) |
| 104 | |
| 105 | if arg in COMMON_INFO_ARGS: |
| 106 | companion = get_companion() |
| 107 | if companion is None: |
| 108 | return LocalCommandResult( |
| 109 | type='text', |
| 110 | value='No buddy hatched yet. Run /buddy to hatch one.', |
| 111 | ) |
| 112 | return LocalCommandResult( |
| 113 | type='text', |
| 114 | value=( |
| 115 | f"{companion.name} is your {_title_case(companion.rarity)} " |
| 116 | f"{companion.species}. {companion.personality}" |
| 117 | ), |
| 118 | ) |
| 119 | |
| 120 | if arg in ('mute', 'unmute'): |
| 121 | muted = arg == 'mute' |
| 122 | _set_companion_muted(muted) |
| 123 | return LocalCommandResult( |
| 124 | type='text', |
| 125 | value=f"Buddy {'muted' if muted else 'unmuted'}.", |
| 126 | ) |
| 127 | |
| 128 | if arg != '': |
| 129 | return LocalCommandResult(type='text', value=_HELP_TEXT) |
| 130 | |
| 131 | # Empty arg: hatch (first time) or pet (subsequent). |
| 132 | companion = get_companion() |
| 133 | if companion is None: |
| 134 | user_id = companion_user_id() |
| 135 | stored = create_stored_companion(user_id) |
| 136 | _save_companion(stored) |
| 137 | # Re-read with fresh bones merged for the species-name line. |
| 138 | companion = get_companion() |
| 139 | if companion is None: |
| 140 | # Defensive: should never happen — _save_companion succeeded. |
| 141 | return LocalCommandResult( |
| 142 | type='text', value='Failed to hatch companion (state error).', |
| 143 | ) |
| 144 | return LocalCommandResult( |