1
0
Fork 0
mirror of synced 2024-06-22 16:20:23 +12:00

Corrected the logic when nothing is found in the database; changed some exceptions

This commit is contained in:
phxntxm 2016-08-30 19:23:07 -05:00
parent 60ed33fa15
commit dbfff6e01d
4 changed files with 4 additions and 11 deletions

3
bot.py
View file

@ -39,7 +39,6 @@ logging.basicConfig(level=logging.INFO, filename='bonfire.log')
@bot.event
async def on_ready():
print("We have connected")
# Change the status upon connection to the default status
await bot.change_status(discord.Game(name=config.default_status, type=0))
channel_id = await config.get_content('restart_server') or 0
@ -122,8 +121,6 @@ async def on_command_error(error, ctx):
if __name__ == '__main__':
print("Loading extensions")
for e in extensions:
bot.load_extension(e)
print("Running bot")
bot.run(config.bot_token)

View file

@ -22,9 +22,7 @@ async def channel_online(channel: str):
try:
data = json.loads(response)
return data['stream'] is not None
except KeyError:
return False
except json.JSONDecodeError:
except (KeyError, json.JSONDecodeError):
return False

View file

@ -25,9 +25,7 @@ def custom_perms(**perms):
perm_values = loop.run_until_complete(config.get_content('custom_permissions'))
required_perm_value = perm_values[ctx.message.server.id][ctx.command.qualified_name]
required_perm = discord.Permissions(required_perm_value)
except KeyError:
required_perm = default_perms
except TypeError:
except (KeyError, TypeError):
required_perm = default_perms
return member_perms >= required_perm

View file

@ -79,11 +79,11 @@ async def get_content(key: str):
# Just connect to the database
opts = {'host': db_host, 'db': db_name, 'port': db_port, 'ssl': {'ca_certs': db_cert}}
conn = await r.connect(**opts)
cursor = await r.table(key).run(conn)
# We should only ever get one result, so use it if it exists, otherwise return none
try:
cursor = await r.table(key).run(conn)
items = list(cursor.items)[0]
except IndexError:
except (IndexError, r.ReqlOpFailedError):
return None
# Rethink db stores an internal id per table, delete this and return the rest
del items['id']