-
-
Notifications
You must be signed in to change notification settings - Fork 39
Pattern Matching
Sometimes you want your bot to be able to respond, not to commands, but to certain patterns. This could be for a number of reasons. Maybe you want it to be able to say "Hello" back whenever it hears someone say hello to the group, maybe you want to automatically mute someone that sends a link/email right after joining a group. Whatever the reason, Tourmaline's got your back.
Tourmaline comes with an annotation called Hears
which accepts a pattern and will call the annotated method any time that pattern is matched. Let's see an example:
@[Hears(/^Hello/)
def on_hello(message)
message.reply("Hello to you")
end
Now any time your bot sees a message that starts with "Hello" it will respond with "Hello to you". As with the Command
annotation, the Hears
annotation has a handler counterpart in the HearsHandler
which can be used instead.
Tourmaline (and many other projects) was written by watzon. It is free software, but if you feel so inclined you could sponsor its development on Patreon. Thank you for using my projects!
- Webhooks
- Inline Actions
- Reply Keyboards
- Games (coming soon)
- Stickers (coming soon)
- Payments