From dbfff6e01dea2a5274f06dd8bb890b400ae8176a Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 30 Aug 2016 19:23:07 -0500 Subject: [PATCH] Corrected the logic when nothing is found in the database; changed some exceptions --- bot.py | 3 --- cogs/twitch.py | 4 +--- cogs/utils/checks.py | 4 +--- cogs/utils/config.py | 4 ++-- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index 84b28fc..684bfc6 100644 --- a/bot.py +++ b/bot.py @@ -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) diff --git a/cogs/twitch.py b/cogs/twitch.py index 207f0cc..2a1f96c 100644 --- a/cogs/twitch.py +++ b/cogs/twitch.py @@ -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 diff --git a/cogs/utils/checks.py b/cogs/utils/checks.py index d74a650..7f78e21 100644 --- a/cogs/utils/checks.py +++ b/cogs/utils/checks.py @@ -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 diff --git a/cogs/utils/config.py b/cogs/utils/config.py index d8cc588..a552be3 100644 --- a/cogs/utils/config.py +++ b/cogs/utils/config.py @@ -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']