diff options
| author | 2019-10-01 18:29:47 -0700 | |
|---|---|---|
| committer | 2019-10-01 18:29:47 -0700 | |
| commit | f60f6044098a658f921357808353af6bfeb65465 (patch) | |
| tree | d17cbe464da57fe2e71a7d8e4bd719012ca0cbc6 | |
| parent | Add an optional icon_url parameter with a default to notify_infraction (diff) | |
Use has_active_infraction util function in superstarify
* Rename already_has_active_infraction to has_active_infraction
* Fit some lines in utils to 100 columns
| -rw-r--r-- | bot/cogs/moderation/infractions.py | 4 | ||||
| -rw-r--r-- | bot/cogs/moderation/superstarify.py | 14 | ||||
| -rw-r--r-- | bot/cogs/moderation/utils.py | 16 |
3 files changed, 15 insertions, 19 deletions
diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py index 85d29cbd8..5a93745ba 100644 --- a/bot/cogs/moderation/infractions.py +++ b/bot/cogs/moderation/infractions.py @@ -160,7 +160,7 @@ class Infractions(Scheduler, commands.Cog): async def apply_mute(self, ctx: Context, user: Member, reason: str, **kwargs) -> None: """Apply a mute infraction with kwargs passed to `post_infraction`.""" - if await utils.already_has_active_infraction(ctx, user, "mute"): + if await utils.has_active_infraction(ctx, user, "mute"): return infraction = await utils.post_infraction(ctx, user, "mute", reason, **kwargs) @@ -187,7 +187,7 @@ class Infractions(Scheduler, commands.Cog): @respect_role_hierarchy() async def apply_ban(self, ctx: Context, user: MemberObject, reason: str, **kwargs) -> None: """Apply a ban infraction with kwargs passed to `post_infraction`.""" - if await utils.already_has_active_infraction(ctx, user, "ban"): + if await utils.has_active_infraction(ctx, user, "ban"): return infraction = await utils.post_infraction(ctx, user, "ban", reason, **kwargs) diff --git a/bot/cogs/moderation/superstarify.py b/bot/cogs/moderation/superstarify.py index e5c89e5b5..ccd163a88 100644 --- a/bot/cogs/moderation/superstarify.py +++ b/bot/cogs/moderation/superstarify.py @@ -154,19 +154,7 @@ class Superstarify(Cog): If no reason is given, the original name will be shown in a generated reason. """ - active_superstarifies = await self.bot.api_client.get( - 'bot/infractions', - params={ - 'active': 'true', - 'type': 'superstar', - 'user__id': str(member.id) - } - ) - if active_superstarifies: - await ctx.send( - ":x: According to my records, this user is already superstarified. " - f"See infraction **#{active_superstarifies[0]['id']}**." - ) + if await utils.has_active_infraction(ctx, member, "superstar"): return infraction = await utils.post_infraction( diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py index a4e258d11..c8d350b99 100644 --- a/bot/cogs/moderation/utils.py +++ b/bot/cogs/moderation/utils.py @@ -29,7 +29,11 @@ Infraction = t.Dict[str, t.Union[str, int, bool]] def proxy_user(user_id: str) -> discord.Object: - """Create a proxy user for the provided user_id for situations where a Member or User object cannot be resolved.""" + """ + Create a proxy user object from the given id. + + Used when a Member or User object cannot be resolved. + """ try: user_id = int(user_id) except ValueError: @@ -71,7 +75,9 @@ async def post_infraction( f"{ctx.author} tried to add a {type} infraction to `{user.id}`, " "but that user id was not found in the database." ) - await ctx.send(f":x: Cannot add infraction, the specified user is not known to the database.") + await ctx.send( + f":x: Cannot add infraction, the specified user is not known to the database." + ) return else: log.exception("An unexpected ResponseCodeError occurred while adding an infraction:") @@ -81,7 +87,7 @@ async def post_infraction( return response -async def already_has_active_infraction(ctx: Context, user: MemberObject, type: str) -> bool: +async def has_active_infraction(ctx: Context, user: MemberObject, type: str) -> bool: """Checks if a user already has an active infraction of the given type.""" active_infractions = await ctx.bot.api_client.get( 'bot/infractions', @@ -123,7 +129,9 @@ async def notify_infraction( embed.url = RULES_URL if infr_type in APPEALABLE_INFRACTIONS: - embed.set_footer(text="To appeal this infraction, send an e-mail to [email protected]") + embed.set_footer( + text="To appeal this infraction, send an e-mail to [email protected]" + ) return await send_private_embed(user, embed) |