Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback message handler #236

Closed
emilyyyylime opened this issue Jan 3, 2024 · 3 comments
Closed

Add fallback message handler #236

emilyyyylime opened this issue Jan 3, 2024 · 3 comments

Comments

@emilyyyylime
Copy link
Contributor

(As discussed on Discord)

My usecase requires potentially processing all non-command messages, and I found the only way to robustly do this was to add a general event handler and then parse all messages twice to check whether they are valid commands or not. It would be nice to have an exposed API to process any message that wasn't found to be a command, perhaps exposing the reason it failed to parse as a command—though that's beyond my own use case

@emilyyyylime
Copy link
Contributor Author

Another option would be to expose prefix::strip_prefix as a public API, though that's less 'robust'

@kangalio
Copy link
Collaborator

kangalio commented Jan 8, 2024

Using strip_prefix to check whether a message is a command would give false positives...

  • if the message is from the bot itself and execute_self_messages isn't set
  • if the message is from other bots and ignore_bots is set
  • if the message is a thread creation and ignore_thread_creation is set
  • if the string after the prefix is not a valid command invocation (find_command)
  • if the parsed command doesn't have a prefix implementation

All these edge cases along with a nested call to the actual strip_prefix are handled in parse_invocation, and that function is public. So FYI if you're ok with that hacky solution, you can already do it now if you want

@kangalio
Copy link
Collaborator

Implemented in 1f0abfb. Feel free to try it in your bot via a cargo git dependency ^^

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

No branches or pull requests

3 participants