diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-08-26 10:27:05 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-08-26 10:27:05 +0200 |
commit | 6c2fa3b89434d489a26e1902f357a307322ce530 (patch) | |
tree | c0b2b5b45cf51e17c4364e8bd64993896ee62308 | |
parent | 1276ce4162b5be7ec9df761ecd3c7694856ac92b (diff) | |
download | n_frontend_signal-6c2fa3b89434d489a26e1902f357a307322ce530.tar.gz n_frontend_signal-6c2fa3b89434d489a26e1902f357a307322ce530.zip |
handle a few annotations
-rwxr-xr-x | main.py | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -33,6 +33,35 @@ def register_signald(number): s.verify(code) +def handle_response(response): + answer = "" + replies = response.json()['reply'] + for reply in replies: + # handle annotations + answer += reply['text'] + for annotation in reply["annotations"]: + atype = annotation["type"] + aextra = annotation["extra"] + + if atype == "command": + answer = f"/{answer}: " + break + elif atype == "link": + answer = f"{aextra} ({answer})" + break + elif atype == "bold": + answer = f"*{answer}*" + break + elif atype == "italic": + answer = f"_{answer}_" + break + elif atype == "strikethrough": + answer = f"~{answer}~" + break + + return answer + + def startup(number): s = Signal(number) @@ -47,10 +76,7 @@ def startup(number): response = requests.post('http://localhost:18080', json={"command": match.group(1), "arguments": match.group(2).strip()}) - answer = "" - replies = response.json()['reply'] - for reply in replies: - answer += reply['text'] + answer = handle_response(response) return stop, answer @@ -65,10 +91,7 @@ def startup(number): response = requests.post('http://localhost:18080', json={"command": match.group(1), "arguments": ""}) - answer = "" - replies = response.json()['reply'] - for reply in replies: - answer += reply['text'] + answer = handle_response(response) return stop, answer |