diff --git a/tgschedpub.py b/tgschedpub.py index a134744..0e0d22d 100755 --- a/tgschedpub.py +++ b/tgschedpub.py @@ -13,7 +13,7 @@ from telethon.extensions.html import ( ) from telethon.tl.patched import Message from telethon.tl.types import InputPeerChannel, InputMediaWebPage -from telethon.tl.functions.messages import EditMessageRequest, SendScheduledMessagesRequest +from telethon.tl.functions.messages import EditMessageRequest, SendScheduledMessagesRequest, GetScheduledHistoryRequest # Set up logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) @@ -30,20 +30,25 @@ def load_config(): async def main(mode, channel_id=None): - messages = reversed(await client.get_messages(channel_id, limit=100, scheduled=True)) channel = await client.get_entity(channel_id) + messages = reversed((await client(GetScheduledHistoryRequest(peer=channel.id, hash=0))).messages) input_peer = InputPeerChannel(channel.id, channel.access_hash) + send_date = None for m in messages: if not isinstance(m, Message): continue if mode == 'send': - await client(SendScheduledMessagesRequest( - peer=input_peer, - id=[m.id] - )) - break + if send_date is None or m.date.date() == send_date: + send_date = m.date.date() + await client(SendScheduledMessagesRequest( + peer=input_peer, + id=[m.id] + )) + continue + else: + break elif mode == 'images': html = entities_to_html(m.message, m.entities) @@ -68,7 +73,7 @@ async def main(mode, channel_id=None): await sleep(2) else: - logging.error(f'Message {m.id}: could not find link with a dot!') + logging.warning(f'Message {m.id}: could not find link with a dot!') if __name__ == '__main__':