From 36560c9c3b414d24ecaff901dc766ade28fad228 Mon Sep 17 00:00:00 2001 From: Stavros Korokithakis Date: Tue, 11 Dec 2018 19:00:07 +0200 Subject: Add `order` argument and match continuation --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4999174..3843409 100644 --- a/README.md +++ b/README.md @@ -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() ``` -- cgit v1.2.3-54-g00ecf