@@ -36,7 +36,8 @@ def __init__(self, bot: Bot):
3636 self .access_token = None
3737 self .client_auth = BasicAuth (RedditConfig .client_id .get_secret_value (), RedditConfig .secret .get_secret_value ())
3838
39- self .auto_poster_loop .start ()
39+ if RedditConfig .send_top_daily_posts :
40+ self .auto_poster_loop .start ()
4041
4142 async def cog_unload (self ) -> None :
4243 """Stop the loop task and revoke the access token when the cog is unloaded."""
@@ -201,6 +202,13 @@ async def fetch_posts(self, route: str, *, amount: int = 25, params: dict | None
201202 await asyncio .sleep (3 )
202203
203204 log .debug (f"Invalid response from: { url } - status code { response .status } , mimetype { response .content_type } " )
205+ if response .status == 429 :
206+ log .warning (
207+ "Hit reddit ratelimit. Used: %s Remaining: %s Reset: %s" ,
208+ response .headers .get ("X-Ratelimit-Used" , "Missing" ),
209+ response .headers .get ("X-Ratelimit-Remaining" , "Missing" ),
210+ response .headers .get ("X-Ratelimit-Approximate " , "Missing" ),
211+ )
204212 return [] # Failed to get appropriate response within allowed number of retries.
205213
206214 async def get_top_posts (
@@ -301,6 +309,11 @@ async def top_command(self, ctx: Context, subreddit: Subreddit = "r/Python") ->
301309 async with ctx .typing ():
302310 pages = await self .get_top_posts (subreddit = subreddit , time = "all" , paginate = True )
303311
312+ if isinstance (pages , Embed ):
313+ # If get_top_posts hits an error, then an error embed is returned, not actual posts.
314+ await ctx .send (embed = pages )
315+ return
316+
304317 await ctx .send (f"Here are the top { subreddit } posts of all time!" )
305318 embed = Embed (
306319 color = Colour .og_blurple ()
0 commit comments