diff options
author | 2019-09-26 21:07:12 -0700 | |
---|---|---|
committer | 2019-10-01 18:25:31 -0700 | |
commit | a320d5b7cfac5bf841d6029be83ae6e4a0db19f6 (patch) | |
tree | efb174c0d10af7b3e0a2324d9f8cdfd3751901fe | |
parent | Use None for default values for notify_infraction's parameters (diff) |
Refactor user type annotations in moderation cog
* Rename the UserTypes alias to UserConverter
* Create a new non-converter alias similar to UserConverter which has
Object instead of the proxy_user converter in the Union.
* Use the new alias in the utility functions instead of just a Union of
a Member and User.
-rw-r--r-- | bot/cogs/moderation.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 3162a9a5d..ca46ccef2 100644 --- a/bot/cogs/moderation.py +++ b/bot/cogs/moderation.py @@ -53,7 +53,8 @@ def permanent_duration(expires_at: str) -> str: return expires_at -UserTypes = Union[Member, User, proxy_user] +UserConverter = Union[Member, User, proxy_user] +UserObject = Union[Member, User, Object] Infraction = Dict[str, Union[str, int, bool]] @@ -85,7 +86,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command() - async def warn(self, ctx: Context, user: UserTypes, *, reason: str = None) -> None: + async def warn(self, ctx: Context, user: UserConverter, *, reason: str = None) -> None: """Create a warning infraction in the database for a user.""" infraction = await post_infraction(ctx, user, type="warning", reason=reason) if infraction is None: @@ -164,7 +165,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command() @respect_role_hierarchy() - async def ban(self, ctx: Context, user: UserTypes, *, reason: str = None) -> None: + async def ban(self, ctx: Context, user: UserConverter, *, reason: str = None) -> None: """Create a permanent ban infraction for a user with the provided reason.""" if await already_has_active_infraction(ctx=ctx, user=user, type="ban"): return @@ -277,7 +278,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command() @respect_role_hierarchy() - async def tempban(self, ctx: Context, user: UserTypes, duration: Duration, *, reason: str = None) -> None: + async def tempban(self, ctx: Context, user: UserConverter, duration: Duration, *, reason: str = None) -> None: """ Create a temporary ban infraction for a user with the provided expiration and reason. @@ -343,7 +344,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command(hidden=True) - async def note(self, ctx: Context, user: UserTypes, *, reason: str = None) -> None: + async def note(self, ctx: Context, user: UserConverter, *, reason: str = None) -> None: """ Create a private infraction note in the database for a user with the provided reason. @@ -415,7 +416,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command(hidden=True, aliases=['shadowban', 'sban']) @respect_role_hierarchy() - async def shadow_ban(self, ctx: Context, user: UserTypes, *, reason: str = None) -> None: + async def shadow_ban(self, ctx: Context, user: UserConverter, *, reason: str = None) -> None: """ Create a permanent ban infraction for a user with the provided reason. @@ -509,7 +510,7 @@ class Moderation(Scheduler, Cog): @command(hidden=True, aliases=["shadowtempban, stempban"]) @respect_role_hierarchy() async def shadow_tempban( - self, ctx: Context, user: UserTypes, duration: Duration, *, reason: str = None + self, ctx: Context, user: UserConverter, duration: Duration, *, reason: str = None ) -> None: """ Create a temporary ban infraction for a user with the provided reason. @@ -568,7 +569,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command() - async def unmute(self, ctx: Context, user: UserTypes) -> None: + async def unmute(self, ctx: Context, user: UserConverter) -> None: """Deactivates the active mute infraction for a user.""" try: # check the current active infraction @@ -646,7 +647,7 @@ class Moderation(Scheduler, Cog): @with_role(*MODERATION_ROLES) @command() - async def unban(self, ctx: Context, user: UserTypes) -> None: + async def unban(self, ctx: Context, user: UserConverter) -> None: """Deactivates the active ban infraction for a user.""" try: # check the current active infraction @@ -974,7 +975,7 @@ class Moderation(Scheduler, Cog): async def notify_infraction( self, - user: Union[User, Member], + user: UserObject, infr_type: str, expires_at: Optional[str] = None, reason: Optional[str] = None @@ -1007,7 +1008,7 @@ class Moderation(Scheduler, Cog): async def notify_pardon( self, - user: Union[User, Member], + user: UserObject, title: str, content: str, icon_url: str = Icons.user_verified @@ -1026,7 +1027,7 @@ class Moderation(Scheduler, Cog): return await self.send_private_embed(user, embed) - async def send_private_embed(self, user: Union[User, Member], embed: Embed) -> bool: + async def send_private_embed(self, user: UserObject, embed: Embed) -> bool: """ A helper method for sending an embed to a user's DMs. |