From cbf8d01b8feeddb686b27b4f1007b410f7ee48f2 Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 19:35:15 -0400 Subject: [PATCH 1/6] Update to current Discord.py --- bot.py | 10 +++++++--- requirements.txt | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 3f4373f..31af111 100644 --- a/bot.py +++ b/bot.py @@ -3,12 +3,17 @@ import json import cfg +intents = discord.Intents.default() +intents.message_content=True + + bot = commands.Bot( command_prefix=cfg.bot['prefix'], description=cfg.bot['description'], owner_id=cfg.bot['owner'], activity=discord.Game(name=cfg.bot['game'], type=0), - case_insensitive=True + case_insensitive=True, + intents=intents ) @bot.event @@ -16,7 +21,6 @@ async def on_ready(): print('Logged in as') print(bot.user.name) print(bot.user.id) - print("Has nitro: " + str(bot.user.premium)) print("prefix: {}".format(cfg.bot['prefix'])) print('------') @@ -36,4 +40,4 @@ async def on_message(message): cogName = 'cogs.{}'.format(cog) print('loading: {}'.format(cogName)) bot.load_extension(cogName) - bot.run(cfg.bot['token'], bot=True, reconnect=True) \ No newline at end of file + bot.run(cfg.bot['token'], reconnect=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d40c3e1..34711e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -git+https://github.com/Rapptz/discord.py@rewrite -pillow==5.1.0 +discord.py +pillow>=10.0.0 requests>=2.19 \ No newline at end of file From 6175604b07e8495dfb5d119eb02d0af68a1ce546 Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 19:43:32 -0400 Subject: [PATCH 2/6] Better on_ready print --- bot.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 31af111..0044db8 100644 --- a/bot.py +++ b/bot.py @@ -18,11 +18,7 @@ @bot.event async def on_ready(): - print('Logged in as') - print(bot.user.name) - print(bot.user.id) - print("prefix: {}".format(cfg.bot['prefix'])) - print('------') + print(f'Logged in as {bot.user.name}({bot.user.id}) with prefix {cfg.bot['prefix']}\n-----') @bot.event async def on_message(message): From ebf53f2fb40444208c445f8e6d4bc9f3f599dd1f Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 20:14:16 -0400 Subject: [PATCH 3/6] Fix "invalid escapes" --- cogs/fun.py | 2 +- cogs/rain.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/fun.py b/cogs/fun.py index 32a1d0e..b34082e 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -167,7 +167,7 @@ async def roll(self, ctx, *, expression=""): # voodoo magic regex (matches A,dB,AdB,AdBrC and AdBh/lD all at once, and splits them up to be processed) - m = re.findall('(-?)((?:(\d*)d(\d+))|\d+)(r\d+)?([h,l]{1}\d+)?', parts[0]) + m = re.findall('(-?)((?:(\\d*)d(\\d+))|\\d+)(r\\d+)?([h,l]{1}\\d+)?', parts[0]) if not m: # either no arguments, or the expression contained nothing that could be seen as a number or roll return await ctx.send("Expression missing. If you are unsure of what the format should be, please use `{}help roll`".format(ctx.prefix),delete_after=15) diff --git a/cogs/rain.py b/cogs/rain.py index 942d0c1..5517e82 100644 --- a/cogs/rain.py +++ b/cogs/rain.py @@ -9,7 +9,7 @@ import time makeNull = re.compile('[,.?!"\';:&]||||') -nameNull = re.compile('[,.?!"\';:&]|\(.*\)') +nameNull = re.compile('[,.?!"\';:&]|\\(.*\\)') makeSpace = {'\n',' ',' '}## th replacing double space with space, twice is to remove multi spaces where there was a situation of [space][punctuation][space] def stipPunc(t): From aec2e91512b6dc53f28b0e3ff9f9dfc17c73c97d Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 20:14:42 -0400 Subject: [PATCH 4/6] Update cogs and cog loader to be async --- bot.py | 24 +++++++++++++++++++----- cogs/custom.py | 4 ++-- cogs/dev.py | 2 +- cogs/fun.py | 4 ++-- cogs/guess.py | 4 ++-- cogs/rain.py | 4 ++-- cogs/search.py | 4 ++-- cogs/test.py | 4 ++-- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/bot.py b/bot.py index 0044db8..c3994ee 100644 --- a/bot.py +++ b/bot.py @@ -31,9 +31,23 @@ async def on_message(message): message.author.discriminator = -1 return await bot.process_commands(message) -if __name__ == "__main__": +@bot.event +async def on_command_error(ctx,err): + if ('Command ' in str(err)) and (' is not found' in str(err)): + return await ctx.message.add_reaction('❓') + print(f'[ERROR] {err}') + return await ctx.message.add_reaction('❗') + +@bot.event +async def setup_hook(): + for cog in cfg.cogs: - cogName = 'cogs.{}'.format(cog) - print('loading: {}'.format(cogName)) - bot.load_extension(cogName) - bot.run(cfg.bot['token'], reconnect=True) \ No newline at end of file + cogName = f'cogs.{cog}' + print(f'loading: {cogName}') + await bot.load_extension(cogName) + + + + + +if __name__ == "__main__": bot.run(cfg.bot['token'], reconnect=True) \ No newline at end of file diff --git a/cogs/custom.py b/cogs/custom.py index 9d3ed4c..b6b16d2 100644 --- a/cogs/custom.py +++ b/cogs/custom.py @@ -238,5 +238,5 @@ async def clear(self, ctx, num:int=1): await m.delete() return await ctx.send('cleared {} messages'.format(num)) -def setup(bot): - bot.add_cog(Custom(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Custom(bot)) \ No newline at end of file diff --git a/cogs/dev.py b/cogs/dev.py index 60a7773..04761e6 100644 --- a/cogs/dev.py +++ b/cogs/dev.py @@ -44,5 +44,5 @@ async def say(self, ctx, *, convert): await ctx.send(convert) return await ctx.message.delete() -def setup(bot): +async def setup(bot): bot.add_cog(Dev(bot)) \ No newline at end of file diff --git a/cogs/fun.py b/cogs/fun.py index b34082e..b8cf278 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -267,5 +267,5 @@ def take_first(ele): return await ctx.send('I\'m not sure what on earth you\'ve done here, but the rolls post is to long to print. <:facepalmy:263144001777958913>') return await ctx.send(response) -def setup(bot): - bot.add_cog(Fun(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Fun(bot)) \ No newline at end of file diff --git a/cogs/guess.py b/cogs/guess.py index 4349206..0930780 100644 --- a/cogs/guess.py +++ b/cogs/guess.py @@ -150,5 +150,5 @@ async def highscore(self, ctx): text = text + '\nUnkown user:\t{}'.format(value) return await ctx.send(text) -def setup(bot): - bot.add_cog(Guess(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Guess(bot)) \ No newline at end of file diff --git a/cogs/rain.py b/cogs/rain.py index 5517e82..666aec5 100644 --- a/cogs/rain.py +++ b/cogs/rain.py @@ -201,5 +201,5 @@ async def update(self, ctx): self.makeIndexs() return await ctx.send(resp) -def setup(bot): - bot.add_cog(Rain(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Rain(bot)) \ No newline at end of file diff --git a/cogs/search.py b/cogs/search.py index bef2981..c32c25c 100644 --- a/cogs/search.py +++ b/cogs/search.py @@ -66,5 +66,5 @@ async def wa(self, ctx, *, search): return await ctx.send('**Result:**\n'+'\n\n'.join(plaintext)) return await ctx.send('I\'m sorry {}. I\'m afraid I can\'t do that :confused:\nSomething went wrong'.format(ctx.author.display_name),delete_after=5) -def setup(bot): - bot.add_cog(Search(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Search(bot)) \ No newline at end of file diff --git a/cogs/test.py b/cogs/test.py index 09ab9f2..8c00e69 100644 --- a/cogs/test.py +++ b/cogs/test.py @@ -20,5 +20,5 @@ async def no(self, ctx): em = discord.Embed(title="No way", description='I disagree', colour=cfg.colors['red']) return await ctx.send(embed=em) -def setup(bot): - bot.add_cog(Test(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Test(bot)) \ No newline at end of file From 61a2dc5dddc256b25ebbbc5dbb0bee2a8d4e74ea Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 20:54:23 -0400 Subject: [PATCH 5/6] Prettify rain search output --- cogs/rain.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cogs/rain.py b/cogs/rain.py index 666aec5..4b11079 100644 --- a/cogs/rain.py +++ b/cogs/rain.py @@ -59,8 +59,8 @@ def genPage(self,i): async def rain(self, ctx): """A group of commands to lookup updates from the rain comic.""" if ctx.invoked_subcommand is None: - return await ctx.send('Missing Argument: use `cf (number)` `da (code)` or `latest`\nAlternatively use {comand prefix}help rain for a more indepth help',delete_after=10) - + return await ctx.send(f'Missing Subcommand! Use `{cfg.bot.prefix}help rain` to list all sub-commands!',delete_after=10) + @rain.command() async def cf(self, ctx, *, page): """ @@ -71,14 +71,12 @@ async def cf(self, ctx, *, page): This will only work for pages in the bots page list you can use the latest command to check if the list is up to date """ - page = int(page) - if page in self.dex['CF']: - output = self.genPage(self.dex['CF'][page]) - em = discord.Embed(title=self.ref[self.dex['CF'][page]]['Page Title'], description=output, colour=cfg.colors['green']) + if page := self.dex['CF'][int(page)]: + output = self.genPage(page) + em = discord.Embed(title=self.ref[page]['Page Title'], description=output, colour=cfg.colors['green']) return await ctx.send(embed=em) - else: - em = discord.Embed(title="Error", description="Unable to find an update with that number", colour=cfg.colors['red']) - return await ctx.send(embed=em,delete_after=5) + em = discord.Embed(title="Error", description="Unable to find an update with that number", colour=cfg.colors['red']) + return await ctx.send(embed=em,delete_after=5) @rain.command() async def da(self, ctx, *, page): @@ -136,10 +134,7 @@ async def search(self, ctx, *, Query): i+=2 continue if Query[i]=='"': - if inQuotes: - inQuotes=False - else: - inQuotes=True + inQuotes=not inQuotes if Query[i]==' ' and not inQuotes: #this is both an end of term and a start(if ) if startI 10: - output.append('Too many pages to list, showing first 10') - for j in range(10): - output.append(' http://rain.thecomicseries.com/comics/{}'.format(self.ref[results[j]]['CF page'])) - else: - for result in results: - output.append(' http://rain.thecomicseries.com/comics/{}'.format(self.ref[result]['CF page'])) + char_count = 0 + i=0 + for result in results: + ref = self.ref[result] + name = ref['Page Title'] + if not name :name = f'Page {ref['CF page']}' + formatted_text = f'[{name}](http://rain.thecomicseries.com/comics/{ref['CF page']})' + char_count+=len(formatted_text) + if(char_count>1600): + output.append(f'{len(results)-i} more...') + break + i+=1 + output.append(formatted_text) stopTime = time.perf_counter() - em = discord.Embed(title='found {} results, in {}ms'.format(len(results),int((stopTime-startTime)*1000)), description='\n'.join(output), colour=cfg.colors['green']) + em = discord.Embed(title=f'Found {len(results)} results, in {int((stopTime-startTime)*1000)}ms', description=', '.join(output), colour=cfg.colors['green']) return await ctx.send(embed=em) @rain.command() From 4ad94e7ca875db597393b1928bf4dfeeadd5db57 Mon Sep 17 00:00:00 2001 From: Steph <38338700+superpowers04@users.noreply.github.com> Date: Fri, 15 May 2026 21:00:35 -0400 Subject: [PATCH 6/6] Slightly cleaner code --- bot.py | 2 +- cogs/rain.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index c3994ee..157c8bb 100644 --- a/bot.py +++ b/bot.py @@ -18,7 +18,7 @@ @bot.event async def on_ready(): - print(f'Logged in as {bot.user.name}({bot.user.id}) with prefix {cfg.bot['prefix']}\n-----') + print(f'Logged in as "{bot.user.name}"({bot.user.id}) with prefix "{cfg.bot['prefix']}"\n-----') @bot.event async def on_message(message): diff --git a/cogs/rain.py b/cogs/rain.py index 4b11079..e425c1c 100644 --- a/cogs/rain.py +++ b/cogs/rain.py @@ -154,8 +154,9 @@ async def search(self, ctx, *, Query): print(Cquery,Tquery) results = [] for j, page in enumerate(self.ref): - if Cquery:#char search first as its fast - if ('chars' not in page) or (not Cquery.issubset(page['chars'])): + #char search first as its fast + if Cquery: + if not ('chars' in page and Cquery.issubset(page['chars'])): continue good=True if Tquery:#word search @@ -169,20 +170,22 @@ async def search(self, ctx, *, Query): results.append(j) output=[] char_count = 0 - i=0 - for result in results: + for i, result in enumerate(results): ref = self.ref[result] name = ref['Page Title'] - if not name :name = f'Page {ref['CF page']}' + if not name: name = f'Page {ref['CF page']}' formatted_text = f'[{name}](http://rain.thecomicseries.com/comics/{ref['CF page']})' char_count+=len(formatted_text) if(char_count>1600): output.append(f'{len(results)-i} more...') break - i+=1 output.append(formatted_text) stopTime = time.perf_counter() - em = discord.Embed(title=f'Found {len(results)} results, in {int((stopTime-startTime)*1000)}ms', description=', '.join(output), colour=cfg.colors['green']) + em = discord.Embed( + title=f'Found {len(results)} results in {int((stopTime-startTime)*1000)}ms', + description=', '.join(output), + colour=cfg.colors['green'] + ) return await ctx.send(embed=em) @rain.command()