diff options
author | Stavros Korokithakis <hi@stavros.io> | 2018-12-11 19:00:07 +0200 |
---|---|---|
committer | Stavros Korokithakis <hi@stavros.io> | 2018-12-11 19:00:07 +0200 |
commit | 36560c9c3b414d24ecaff901dc766ade28fad228 (patch) | |
tree | af6338b30095272f5b02e54efd24ee924c235a72 /README.md | |
parent | e4255041219e364e5ae7aa4d95085008f823e9fe (diff) | |
download | pysignald-36560c9c3b414d24ecaff901dc766ade28fad228.tar.gz pysignald-36560c9c3b414d24ecaff901dc766ade28fad228.zip |
Add `order` argument and match continuation
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -46,9 +46,23 @@ from signald import Signal s = Signal("+1234567890") -@s.chat_handler("hello") # This is case-insensitive. +@s.chat_handler("hello there", order=10) # This is case-insensitive. +def hello_there(message, match): + # Returning `False` as the first argument will cause matching to continue + # after this handler runs. + stop = False + reply = "Hello there!" + return stop, reply + + +# Matching is case-insensitive. The `order` argument signifies when +# the handler will try to match (default is 100), and functions get sorted +# by order of declaration secondly. +@s.chat_handler("hello", order=10) def hello(message, match): - return "Hello there!" + # This will match on "hello there" as well because of the "stop" return code in + # the function above. Both replies will be sent. + return "Hello!" @s.chat_handler(re.compile("my name is (.*)")) # This is case-sensitive. @@ -56,6 +70,12 @@ def name(message, match): return "Hello %s." % match.group(1) +@s.chat_handler("") +def catch_all(message, match): + # This will only be sent if nothing else matches, because matching + # stops by default on the first function that matches. + return "I don't know what you said." + s.run_chat() ``` |