From 6336244dd40ed06af41f582abc97674799cb95b5 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Mon, 11 Jul 2016 12:05:38 -0500 Subject: [PATCH] Testing error on twitch loop --- cogs/twitch.py | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/cogs/twitch.py b/cogs/twitch.py index 9a68d05..6be3927 100644 --- a/cogs/twitch.py +++ b/cogs/twitch.py @@ -16,27 +16,34 @@ def channelOnline(channel: str): async def checkChannels(bot): - await bot.wait_until_ready() - cursor = config.getCursor() - cursor.execute('use {}'.format(config.db_default)) - cursor.execute('select * from twitch') - result = cursor.fetchall() - for r in result: - server = discord.utils.find(lambda s: s.id == r['server_id'], bot.servers) - member = discord.utils.find(lambda m: m.id == r['user_id'], server.members) - url = r['twitch_url'] - live = int(r['live']) - notify = int(r['notifications_on']) - user = re.search("(?<=twitch.tv/)(.*)", url).group(1) - if not live and notify and channelOnline(user): - cursor.execute('update twitch set live=1 where user_id="{}"'.format(r['user_id'])) - await bot.send_message(server, "{} has just gone live! View their stream at {}".format(member.name, url)) - elif live and not channelOnline(user): - cursor.execute('update twitch set live=0 where user_id="{}"'.format(r['user_id'])) - await bot.send_message(server, "{} has just gone offline! Catch them next time they stream at {}" - .format(member.name, url)) - config.closeConnection() - await asyncio.sleep(60) + try: + await bot.wait_until_ready() + cursor = config.getCursor() + cursor.execute('use {}'.format(config.db_default)) + cursor.execute('select * from twitch') + result = cursor.fetchall() + for r in result: + server = discord.utils.find(lambda s: s.id == r['server_id'], bot.servers) + member = discord.utils.find(lambda m: m.id == r['user_id'], server.members) + url = r['twitch_url'] + live = int(r['live']) + notify = int(r['notifications_on']) + user = re.search("(?<=twitch.tv/)(.*)", url).group(1) + if not live and notify and channelOnline(user): + cursor.execute('update twitch set live=1 where user_id="{}"'.format(r['user_id'])) + await bot.send_message(server, "{} has just gone live! View their stream at {}".format(member.name, url)) + elif live and not channelOnline(user): + cursor.execute('update twitch set live=0 where user_id="{}"'.format(r['user_id'])) + await bot.send_message(server, "{} has just gone offline! Catch them next time they stream at {}" + .format(member.name, url)) + config.closeConnection() + await asyncio.sleep(60) + except Exception as e: + + server = discord.utils.find(lambda s: s.id == "183662839741939712", bot.servers) + channel = discord.utils.find(lambda c: c.id == "184201951381028864", server.channels) + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await bot.send_message(, fmt.format(type(error).__name__, error)) class Twitch: