diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-08-26 10:56:33 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-08-26 10:56:33 +0200 |
commit | a653cf023c39e6e668f9b8136bff1d012ab4f5b9 (patch) | |
tree | 71a22f15952fc5cd1a391433483bd6cc787e5c63 | |
parent | e01490fb32fbfee4ec13cb3cedb512fbb29baa55 (diff) | |
download | n_frontend_signal-a653cf023c39e6e668f9b8136bff1d012ab4f5b9.tar.gz n_frontend_signal-a653cf023c39e6e668f9b8136bff1d012ab4f5b9.zip |
support recursive annotations (for now for command only)
-rwxr-xr-x | main.py | 39 |
1 files changed, 20 insertions, 19 deletions
@@ -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) |