From 29084d1576e1435a5a4a32071a79b6af28acd362 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 22 Apr 2021 20:25:38 +0100 Subject: Fix errors when a subreddit has <5 posts. If a subreddit has <2 posts, the posts[1] check would fail with an IndexError. If the subreddit had less that 5 posts, then the k=5 check would also error. These changes harden the command for these edge cases. --- bot/exts/evergreen/reddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/reddit.py b/bot/exts/evergreen/reddit.py index 49127bea..4fdb6fca 100644 --- a/bot/exts/evergreen/reddit.py +++ b/bot/exts/evergreen/reddit.py @@ -54,7 +54,7 @@ class Reddit(commands.Cog): if not posts: return await ctx.send('No posts available!') - if posts[1]["data"]["over_18"] is True: + if posts[0]["data"]["over_18"] is True: return await ctx.send( "You cannot access this Subreddit as it is ment for those who " "are 18 years or older." @@ -63,7 +63,7 @@ class Reddit(commands.Cog): embed_titles = "" # Chooses k unique random elements from a population sequence or set. - random_posts = random.sample(posts, k=5) + random_posts = random.sample(posts, k=min(len(posts), 5)) # ----------------------------------------------------------- # This code below is bound of change when the emojis are added. -- cgit v1.2.3 From d77986e528b977170c30efb6afc41e53425ad6df Mon Sep 17 00:00:00 2001 From: ChrisJL Date: Fri, 23 Apr 2021 12:28:37 +0100 Subject: Fix spelling of a user facing message in reddit cog Co-authored-by: Xithrius <15021300+Xithrius@users.noreply.github.com> --- bot/exts/evergreen/reddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/reddit.py b/bot/exts/evergreen/reddit.py index 4fdb6fca..2be511c8 100644 --- a/bot/exts/evergreen/reddit.py +++ b/bot/exts/evergreen/reddit.py @@ -56,7 +56,7 @@ class Reddit(commands.Cog): if posts[0]["data"]["over_18"] is True: return await ctx.send( - "You cannot access this Subreddit as it is ment for those who " + "You cannot access this Subreddit as it is meant for those who " "are 18 years or older." ) -- cgit v1.2.3