aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar PureFunctor <[email protected]>2020-10-03 15:43:51 +0800
committerGravatar PureFunctor <[email protected]>2020-10-03 15:43:51 +0800
commit1ae9b15d7718d7e2f96b4406de99b89f1778b971 (patch)
treec49e0f3ce5ae0e7215fc4a5739ac57cf00c7359a
parentAdd Infraction converter (diff)
Refactor infraction_edit and infraction_append
This refactors the infraction_edit and infraction_append commands to utilize the Infraction converter.
-rw-r--r--bot/exts/moderation/infraction/management.py47
1 files changed, 15 insertions, 32 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index 2cb9bce8b..8aeb45f96 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -10,7 +10,7 @@ from discord.utils import escape_markdown
from bot import constants
from bot.bot import Bot
-from bot.converters import Expiry, Snowflake, UserMention, allowed_strings, proxy_user
+from bot.converters import Expiry, Infraction, Snowflake, UserMention, allowed_strings, proxy_user
from bot.exts.moderation.infraction.infractions import Infractions
from bot.exts.moderation.modlog import ModLog
from bot.pagination import LinePaginator
@@ -49,7 +49,7 @@ class ModManagement(commands.Cog):
async def infraction_append(
self,
ctx: Context,
- infraction_id: t.Union[int, allowed_strings("l", "last", "recent")], # noqa: F821
+ infraction: Infraction, # noqa: F821
duration: t.Union[Expiry, allowed_strings("p", "permanent"), None], # noqa: F821
*,
reason: str = None
@@ -73,29 +73,21 @@ class ModManagement(commands.Cog):
Use "p" or "permanent" to mark the infraction as permanent. Alternatively, an ISO 8601
timestamp can be provided for the duration.
"""
- if isinstance(infraction_id, str):
- old_infraction = await self.get_latest_infraction(ctx.author.id)
-
- if old_infraction is None:
- await ctx.send(
- ":x: Couldn't find most recent infraction; you have never given an infraction."
- )
- return
-
- infraction_id = old_infraction["id"]
-
- else:
- old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}")
-
- reason = fr"{old_infraction['reason']} **\|\|** {reason}"
+ if not infraction:
+ return
- await self.infraction_edit(infraction_id=infraction_id, duration=duration, reason=reason)
+ await self.infraction_edit(
+ ctx=ctx,
+ infraction=infraction,
+ duration=duration,
+ reason=fr"{infraction['reason']} **\|\|** {reason}",
+ )
@infraction_group.command(name='edit')
async def infraction_edit(
self,
ctx: Context,
- infraction_id: t.Union[int, allowed_strings("l", "last", "recent")], # noqa: F821
+ infraction: Infraction, # noqa: F821
duration: t.Union[Expiry, allowed_strings("p", "permanent"), None], # noqa: F821
*,
reason: str = None
@@ -123,20 +115,11 @@ class ModManagement(commands.Cog):
# Unlike UserInputError, the error handler will show a specified message for BadArgument
raise commands.BadArgument("Neither a new expiry nor a new reason was specified.")
- # Retrieve the previous infraction for its information.
- if isinstance(infraction_id, str):
- old_infraction = await self.get_latest_infraction(ctx.author.id)
-
- if old_infraction is None:
- await ctx.send(
- ":x: Couldn't find most recent infraction; you have never given an infraction."
- )
- return
-
- infraction_id = old_infraction["id"]
+ if not infraction:
+ return
- else:
- old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}")
+ old_infraction = infraction
+ infraction_id = infraction["id"]
request_data = {}
confirm_messages = []