From a653cf023c39e6e668f9b8136bff1d012ab4f5b9 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Wed, 26 Aug 2020 10:56:33 +0200 Subject: support recursive annotations (for now for command only) --- main.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 0ea3605..a113b61 100755 --- a/main.py +++ b/main.py @@ -33,31 +33,32 @@ def register_signald(number): s.verify(code) -def handle_response(response): +def handle_replies(replies): answer = "" - replies = response.json()['reply'] for reply in replies: - # handle annotations - local_answer = reply['text'] + answer = reply['text'] for annotation in reply["annotations"]: - atype = annotation["type"] - aextra = annotation["extra"] - - if atype == "command": - local_answer = f"/{local_answer}: " - elif atype == "link": - local_answer = f"{aextra} ({local_answer})" - elif atype == "bold": - local_answer = f"*{local_answer}*" - elif atype == "italic": - local_answer = f"_{local_answer}_" - elif atype == "strikethrough": - local_answer = f"~{local_answer}~" - answer += local_answer - + a_type = annotation["type"] + a_extra = annotation["extra"] + + if a_type == "command": + answer = f"/{answer}: {handle_replies(a_extra)}\n" + elif a_type == "link": + answer = f"{a_extra} ({answer})" + elif a_type == "bold": + answer = f"*{answer}*" + elif a_type == "italic": + answer = f"_{answer}_" + elif a_type == "strikethrough": + answer = f"~{answer}~" return answer +def handle_response(response): + replies = response.json()['reply'] + return handle_replies(replies) + + def startup(number): s = Signal(number) -- cgit v1.2.3-54-g00ecf