Handle having zero new posts
This commit is contained in:
		
							parent
							
								
									83ad790162
								
							
						
					
					
						commit
						c0d035fcb4
					
				
							
								
								
									
										10
									
								
								redditbot.py
								
								
								
								
							
							
						
						
									
										10
									
								
								redditbot.py
								
								
								
								
							| 
						 | 
				
			
			@ -104,7 +104,7 @@ async def main():
 | 
			
		|||
                random_post = await subreddit.random()
 | 
			
		||||
                cpid = cpp = None
 | 
			
		||||
                if random_post is None:
 | 
			
		||||
                    async for submission in subreddit.hot():
 | 
			
		||||
                    async for submission in subreddit.hot(limit=None):
 | 
			
		||||
                        if unique_id in give_ups:
 | 
			
		||||
                            return
 | 
			
		||||
                        cpid = getattr(submission, 'crosspost_parent', None)
 | 
			
		||||
| 
						 | 
				
			
			@ -132,6 +132,9 @@ async def main():
 | 
			
		|||
                                continue
 | 
			
		||||
                        random_post = submission
 | 
			
		||||
                        break
 | 
			
		||||
                if random_post is None:
 | 
			
		||||
                    return
 | 
			
		||||
 | 
			
		||||
                cpid = getattr(random_post, 'crosspost_parent', None)
 | 
			
		||||
                if cpid and getattr(random_post, 'crosspost_parent_list', None):
 | 
			
		||||
                    cpid = cpid[3:]
 | 
			
		||||
| 
						 | 
				
			
			@ -165,7 +168,7 @@ async def main():
 | 
			
		|||
            while True:
 | 
			
		||||
                unique_id = time.time()
 | 
			
		||||
                try:
 | 
			
		||||
                    random_post, cpp = await asyncio.wait_for(_get_submission(unique_id), timeout)
 | 
			
		||||
                    result = await asyncio.wait_for(_get_submission(unique_id), timeout)
 | 
			
		||||
                except asyncio.TimeoutError:
 | 
			
		||||
                    give_ups.add(unique_id)
 | 
			
		||||
                    logging.error('%s timed out', chat)
 | 
			
		||||
| 
						 | 
				
			
			@ -178,6 +181,9 @@ async def main():
 | 
			
		|||
                    for i in bot_admins:
 | 
			
		||||
                        await client.send_message(i, f'{chat}\n{traceback.format_exc()}')
 | 
			
		||||
                else:
 | 
			
		||||
                    if not result:
 | 
			
		||||
                        return
 | 
			
		||||
                    random_post, cpp = result
 | 
			
		||||
                    try:
 | 
			
		||||
                        await _actual_start_post(random_post, [chat], cpp, show_nsfw_warning, show_spoilers_warning)
 | 
			
		||||
                    except BaseException:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue