From f0897467d0cb3ae5590e5ec1487ffc4d281b8cd7 Mon Sep 17 00:00:00 2001 From: Guus Date: Wed, 28 Oct 2026 17:58:59 +0100 Subject: [PATCH 1/2] rewrite kopieerpasta fixes #32 --- General.py | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/General.py b/General.py index 8a57b95..6e2b0b4 100644 --- a/General.py +++ b/General.py @@ -14,12 +14,12 @@ class General(commands.Cog): def __init__(self, bot): self.bot = bot self.muzak_url = 'http://muzak.hoekveen.net:8001' - self.r = praw.Reddit( + self.reddit = praw.Reddit( user_agent='StroopwafelBot', client_secret=os.getenv("STROOP_REDDIT_SECRET"), client_id=os.getenv("STROOP_REDDIT_ID") ) - self.r.read_only = True + self.reddit.read_only = True warnings.simplefilter("ignore") def get_emoji_embed(self, tag: str): @@ -43,7 +43,7 @@ class General(commands.Cog): await ctx.channel.send(ctx.author.mention, embed=em) def get_aww_post(self): - raww = self.r.subreddit('aww+catloaf+tuckedinkitties+babyelephantgifs+babybigcatgifs+blep+holdmynip+gingerkitty+cathighfive+catsstandingup+catsareassholes+eyebleach') + raww = self.reddit.subreddit('aww+catloaf+tuckedinkitties+babyelephantgifs+babybigcatgifs+blep+holdmynip+gingerkitty+cathighfive+catsstandingup+catsareassholes+eyebleach') listing = list(raww.top(time_filter='month')) return random.choice(listing) @@ -58,39 +58,29 @@ class General(commands.Cog): await ctx.channel.send(ctx.author.mention + ' ' + post.url) def get_kopieerpasta(self): - rkopieerpasta = self.r.subreddit('kopieerpasta') + rkopieerpasta = self.reddit.subreddit('kopieerpasta') try: - post = rkopieerpasta.random() - - # Subreddits kunnen de random functie uitzetten, dus dit is de fallback: - if post == None: - listing = list(rkopieerpasta.top(time_filter='month', limit=250)) - post = random.choice(listing) - - return post + post = random.choice(list(rkopieerpasta.top(time_filter='year', limit=100))) + if post != None: + return post except: return None - @commands.command(pass_context=True) + @commands.command() async def kopieerpasta(self, ctx): - """Een willekeurige shitpost""" - post = self.get_kopieerpasta() - if not post: - await ctx.channel.send("Geen kopieerpasta voor jou vandaag.") - return - print(post.url) - ATTEMPTS = 10 - a = 0 - while len(post.selftext + post.title) >= 1990 and a < ATTEMPTS: + """Een willekeurige kopieerpasta""" + post = None + for _ in range(10): post = self.get_kopieerpasta() - print(post.url) - a += 1 + if post and post.selftext and post.title and len(post.selftext + post.title) < 1990: + break + try: await ctx.message.delete() - except: - print("No permission to delete message") + except discord.HTTPException: + pass #boeie - if len(post.selftext + post.title) < 1990: + if post: await ctx.channel.send('**'+post.title+'**```'+post.selftext+'```') else: await ctx.channel.send("Geen kopieerpasta voor jou vandaag.") From 9d4ffc8effc89b2fac2fe1e431569c1ea7b94031 Mon Sep 17 00:00:00 2001 From: Guus Date: Wed, 28 Oct 2026 21:31:08 +0100 Subject: [PATCH 2/2] changed exception handling on message delete --- General.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/General.py b/General.py index 6e2b0b4..27043df 100644 --- a/General.py +++ b/General.py @@ -77,7 +77,7 @@ class General(commands.Cog): try: await ctx.message.delete() - except discord.HTTPException: + except: pass #boeie if post: