skip old posts command

This commit is contained in:
bakatrouble 2023-08-13 23:03:37 +03:00
parent 75f8353000
commit 3f2f1ddc38

22
main.py
View File

@ -121,11 +121,11 @@ async def check_updates():
if not posts: if not posts:
return return
already_sent: List = await redis.smismember('e621:sent', [p.id for p in posts]) already_sent: List = await redis.smismember('e621:sent', [p.id for p in posts])
last_index = len(posts) # last_index = len(posts)
if already_sent.count(True): # if already_sent.count(True):
last_index = already_sent.index(True) # last_index = already_sent.index(True)
await redis.sadd('e621:sent', *[posts[i].id for i in range(last_index, len(posts))]) # 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]: for i in list(range(len(posts)))[::-1]:
if already_sent[i]: if already_sent[i]:
continue continue
await send_post(posts[i], tag_list) await send_post(posts[i], tag_list)
@ -145,6 +145,18 @@ async def add_tag(msg: Message):
await msg.reply(f'Tags {args} added') 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+$') @dp.message_handler(filters.IDFilter(chat_id=user_ids), regexp=r'^\/del_\S+$')
async def del_tag(msg: Message): async def del_tag(msg: Message):
args = msg.text[5:] args = msg.text[5:]