Skip to content

Commit 1a00a85

Browse files
authored
Merge branch 'main' into fixing_uwu
2 parents 27a603a + defbe28 commit 1a00a85

File tree

5 files changed

+238
-151
lines changed

5 files changed

+238
-151
lines changed

bot/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class _Reddit(EnvConfig, env_prefix="reddit_"):
301301
client_id: SecretStr = ""
302302
secret: SecretStr = ""
303303
webhook: int = 635408384794951680
304+
send_top_daily_posts: bool = True
304305

305306

306307
Reddit = _Reddit()

bot/exts/utilities/colour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def hex(self, ctx: commands.Context, hex_code: str) -> None:
163163
@colour.command()
164164
async def name(self, ctx: commands.Context, *, user_colour_name: str) -> None:
165165
"""Create an embed from a name input."""
166-
hex_colour = self.match_colour_name(ctx, user_colour_name)
166+
hex_colour = self.match_colour_name(ctx, user_colour_name.title())
167167
if hex_colour is None:
168168
name_error_embed = discord.Embed(
169169
title="No colour match found.",

bot/exts/utilities/reddit.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)