skip posts before last sent

master
bakatrouble 9 months ago
parent 2fd30ea5d0
commit 75f8353000

@ -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…
Cancel
Save