Skip to content

refactor(commandhandler): replace the menu-echo class-name check with a flag - #163

Merged
Rushaway merged 2 commits into
masterfrom
refactor/158-commandhandler-menu-echo-flag
Sep 6, 2026
Merged

refactor(commandhandler): replace the menu-echo class-name check with a flag#163
Rushaway merged 2 commits into
masterfrom
refactor/158-commandhandler-menu-echo-flag

Conversation

@Rushaway

@Rushaway Rushaway commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

  • CommandHandler decided whether to echo a menu-triggered command back to chat via command.__class__.__name__ in ("VoiceTrigger", "MyInstantsSearch") — a string comparison buried in the generic dispatcher. Any new command needing that behavior silently wouldn't get it unless someone remembered to edit this tuple.
  • Added an echo_from_menu class attribute on BaseCommand (default False), set to True on VoiceTrigger and MyInstantsSearch, and the dispatcher now checks it polymorphically.

One subtlety worth a look

Random subclasses VoiceTrigger, so it would have inherited echo_from_menu = True — a behavior change the old exact-class-name check never granted it. Since this is a refactor, I set Random.echo_from_menu = False explicitly to keep runtime behavior byte-identical.

If you think Random should echo when played from a menu (arguably it should — it plays a sound like any other trigger), that's a one-line follow-up, but it's a deliberate product decision rather than something to slip in under a refactor.

Closes #158

Test plan

  • Walked all 25 BaseCommand subclasses via AST, resolving echo_from_menu through the inheritance chain, and compared against the old __name__ in (...) predicate: zero mismatches — semantics are identical, Random included.

🤖 Generated with Claude Code

… a flag

The dispatcher decided whether to echo a menu-triggered command back to
chat by comparing command.__class__.__name__ against a hardcoded tuple of
two names, so any new command needing that behavior silently wouldn't get
it unless someone remembered to edit the generic dispatcher.

Added an echo_from_menu class attribute on BaseCommand (default False),
enabled on VoiceTrigger and MyInstantsSearch, and checked polymorphically.

Random subclasses VoiceTrigger and would have inherited the flag, which
the old exact-name check never granted it, so it is explicitly set back to
False to keep behavior identical.

Bumps VERSION to 1.8.17.

Closes #158

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Dolly132 <109222243+Dolly132@users.noreply.github.com>
@Rushaway
Rushaway requested a review from Dolly132 September 5, 2026 13:09

@Rushaway Rushaway left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review: the interesting bit is Random -- it inherits VoiceTrigger, so a naive flag would have silently enabled menu-echo for it where the old string check didn't. Pinned it to False to keep this a true no-op refactor, and verified equivalence across all 25 command classes by resolving the attribute through the inheritance chain rather than assuming. Flagging it explicitly since it's a judgment call you may want to reverse.

@Dolly132 Dolly132 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, would be helpful when adding new menu-based commands in the future instead of having to edit CommandHandler.py again.

@Rushaway
Rushaway merged commit cb2ced1 into master Sep 6, 2026
2 checks passed
@Rushaway
Rushaway deleted the refactor/158-commandhandler-menu-echo-flag branch September 6, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandHandler uses a string class-name comparison instead of a BaseCommand flag for menu-echo behavior

2 participants