add resend_after command
This commit is contained in:
parent
446649fc7f
commit
1d3221932a
30
main.py
30
main.py
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
@ -143,6 +144,35 @@ async def check_updates():
|
||||
await sleep(1)
|
||||
|
||||
|
||||
@dp.message(filters.Command('resend_after'), ChatFilter)
|
||||
async def resend_after(msg: Message):
|
||||
try:
|
||||
timestamp = int(msg.text.split()[1])
|
||||
except:
|
||||
traceback.print_exc()
|
||||
await msg.reply('Invalid timestamp or not provided')
|
||||
return
|
||||
|
||||
async with redis.lock('e621:update'):
|
||||
tag_list = [t.decode() for t in await redis.smembers('e621:subs')]
|
||||
for i, tag in enumerate(tag_list):
|
||||
await msg.reply(f'Checking tag <b>{tag}</b> ({i+1}/{len(tag_list)}')
|
||||
posts = []
|
||||
page = 1
|
||||
while True:
|
||||
page_posts = await e621.get_posts(tag, page)
|
||||
if not page_posts:
|
||||
break
|
||||
for post in page_posts:
|
||||
if datetime.datetime.fromisoformat(post.created_at).timestamp() < timestamp:
|
||||
break
|
||||
posts.append(post)
|
||||
page += 1
|
||||
for post in posts[::-1]:
|
||||
await send_post(post, tag_list)
|
||||
await msg.reply('Finished')
|
||||
|
||||
|
||||
@dp.message(filters.Command('add'), ChatFilter)
|
||||
async def add_tag(msg: Message):
|
||||
args = ' '.join(msg.text.split()[1:])
|
||||
|
Loading…
Reference in New Issue
Block a user