From a6bc05844bb298b01eb5f0d271c974ff7159726d Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sun, 30 Aug 2020 12:25:43 +0400 Subject: [PATCH] Implement reposting messages with one image, add info about forward msg to the text of toot --- bridge.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bridge.py b/bridge.py index 7be70c4..657201d 100644 --- a/bridge.py +++ b/bridge.py @@ -1,4 +1,8 @@ import asyncio +import os +import uuid +from io import BytesIO + import toml import argparse from mastodon import Mastodon @@ -38,7 +42,17 @@ class BridgeBot: if channel.broadcast: if channel.username in self.config["telegram"]["channels"]: print("dobbry vechur") - self.mastodon_client.toot(event.message.text) + text: str = event.message.text + if event.message.forward: + text = f"[from {event.message.forward.chat.title} (https://t.me/{event.message.forward.chat.username})]\n\n" + text + if event.message.photo: + temp_image_name = uuid.uuid4() + await self.tg_client.download_media(event.message.photo, f"/tmp/{temp_image_name}.jpg") + mstdn_media_meta = self.mastodon_client.media_post(f"/tmp/{temp_image_name}.jpg") + self.mastodon_client.status_post(text, media_ids=[mstdn_media_meta]) + os.remove(f"/tmp/{temp_image_name}.jpg") + return + self.mastodon_client.toot(text) if __name__ == '__main__':