aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
m---------libs/pysignald0
-rwxr-xr-xmain.py25
2 files changed, 19 insertions, 6 deletions
diff --git a/libs/pysignald b/libs/pysignald
-Subproject a4c7361fdaa91c805081abfd7f593244fc00821
+Subproject 64a3de18188aae3c9376bb50a542ee26ca1bb65
diff --git a/main.py b/main.py
index 33dda13..ecb649a 100755
--- a/main.py
+++ b/main.py
@@ -2,8 +2,10 @@
import os
import sys
+import base64
import getopt
import requests
+import tempfile
from libs.pysignald.signald import Signal
from configparser import ConfigParser
@@ -41,7 +43,7 @@ def handle_replies(replies):
l_answer = reply['text']
for annotation in reply["annotations"]:
a_type = annotation["type"]
- a_extra = handle_replies(annotation["extra"])
+ a_extra, is_attachment = handle_replies(annotation["extra"])
if a_type == "command":
l_answer = f"/{l_answer}: {a_extra}\n"
@@ -53,8 +55,19 @@ def handle_replies(replies):
l_answer = f"_{l_answer}_"
elif a_type == "strikethrough":
l_answer = f"~{l_answer}~"
+ elif a_type == "attachment":
+ [file_name, file_type, file_content] = a_extra.split(';')
+ try:
+ tmp_path = tempfile.TemporaryDirectory()
+ file_content = base64.b64decode(file_content)
+ file_path = tmp_path.name + '/' + file_name
+ with open(file_path, "wb") as f:
+ f.write(file_content)
+ return answer, True
+ except Exception as e:
+ print(str(e))
answer += l_answer
- return answer
+ return answer, False
def handle_response(response):
@@ -76,9 +89,9 @@ def startup(number):
response = requests.post('http://localhost:18080',
json={"command": match.group(1), "arguments": match.group(2).strip()})
- answer = handle_response(response)
+ answer, is_attachment = handle_response(response)
- return stop, answer
+ return stop, answer, is_attachment
# no args
@s.chat_handler("^/(.+)$", order=20) # This is case-insensitive.
@@ -91,9 +104,9 @@ def startup(number):
response = requests.post('http://localhost:18080',
json={"command": match.group(1), "arguments": ""})
- answer = handle_response(response)
+ answer, is_attachment = handle_response(response)
- return stop, answer
+ return stop, answer, is_attachment
s.run_chat()