serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
597 stars 106 forks source link

Add fallback message handler #236

Closed emilyyyylime closed 1 month ago

emilyyyylime commented 6 months ago

(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 commented 6 months ago

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

kangalio commented 6 months ago

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

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 commented 6 months ago

Implemented in https://github.com/serenity-rs/poise/commit/1f0abfbc4c6d79af62867ff94fe79f5ae4fe6f8f. Feel free to try it in your bot via a cargo git dependency ^^