From f2a88cbf94336c2be6a699afee3b12facfe8f056 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Sat, 6 Jul 2024 11:46:13 -0400 Subject: [PATCH] fix(aurora): fixed an AttributeError --- aurora/models/moderation_types.py | 21 +++++++++------------ aurora/models/type.py | 24 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/aurora/models/moderation_types.py b/aurora/models/moderation_types.py index 066236f..3921b2f 100644 --- a/aurora/models/moderation_types.py +++ b/aurora/models/moderation_types.py @@ -21,9 +21,8 @@ def get_icon(bot: Red) -> File: @type_registry.register(key="ban") class Ban(Type): - def __init__(self) -> None: - self.type="ban" - self.verb="banned" + moderation_type="ban" + verb="banned" @classmethod async def handler(cls, ctx: commands.Context, target: Member | User, silent: bool, reason: str = None, delete_messages: app_commands.Choice | None = None) -> 'Ban': @@ -49,7 +48,7 @@ class Ban(Type): await bot.get_embed_color(ctx.channel), ctx.guild, reason, - cls.type, + cls(), ctx.author, None, response_message @@ -63,7 +62,7 @@ class Ban(Type): bot, ctx.guild.id, ctx.author.id, - cls.type, + cls.moderation_type, 'USER', target.id, None, @@ -76,7 +75,7 @@ class Ban(Type): return cls @classmethod - async def resolve_handler(cls, bot: Red, guild: Guild, target: Member, reason: str): + async def resolve_handler(cls, bot: Red, guild: Guild, target: Member | User, reason: str | None = None) -> None: try: await guild.fetch_ban(user=target) except NotFound: @@ -100,10 +99,8 @@ class Ban(Type): @type_registry.register(key="tempban") class Tempban(Ban): - def __init__(self) -> None: - super().__init__() - self.type="tempban" - self.verb="tempbanned" + moderation_type="tempban" + verb="tempbanned" @classmethod async def handler(cls, ctx: commands.Context, target: Member | User, silent: bool, duration: str, reason: str = None, delete_messages: app_commands.Choice | None = None) -> 'Ban': @@ -137,7 +134,7 @@ class Tempban(Ban): await bot.get_embed_color(ctx.channel), ctx.guild, reason, - cls.type, + cls(), ctx.author, parsed_time, response_message @@ -151,7 +148,7 @@ class Tempban(Ban): bot, ctx.guild.id, ctx.author.id, - cls.type, + cls.moderation_type, 'USER', target.id, None, diff --git a/aurora/models/type.py b/aurora/models/type.py index 87689ec..cc7ec61 100644 --- a/aurora/models/type.py +++ b/aurora/models/type.py @@ -1,13 +1,15 @@ -from discord import Member, User +from typing import Any + +from discord import Guild, Member, User from redbot.core import commands +from redbot.core.bot import Red class Type(object): - def __init__(self) -> None: - self.type = None - self.verb = None - self.embed_desc = "been" + moderation_type = None + verb = None + embed_desc = "been" def __str__(self) -> str: return self.type @@ -16,3 +18,15 @@ class Type(object): async def handler(cls, ctx: commands.Context, target: Member | User, silent: bool, **kwargs) -> 'Type': # pylint: disable=unused-argument """This method should be overridden by any child classes, but should retain the same starting keyword arguments.""" raise NotImplementedError + + @classmethod + async def resolve_handler(cls, bot: Red, guild: Guild, target: Member | User, reason: str | None = None) -> Any: # pylint: disable=unused-argument + """This method should be overridden by any resolvable child classes, but should retain the same keyword arguments. + If your moderation type should not be resolvable, do not override this.""" + raise NotImplementedError + + @classmethod + async def expiry_handler(cls, bot: Red, guild: Guild, target: Member | User) -> Any: # pylint: disable=unused-argument + """This method should be overridden by any expirable child classes, but should retain the same keyword arguments. + If your moderation type should not expire, do not override this.""" + raise NotImplementedError