From c82aa6a0f50307d801f54b30e08699ca429a4723 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Mon, 12 Aug 2024 20:33:37 -0400 Subject: [PATCH] fix(aurora): catch an attribute error --- aurora/aurora.py | 105 ++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index a5dc168..6118b2c 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -113,7 +113,7 @@ class Aurora(commands.Cog): self.handle_expiry.cancel() @commands.Cog.listener("on_guild_join") - async def db_generate_guild_join(self, guild: discord.Guild): + async def db_generate_on_guild_join(self, guild: discord.Guild): """This method prepares the database schema whenever the bot joins a guild.""" if not await self.bot.cog_disabled_in_guild(self, guild): try: @@ -135,58 +135,61 @@ class Aurora(commands.Cog): @commands.Cog.listener("on_audit_log_entry_create") async def autologger(self, entry: discord.AuditLogEntry): """This method automatically logs moderations done by users manually ("right clicks").""" - if not await self.bot.cog_disabled_in_guild(self, entry.guild): - if await config.guild(entry.guild).ignore_other_bots() is True: - if entry.user.bot or entry.target.bot: - return - else: - if entry.user.id == self.bot.user.id: - return - - duration = None - - if entry.reason: - reason = entry.reason + " (This action was performed without the bot.)" - - else: - reason = "This action was performed without the bot." - - if entry.action == discord.AuditLogAction.kick: - moderation_type = "KICK" - - elif entry.action == discord.AuditLogAction.ban: - moderation_type = "BAN" - - elif entry.action == discord.AuditLogAction.unban: - moderation_type = "UNBAN" - - elif entry.action == discord.AuditLogAction.member_update: - if entry.after.timed_out_until is not None: - timed_out_until_aware = entry.after.timed_out_until.replace( - tzinfo=timezone.utc - ) - duration_datetime = timed_out_until_aware - datetime.now( - tz=timezone.utc - ) - minutes = round(duration_datetime.total_seconds() / 60) - duration = timedelta(minutes=minutes) - moderation_type = "MUTE" + try: + if not await self.bot.cog_disabled_in_guild(self, entry.guild): + if await config.guild(entry.guild).ignore_other_bots() is True: + if entry.user.bot or entry.target.bot: + return else: - moderation_type = "UNMUTE" - else: - return + if entry.user.id == self.bot.user.id: + return - await Moderation.log( - self.bot, - entry.guild.id, - entry.user.id, - moderation_type, - "USER", - entry.target.id, - None, - duration, - reason, - ) + duration = None + + if entry.reason: + reason = entry.reason + " (This action was performed without the bot.)" + + else: + reason = "This action was performed without the bot." + + if entry.action == discord.AuditLogAction.kick: + moderation_type = "KICK" + + elif entry.action == discord.AuditLogAction.ban: + moderation_type = "BAN" + + elif entry.action == discord.AuditLogAction.unban: + moderation_type = "UNBAN" + + elif entry.action == discord.AuditLogAction.member_update: + if entry.after.timed_out_until is not None: + timed_out_until_aware = entry.after.timed_out_until.replace( + tzinfo=timezone.utc + ) + duration_datetime = timed_out_until_aware - datetime.now( + tz=timezone.utc + ) + minutes = round(duration_datetime.total_seconds() / 60) + duration = timedelta(minutes=minutes) + moderation_type = "MUTE" + else: + moderation_type = "UNMUTE" + else: + return + + await Moderation.log( + self.bot, + entry.guild.id, + entry.user.id, + moderation_type, + "USER", + entry.target.id, + None, + duration, + reason, + ) + except AttributeError: + return ####################################################################################################################### ### COMMANDS