Merge branch 'master' of https://github.com/Phxntxm/Bonfire
This commit is contained in:
commit
2284049af0
43
bot.py
43
bot.py
|
@ -91,14 +91,53 @@ async def on_message(message):
|
|||
return
|
||||
await bot.process_commands(message)
|
||||
|
||||
@bot.event
|
||||
async def on_command_completion(command, ctx):
|
||||
# There's no reason to continue waiting for this to complete, so lets immediately lanch this in a new future
|
||||
bot.loop.create_task(process_command(command, ctx))
|
||||
|
||||
async def process_command(command, ctx):
|
||||
# This try catch is only here while this is first being implemented
|
||||
# It will be removed once I ensure this is working correctly
|
||||
try:
|
||||
author = ctx.message.author
|
||||
server = ctx.message.server
|
||||
|
||||
total_command_usage = await config.get_content('command_usage')
|
||||
command_usage = total_command_usage.get(command.qualified_name, {})
|
||||
# Add one to the total usage for this command, basing it off 0 to start with (obviously)
|
||||
total_usage = command_usage.get('total_usage', 0) + 1
|
||||
command_usage['total_usage'] = total_usage
|
||||
|
||||
# Add one to the author's usage for this command
|
||||
total_member_usage = command_usage.get('member_usage',{})
|
||||
member_usage = total_member_usage.get(author.id, 0) + 1
|
||||
command_usage['member_usage'] = member_usage
|
||||
|
||||
# Add one to the server's usage for this command
|
||||
total_server_usage = command_usage.get('server_usage', {})
|
||||
server_usage = total_server_usage.get(server.id, 0) + 1
|
||||
command_usage['server_usage'] = server_usage
|
||||
|
||||
# Save all the changes
|
||||
total_command_usage[command.qualified_name] = command_usage
|
||||
await config.save_content('command_usage', total_command_usage)
|
||||
except Exception as error:
|
||||
with open("error_log", 'a') as f:
|
||||
traceback.print_tb(error.__traceback__, file=f)
|
||||
print('{0.__class__.__name__}: {0}'.format(error), file=f)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(error, ctx):
|
||||
if isinstance(error, commands.CommandNotFound):
|
||||
return
|
||||
if error.original and isinstance(error.original, discord.Forbidden):
|
||||
return
|
||||
try:
|
||||
if isinstance(error.original, discord.Forbidden):
|
||||
return
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if isinstance(error, commands.BadArgument):
|
||||
fmt = "Please provide a valid argument to pass to the command: {}".format(error)
|
||||
await bot.send_message(ctx.message.channel, fmt)
|
||||
|
|
|
@ -104,7 +104,7 @@ class Links:
|
|||
else:
|
||||
# If no search term was provided, search for a random image
|
||||
async with self.session.get('https://derpibooru.org/images/random') as r:
|
||||
# .url will be the URl we end up at, not the one requested.
|
||||
# .url will be the URl we end up at, not the one requested.
|
||||
# https://derpibooru.org/images/random redirects to a random image, so this is exactly what we want
|
||||
image_link = r.url
|
||||
await self.bot.say(image_link)
|
||||
|
@ -138,16 +138,16 @@ class Links:
|
|||
async with self.session.get(url, headers=self.headers) as r:
|
||||
data = await r.json()
|
||||
|
||||
# Check if there were any results, if there are find a random image based on the length of results
|
||||
if len(data) == 0:
|
||||
await self.bot.say("No results with that image {}".format(ctx.message.author.mention))
|
||||
return
|
||||
else:
|
||||
if len(data) == 1:
|
||||
rand_image = data[0]['file_url']
|
||||
else:
|
||||
# Try to find an image from the list. If there were no results, we're going to attempt to find
|
||||
# A number between (0,-1) and receive an error.
|
||||
# The response should be in a list format, so we'll end up getting a key error if the response was in json
|
||||
# i.e. it responded with a 404/504/etc.
|
||||
try:
|
||||
rand_image = data[random.SystemRandom().randint(0, len(data) - 1)]['file_url']
|
||||
await self.bot.say(rand_image)
|
||||
await self.bot.say(rand_image)
|
||||
except (ValueError, KeyError):
|
||||
await self.bot.say("No results with that tag {}".format(ctx.message.author.mention))
|
||||
return
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
|
|
@ -98,7 +98,7 @@ class Twitch:
|
|||
member = ctx.message.author
|
||||
|
||||
twitch_channels = await config.get_content('twitch')
|
||||
result = twitch_channels.get(ctx.message.author.id)
|
||||
result = twitch_channels.get(member.id)
|
||||
if result is None:
|
||||
await self.bot.say("{} has not saved their twitch URL yet!".format(member.name))
|
||||
return
|
||||
|
|
|
@ -22,7 +22,7 @@ def custom_perms(**perms):
|
|||
setattr(default_perms, perm, setting)
|
||||
|
||||
try:
|
||||
perm_values = config.cache.get('custom_permissions')
|
||||
perm_values = config.cache.get('custom_permissions').values
|
||||
required_perm_value = perm_values[ctx.message.server.id][ctx.command.qualified_name]
|
||||
required_perm = discord.Permissions(required_perm_value)
|
||||
except (KeyError, TypeError):
|
||||
|
|
Loading…
Reference in a new issue