Corrected the logic when nothing is found in the database; changed some exceptions
This commit is contained in:
parent
60ed33fa15
commit
dbfff6e01d
3
bot.py
3
bot.py
|
@ -39,7 +39,6 @@ logging.basicConfig(level=logging.INFO, filename='bonfire.log')
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("We have connected")
|
|
||||||
# Change the status upon connection to the default status
|
# Change the status upon connection to the default status
|
||||||
await bot.change_status(discord.Game(name=config.default_status, type=0))
|
await bot.change_status(discord.Game(name=config.default_status, type=0))
|
||||||
channel_id = await config.get_content('restart_server') or 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__':
|
if __name__ == '__main__':
|
||||||
print("Loading extensions")
|
|
||||||
for e in extensions:
|
for e in extensions:
|
||||||
bot.load_extension(e)
|
bot.load_extension(e)
|
||||||
print("Running bot")
|
|
||||||
bot.run(config.bot_token)
|
bot.run(config.bot_token)
|
||||||
|
|
|
@ -22,9 +22,7 @@ async def channel_online(channel: str):
|
||||||
try:
|
try:
|
||||||
data = json.loads(response)
|
data = json.loads(response)
|
||||||
return data['stream'] is not None
|
return data['stream'] is not None
|
||||||
except KeyError:
|
except (KeyError, json.JSONDecodeError):
|
||||||
return False
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,7 @@ def custom_perms(**perms):
|
||||||
perm_values = loop.run_until_complete(config.get_content('custom_permissions'))
|
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_value = perm_values[ctx.message.server.id][ctx.command.qualified_name]
|
||||||
required_perm = discord.Permissions(required_perm_value)
|
required_perm = discord.Permissions(required_perm_value)
|
||||||
except KeyError:
|
except (KeyError, TypeError):
|
||||||
required_perm = default_perms
|
|
||||||
except TypeError:
|
|
||||||
required_perm = default_perms
|
required_perm = default_perms
|
||||||
return member_perms >= required_perm
|
return member_perms >= required_perm
|
||||||
|
|
||||||
|
|
|
@ -79,11 +79,11 @@ async def get_content(key: str):
|
||||||
# Just connect to the database
|
# Just connect to the database
|
||||||
opts = {'host': db_host, 'db': db_name, 'port': db_port, 'ssl': {'ca_certs': db_cert}}
|
opts = {'host': db_host, 'db': db_name, 'port': db_port, 'ssl': {'ca_certs': db_cert}}
|
||||||
conn = await r.connect(**opts)
|
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
|
# We should only ever get one result, so use it if it exists, otherwise return none
|
||||||
try:
|
try:
|
||||||
|
cursor = await r.table(key).run(conn)
|
||||||
items = list(cursor.items)[0]
|
items = list(cursor.items)[0]
|
||||||
except IndexError:
|
except (IndexError, r.ReqlOpFailedError):
|
||||||
return None
|
return None
|
||||||
# Rethink db stores an internal id per table, delete this and return the rest
|
# Rethink db stores an internal id per table, delete this and return the rest
|
||||||
del items['id']
|
del items['id']
|
||||||
|
|
Loading…
Reference in a new issue