skip posts before last sent
This commit is contained in:
parent
2fd30ea5d0
commit
75f8353000
10
main.py
10
main.py
@ -120,8 +120,12 @@ async def check_updates():
|
||||
posts = await e621.get_posts(tags)
|
||||
if not posts:
|
||||
return
|
||||
already_sent = await redis.smismember('e621:sent', [p.id for p in posts])
|
||||
for i in list(range(len(posts)))[::-1]:
|
||||
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]:
|
||||
if already_sent[i]:
|
||||
continue
|
||||
await send_post(posts[i], tag_list)
|
||||
@ -135,6 +139,8 @@ async def add_tag(msg: Message):
|
||||
await msg.reply('Please provide tag to subscribe to')
|
||||
return
|
||||
for tag in args.split():
|
||||
posts = await e621.get_posts(tag)
|
||||
await redis.sadd('e621:sent', *[post.id for post in posts])
|
||||
await redis.sadd('e621:subs', tag)
|
||||
await msg.reply(f'Tags {args} added')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user