Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
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
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('------')
print(f'Logged in as "{bot.user.name}"({bot.user.id}) with prefix "{cfg.bot['prefix']}"\n-----')

@bot.event
async def on_message(message):
Expand All @@ -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'], bot=True, reconnect=True)
cogName = f'cogs.{cog}'
print(f'loading: {cogName}')
await bot.load_extension(cogName)





if __name__ == "__main__": bot.run(cfg.bot['token'], reconnect=True)
4 changes: 2 additions & 2 deletions cogs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
async def setup(bot):
await bot.add_cog(Custom(bot))
2 changes: 1 addition & 1 deletion cogs/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 3 additions & 3 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
async def setup(bot):
await bot.add_cog(Fun(bot))
4 changes: 2 additions & 2 deletions cogs/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
async def setup(bot):
await bot.add_cog(Guess(bot))
59 changes: 31 additions & 28 deletions cogs/rain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time

makeNull = re.compile('[,.?!"\';:&]|<b>|</b>|<i>|</i>')
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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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<i:
Expand All @@ -148,6 +143,7 @@ async def search(self, ctx, *, Query):
i+=1
if startI<i:
terms.append(Query[startI:i])

Cquery = set()
Tquery = []
for term in terms:
Expand All @@ -158,10 +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:
continue
if 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
Expand All @@ -174,15 +169,23 @@ async def search(self, ctx, *, Query):
if good:
results.append(j)
output=[]
if len(results) > 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
for i, result in enumerate(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
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()
Expand All @@ -201,5 +204,5 @@ async def update(self, ctx):
self.makeIndexs()
return await ctx.send(resp)

def setup(bot):
bot.add_cog(Rain(bot))
async def setup(bot):
await bot.add_cog(Rain(bot))
4 changes: 2 additions & 2 deletions cogs/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
async def setup(bot):
await bot.add_cog(Search(bot))
4 changes: 2 additions & 2 deletions cogs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
async def setup(bot):
await bot.add_cog(Test(bot))
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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