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