From 0fcd51958aad54de3b19b576af851cd150f11050 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Mon, 31 Jul 2017 20:39:10 -0500 Subject: [PATCH] Removal of default_channel --- cogs/birthday.py | 8 ++++---- cogs/events.py | 8 ++++---- cogs/picarto.py | 7 ++----- cogs/raffle.py | 6 ++---- cogs/twitch.py | 7 ++----- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/cogs/birthday.py b/cogs/birthday.py index 8c5b429..460b255 100644 --- a/cogs/birthday.py +++ b/cogs/birthday.py @@ -73,16 +73,16 @@ class Birthday: bds = self.get_birthdays_for_server(server, today=True) for bd in bds: - # Set our default to either the one set, or the default channel of the server - default_channel_id = s.get('notifications', {}).get('default') or server.id + # Set our default to either the one set + default_channel_id = s.get('notifications', {}).get('default') # If it is has been overriden by picarto notifications setting, use this channel_id = s.get('notifications', {}).get('birthday') or default_channel_id # Now get the channel based on that ID - channel = server.get_channel(int(channel_id)) or server.default_channel + channel = server.get_channel(int(channel_id)) try: await channel.send("It is {}'s birthday today! " "Wish them a happy birthday! \N{SHORTCAKE}".format(bd['member'].mention)) - except (discord.Forbidden, discord.HTTPException): + except (discord.Forbidden, discord.HTTPException, AttributeError): pass @commands.group(aliases=['birthdays'], invoke_without_command=True) diff --git a/cogs/events.py b/cogs/events.py index 2d2c0c9..66218ec 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -63,7 +63,7 @@ class StatsUpdate: # Get the notifications settings, get the welcome setting notifications = self.bot.db.load('server_settings', key=guild.id, pluck='notifications') or {} # Set our default to either the one set, or the default channel of the server - default_channel_id = notifications.get('default') or guild.id + default_channel_id = notifications.get('default') # If it is has been overriden by picarto notifications setting, use this channel_id = notifications.get('welcome') or default_channel_id # Get the message if it exists @@ -78,7 +78,7 @@ class StatsUpdate: channel = guild.get_channel(int(channel_id)) try: await channel.send(join_message.format(server=guild.name, member=member.mention)) - except (discord.Forbidden, discord.HTTPException): + except (discord.Forbidden, discord.HTTPException, AttributeError): pass async def on_member_remove(self, member): @@ -91,7 +91,7 @@ class StatsUpdate: # Get the notifications settings, get the welcome setting notifications = self.bot.db.load('server_settings', key=guild.id, pluck='notifications') or {} # Set our default to either the one set, or the default channel of the server - default_channel_id = notifications.get('default') or guild.id + default_channel_id = notifications.get('default') # If it is has been overriden by picarto notifications setting, use this channel_id = notifications.get('welcome') or default_channel_id # Get the message if it exists @@ -106,7 +106,7 @@ class StatsUpdate: channel = guild.get_channel(int(channel_id)) try: await channel.send(leave_message.format(server=guild.name, member=member.name)) - except (discord.Forbidden, discord.HTTPException): + except (discord.Forbidden, discord.HTTPException, AttributeError): pass diff --git a/cogs/picarto.py b/cogs/picarto.py index e7c8777..cfebbff 100644 --- a/cogs/picarto.py +++ b/cogs/picarto.py @@ -107,19 +107,16 @@ class Picarto: # Get the notifications settings, get the picarto setting notifications = self.bot.db.load('server_settings', key=s_id, pluck='notifications') or {} # Set our default to either the one set, or the default channel of the server - default_channel_id = notifications.get('default') or s_id + default_channel_id = notifications.get('default') # If it is has been overriden by picarto notifications setting, use this channel_id = notifications.get('picarto') or default_channel_id # Now get the channel channel = server.get_channel(int(channel_id)) - # Unfortunately we need one more check, to ensure a channel hasn't been chosen, then deleted - if channel is None: - channel = server.default_channel # Then just send our message try: await channel.send(msg.format(member=member), embed=embed) - except (discord.Forbidden, discord.HTTPException): + except (discord.Forbidden, discord.HTTPException, AttributeError): pass await asyncio.sleep(30) diff --git a/cogs/raffle.py b/cogs/raffle.py index 3e9e55a..1602936 100644 --- a/cogs/raffle.py +++ b/cogs/raffle.py @@ -74,13 +74,11 @@ class Raffle: # Get the notifications settings, get the raffle setting notifications = self.bot.db.load('server_settings', key=server.id, pluck='notifications') or {} - # Set our default to either the one set, or the default channel of the server - default_channel_id = notifications.get('default') or server.id + # Set our default to either the one set + default_channel_id = notifications.get('default') # If it is has been overriden by picarto notifications setting, use this channel_id = notifications.get('raffle') or default_channel_id channel = self.bot.get_channel(int(channel_id)) - if channel is None: - channel = server.default_channel try: await channel.send(fmt) except (discord.Forbidden, AttributeError): diff --git a/cogs/twitch.py b/cogs/twitch.py index 049a5f1..33a2d58 100644 --- a/cogs/twitch.py +++ b/cogs/twitch.py @@ -119,19 +119,16 @@ class Twitch: # Get the notifications settings, get the twitch setting notifications = self.bot.db.load('server_settings', key=s_id, pluck='notifications') or {} # Set our default to either the one set, or the default channel of the server - default_channel_id = notifications.get('default') or s_id + default_channel_id = notifications.get('default') # If it is has been overriden by twitch notifications setting, use this channel_id = notifications.get('twitch') or default_channel_id # Now get the channel channel = server.get_channel(int(channel_id)) - # Unfortunately we need one more check, to ensure a channel hasn't been chosen, then deleted - if channel is None: - channel = server.default_channel # Then just send our message try: await channel.send(msg.format(member=member), embed=embed) - except (discord.Forbidden, discord.HTTPException): + except (discord.Forbidden, discord.HTTPException, AttributeError): pass await asyncio.sleep(30)