浏览代码

Merge remote-tracking branch 'mkuhlmann/master'

Tulir Asokan 4 年之前
父节点
当前提交
067f5addfe
共有 3 个文件被更改,包括 23 次插入5 次删除
  1. 3 2
      Dockerfile
  2. 19 3
      mautrix_signal/portal.py
  3. 1 0
      requirements.txt

+ 3 - 2
Dockerfile

@@ -19,9 +19,10 @@ RUN apk add --no-cache \
       ca-certificates \
       ca-certificates \
       su-exec \
       su-exec \
       # encryption
       # encryption
+      libressl \
       olm-dev \
       olm-dev \
       py3-cffi \
       py3-cffi \
-	  py3-pycryptodome \
+      py3-pycryptodome \
       py3-unpaddedbase64 \
       py3-unpaddedbase64 \
       py3-future \
       py3-future \
       bash \
       bash \
@@ -33,7 +34,7 @@ RUN apk add --no-cache \
 COPY requirements.txt /opt/mautrix-signal/requirements.txt
 COPY requirements.txt /opt/mautrix-signal/requirements.txt
 COPY optional-requirements.txt /opt/mautrix-signal/optional-requirements.txt
 COPY optional-requirements.txt /opt/mautrix-signal/optional-requirements.txt
 WORKDIR /opt/mautrix-signal
 WORKDIR /opt/mautrix-signal
-RUN apk add --virtual .build-deps python3-dev libffi-dev build-base \
+RUN apk add --virtual .build-deps python3-dev libffi-dev libressl-dev build-base \
  && pip3 install -r requirements.txt -r optional-requirements.txt \
  && pip3 install -r requirements.txt -r optional-requirements.txt \
  && apk del .build-deps
  && apk del .build-deps
 
 

+ 19 - 3
mautrix_signal/portal.py

@@ -24,6 +24,8 @@ import os.path
 import time
 import time
 import os
 import os
 
 
+from signalstickers_client import StickersClient
+
 from mausignald.types import (Address, MessageData, Reaction, Quote, Group, Contact, Profile,
 from mausignald.types import (Address, MessageData, Reaction, Quote, Group, Contact, Profile,
                               Attachment, GroupID, GroupV2ID, GroupV2, Mention)
                               Attachment, GroupID, GroupV2ID, GroupV2, Mention)
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.appservice import AppService, IntentAPI
@@ -322,9 +324,23 @@ class Portal(DBPortal, BasePortal):
 
 
         if message.sticker:
         if message.sticker:
             if not message.sticker.attachment.incoming_filename:
             if not message.sticker.attachment.incoming_filename:
-                self.log.warning("Failed to bridge sticker, no incoming filename: %s",
-                                 message.sticker.attachment)
-            else:
+                self.log.debug("Downloading sticker from signal, as no incoming filename was defined: %s",
+                               message.sticker.attachment)
+                try:
+                    async with StickersClient() as client:
+                        sticker_data = await client.download_sticker(message.sticker.sticker_id,
+                                                                     message.sticker.pack_id,
+                                                                     message.sticker.pack_key)
+
+                    path = os.path.join(self.config["signal.outgoing_attachment_dir"],
+                                        f"{message.sticker.pack_id}_{message.sticker.sticker_id}")
+                    with open(path, "wb") as file:
+                        file.write(sticker_data)
+                    message.sticker.attachment.incoming_filename = path
+                except Exception as ex:
+                    self.log.warning("Failed to download sticker: %s", ex)
+
+            if message.sticker.attachment.incoming_filename:
                 content = await self._handle_signal_attachment(intent, message.sticker.attachment)
                 content = await self._handle_signal_attachment(intent, message.sticker.attachment)
                 if reply_to:
                 if reply_to:
                     content.set_reply(reply_to)
                     content.set_reply(reply_to)

+ 1 - 0
requirements.txt

@@ -6,3 +6,4 @@ yarl>=1,<2
 attrs>=19.1
 attrs>=19.1
 mautrix>=0.8.11,<0.9
 mautrix>=0.8.11,<0.9
 asyncpg>=0.20,<0.22
 asyncpg>=0.20,<0.22
+signalstickers-client>=3.0