From 3f2f1ddc382cc58ec97d3497c4005a9f85532347 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sun, 13 Aug 2023 23:03:37 +0300 Subject: [PATCH] skip old posts command --- main.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index abf6c8e..f3c9c5b 100644 --- a/main.py +++ b/main.py @@ -121,11 +121,11 @@ async def check_updates(): if not posts: return already_sent: List = await redis.smismember('e621:sent', [p.id for p in posts]) - last_index = len(posts) - if already_sent.count(True): - last_index = already_sent.index(True) - await redis.sadd('e621:sent', *[posts[i].id for i in range(last_index, len(posts))]) - for i in list(range(len(posts)))[:last_index][::-1]: + # last_index = len(posts) + # if already_sent.count(True): + # last_index = already_sent.index(True) + # await redis.sadd('e621:sent', *[posts[i].id for i in range(last_index, len(posts))]) + for i in list(range(len(posts)))[::-1]: if already_sent[i]: continue await send_post(posts[i], tag_list) @@ -145,6 +145,18 @@ async def add_tag(msg: Message): await msg.reply(f'Tags {args} added') +@dp.message_handler(filters.IDFilter(chat_id=user_ids), commands=['mark_old_as_sent']) +async def mark_old_as_sent(msg: Message): + tag_list = [t.decode() for t in await redis.smembers('e621:subs')] + m = await msg.reply(f'0/{len(tag_list)} tags have old posts marked as sent') + for i, tag in enumerate(tag_list, 1): + posts = await e621.get_posts(tag) + await redis.sadd('e621:sent', *[post.id for post in posts]) + await m.edit_text(f'{i}/{len(tag_list)} tags have old posts marked as sent') + await sleep(1) + await m.edit_text(f'Done marking old posts as sent for {len(tag_list)} tags') + + @dp.message_handler(filters.IDFilter(chat_id=user_ids), regexp=r'^\/del_\S+$') async def del_tag(msg: Message): args = msg.text[5:]