mirror of
https://github.com/ChronosX88/mastodon-bridge-bot.git
synced 2024-11-22 13:52:18 +00:00
Implement reposting messages with one image, add info about forward msg to the text of toot
This commit is contained in:
parent
c0cb6ddbf8
commit
a6bc05844b
16
bridge.py
16
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__':
|
||||
|
Loading…
Reference in New Issue
Block a user