From ca542b749c6bcb7c3755d13784c76dd9a48539ac Mon Sep 17 00:00:00 2001 From: jsdio Date: Mon, 13 Sep 2021 03:47:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + main.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a388d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/session.session +/config.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..18d2052 --- /dev/null +++ b/main.py @@ -0,0 +1,108 @@ +import encodings +from tqdm import tqdm +import telethon +from telethon import TelegramClient, sync, functions, errors, types +from telethon.extensions import markdown +import asyncio +import time +from config import * +import markdown2 +loop = asyncio.get_event_loop() + + + + + +class GropAlbum: + def __init__(self, albumId, media, mess): + self.albumId = albumId + self.media = media + self.mess = mess + self.medias = [] + + def inputMedia(self, media): + self.medias.append(media) + + def lenMedia(self): + return len(self.medias) + + def getStatus(self, albumId): + if albumId == self.albumId: + return True + elif self.albumId is None: + return 'None' + else: + return 'main', self.medias, self.mess + +class ForwardAlbum: + def __init__(self, albumId): + self.albumId = albumId + self.ids = [] + + def inputId(self, messId): + self.ids.append(messId) + + def getIds(self): + return self.ids + + def getStatus(self, albumId): + if albumId == self.albumId: + return True + elif self.albumId is None: + return 'None' + else: + return 'forward', self.ids + + + +async def main(): + chat = ForwardAlbum(None) + async with TelegramClient(session, api_id, api_hash) as client: + for mess_id in tqdm([20, 21]): + mess_id = mess_id+1 + mess = await client.get_messages(from_channel, ids=mess_id) + print(mess) + if mess is None: + continue + if mess.grouped_id is not None: + albumId = mess.grouped_id + else: + albumId = None + status = chat.getStatus(albumId) + if mess.fwd_from is not None: + if status is True and albumId is None: + await client.forward_messages(in_channel, mess_id, from_channel) + elif status is True and albumId is not None: + chat.inputId(mess_id) + elif status is not True: + if status[0] == 'main': + await client.send_file(in_channel, chat.medias, caption=chat.mess) + chat = ForwardAlbum(albumId) + chat.inputId(mess_id) + elif status[0] == 'forward': + await client.forward_messages(in_channel, chat.ids, from_channel) + chat = ForwardAlbum(albumId) + chat.inputId(mess_id) + elif status == 'None': + chat = ForwardAlbum(albumId) + chat.inputId(mess_id) + elif mess.grouped_id is not None: + if status is True: + chat.inputMedia(mess.media) + elif status is not True: + if status[0] == 'main': + await client.send_file(in_channel, chat.medias, caption=chat.mess) + chat = GropAlbum(albumId, mess.media, mess.message) + elif status[0] == 'forward': + await client.forward_messages(in_channel, chat.ids, from_channel) + chat = GropAlbum(albumId, mess.media, mess.message) + elif status == 'None': + chat = GropAlbum(albumId, mess.media, mess.message) + else: + await client.send_message(in_channel, mess, parse_mode='HTML') + time.sleep(1) + + # await client.forward_messages(entity=in_channel, messages=[76, 77], from_peer=from_channel) + # await client.send_file(in_channel, [mess.media], caption=mess.message) + +loop.run_until_complete(main()) \ No newline at end of file