From db5cf7d18d6992165abc15cd27ed50a4713af124 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 16:26:29 +0800 Subject: Add append subcommand for infraction group --- bot/exts/moderation/infraction/management.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index de4fb4175..4e31947d4 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -45,6 +45,56 @@ class ModManagement(commands.Cog): """Infraction manipulation commands.""" await ctx.send_help(ctx.command) + @infraction_group.command(name="append", aliases=("amend", "add")) + async def infraction_append( + self, + ctx: Context, + infraction_id: t.Union[int, allowed_strings("l", "last", "recent")], # noqa: F821 + duration: t.Union[Expiry, allowed_strings("p", "permanent"), None], # noqa: F821 + *, + reason: str = None + ) -> None: + """ + Append text and/or edit the duration of an infraction. + + Durations are relative to the time of updating and should be appended with a unit of time. + Units (∗case-sensitive): + \u2003`y` - years + \u2003`m` - months∗ + \u2003`w` - weeks + \u2003`d` - days + \u2003`h` - hours + \u2003`M` - minutes∗ + \u2003`s` - seconds + + Use "l", "last", or "recent" as the infraction ID to specify that the most recent infraction + authored by the command invoker should be edited. + + 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): + params = { + "actor__id": ctx.author.id, + "ordering": "-inserted_at" + } + infractions = await self.bot.api_client.get("bot/infractions", params=params) + + if infractions: + old_infraction = infractions[0] + infraction_id = old_infraction["id"] + else: + await ctx.send( + ":x: Couldn't find most recent infraction; you have never given an infraction." + ) + return + else: + old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}") + + reason = f"{old_infraction['reason']} **Edit:** {reason}" + + await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) + @infraction_group.command(name='edit') async def infraction_edit( self, -- cgit v1.2.3 From f9971be6251dc083332c2adc4bffb746f2c8ccf2 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 17:05:22 +0800 Subject: Add get_latest_infraction utility function --- bot/exts/moderation/infraction/management.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 4e31947d4..7596d2ec1 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -338,6 +338,20 @@ class ModManagement(commands.Cog): return lines.strip() + async def get_latest_infraction(self, actor: int) -> t.Optional[dict]: + """Obtains the latest infraction from an actor.""" + params = { + "actor__id": actor, + "ordering": "-inserted_at" + } + + infractions = await self.bot.api_client.get("bot/infractions", params=params) + + if infractions: + return infractions[0] + + return None + # endregion # This cannot be static (must have a __func__ attribute). -- cgit v1.2.3 From 1ab0084581859a0d8e938b9292bdb86ce9caf523 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 17:11:21 +0800 Subject: Refactor routine for obtaining latest infraction --- bot/exts/moderation/infraction/management.py | 36 +++++++++++----------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 7596d2ec1..b841b11c3 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -74,20 +74,16 @@ class ModManagement(commands.Cog): timestamp can be provided for the duration. """ if isinstance(infraction_id, str): - params = { - "actor__id": ctx.author.id, - "ordering": "-inserted_at" - } - infractions = await self.bot.api_client.get("bot/infractions", params=params) - - if infractions: - old_infraction = infractions[0] - infraction_id = old_infraction["id"] - else: - await ctx.send( + old_infraction = await self.get_latest_infraction(ctx.author.id) + + if old_infraction is None: + 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}") @@ -129,20 +125,16 @@ class ModManagement(commands.Cog): # Retrieve the previous infraction for its information. if isinstance(infraction_id, str): - params = { - "actor__id": ctx.author.id, - "ordering": "-inserted_at" - } - infractions = await self.bot.api_client.get("bot/infractions", params=params) - - if infractions: - old_infraction = infractions[0] - infraction_id = old_infraction["id"] - else: - await ctx.send( + old_infraction = await self.get_latest_infraction(ctx.author.id) + + if old_infraction is None: + 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}") -- cgit v1.2.3 From 4ce59c673c035550ba4f2e55e79faba17002d40c Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 17:46:10 +0800 Subject: Fix unawaited coroutine --- bot/exts/moderation/infraction/management.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index b841b11c3..e35ebcbef 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -77,7 +77,7 @@ class ModManagement(commands.Cog): old_infraction = await self.get_latest_infraction(ctx.author.id) if old_infraction is None: - ctx.send( + await ctx.send( ":x: Couldn't find most recent infraction; you have never given an infraction." ) return @@ -128,7 +128,7 @@ class ModManagement(commands.Cog): old_infraction = await self.get_latest_infraction(ctx.author.id) if old_infraction is None: - ctx.send( + await ctx.send( ":x: Couldn't find most recent infraction; you have never given an infraction." ) return -- cgit v1.2.3 From abbb62a0720f68cbd0a0226f4abeb9c3b337de3c Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 17:47:50 +0800 Subject: Add "a" alias for append --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index e35ebcbef..78dc16b23 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -45,7 +45,7 @@ class ModManagement(commands.Cog): """Infraction manipulation commands.""" await ctx.send_help(ctx.command) - @infraction_group.command(name="append", aliases=("amend", "add")) + @infraction_group.command(name="append", aliases=("amend", "add", "a")) async def infraction_append( self, ctx: Context, -- cgit v1.2.3 From 1dd93784d09baf73a670621f22b96c24ffb6c762 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 17:55:03 +0800 Subject: Add visual buffer for appended reason --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 78dc16b23..ba1485978 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -87,7 +87,7 @@ class ModManagement(commands.Cog): else: old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}") - reason = f"{old_infraction['reason']} **Edit:** {reason}" + reason = f"{old_infraction['reason']} || **Edit:** {reason}" await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) -- cgit v1.2.3 From b65c64575f12ddee57bd6bf9bfaffafe6131890a Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 24 Sep 2020 18:59:50 +0800 Subject: Make vertical bar separators escaped --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index ba1485978..bdb0e8ffa 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -87,7 +87,7 @@ class ModManagement(commands.Cog): else: old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}") - reason = f"{old_infraction['reason']} || **Edit:** {reason}" + reason = fr"{old_infraction['reason']} \|\| **Edit:** {reason}" await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) -- cgit v1.2.3 From 84671acaeb251939722a9b93f217b6256637a998 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 27 Sep 2020 13:30:32 +0800 Subject: Remove prefix when appending a reason --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index bdb0e8ffa..6b3e701c7 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -87,7 +87,7 @@ class ModManagement(commands.Cog): else: old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}") - reason = fr"{old_infraction['reason']} \|\| **Edit:** {reason}" + reason = fr"{old_infraction['reason']} \|\| {reason}" await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) -- cgit v1.2.3 From e18893760b115600b7b03a60ce5bfb80e59fb882 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 1 Oct 2020 04:01:58 +0800 Subject: Add bold styling for vertical bar separators --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 6b3e701c7..1cdcf6568 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -87,7 +87,7 @@ class ModManagement(commands.Cog): else: old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}") - reason = fr"{old_infraction['reason']} \|\| {reason}" + reason = fr"{old_infraction['reason']} **\|\|** {reason}" await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) -- cgit v1.2.3 From c1b46ecc916970ec95e267f017958d30e4773c2a Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 3 Oct 2020 12:52:24 +0800 Subject: Invoke infraction_edit directly with method call --- bot/exts/moderation/infraction/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 1cdcf6568..2cb9bce8b 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -89,7 +89,7 @@ class ModManagement(commands.Cog): reason = fr"{old_infraction['reason']} **\|\|** {reason}" - await ctx.invoke(self.infraction_edit, infraction_id=infraction_id, duration=duration, reason=reason) + await self.infraction_edit(infraction_id=infraction_id, duration=duration, reason=reason) @infraction_group.command(name='edit') async def infraction_edit( -- cgit v1.2.3 From 2de1a6a4091234703d99a26ad2884b586d7204f4 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 3 Oct 2020 15:42:23 +0800 Subject: Add Infraction converter This adds the Infraction converter to be used in infraction_edit and infraction_append. --- bot/converters.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bot/converters.py b/bot/converters.py index 2e118d476..962416238 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -549,6 +549,36 @@ def _snowflake_from_regex(pattern: t.Pattern, arg: str) -> int: return int(match.group(1)) +class Infraction(Converter): + """ + Attempts to convert a given infraction ID into an infraction. + + Alternatively, `l`, `last`, or `recent` can be passed in order to + obtain the most recent infraction by the actor. + """ + + async def convert(self, ctx: Context, arg: str) -> t.Optional[dict]: + """Attempts to convert `arg` into an infraction `dict`.""" + if arg in ("l", "last", "recent"): + params = { + "actor__id": ctx.author.id, + "ordering": "-inserted_at" + } + + infractions = await ctx.bot.api_client.get("bot/infractions", params=params) + + if not infractions: + await ctx.send( + ":x: Couldn't find most recent infraction; you have never given an infraction." + ) + return None + + return infractions[0] + + else: + return ctx.bot.api_client.get(f"bot/infractions/{arg}") + + Expiry = t.Union[Duration, ISODateTime] FetchedMember = t.Union[discord.Member, FetchedUser] UserMention = partial(_snowflake_from_regex, RE_USER_MENTION) -- cgit v1.2.3 From 1ae9b15d7718d7e2f96b4406de99b89f1778b971 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 3 Oct 2020 15:43:51 +0800 Subject: Refactor infraction_edit and infraction_append This refactors the infraction_edit and infraction_append commands to utilize the Infraction converter. --- bot/exts/moderation/infraction/management.py | 47 +++++++++------------------- 1 file 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 = [] -- cgit v1.2.3 From 472faca4b19419f1101258c876fc5fbbd7da8f3a Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 8 Nov 2020 15:03:46 +0800 Subject: Remove unnecessary noqa pragma for flake8 --- bot/exts/moderation/infraction/management.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 8aeb45f96..97fc7b1d8 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -49,7 +49,7 @@ class ModManagement(commands.Cog): async def infraction_append( self, ctx: Context, - infraction: Infraction, # noqa: F821 + infraction: Infraction, duration: t.Union[Expiry, allowed_strings("p", "permanent"), None], # noqa: F821 *, reason: str = None @@ -87,7 +87,7 @@ class ModManagement(commands.Cog): async def infraction_edit( self, ctx: Context, - infraction: Infraction, # noqa: F821 + infraction: Infraction, duration: t.Union[Expiry, allowed_strings("p", "permanent"), None], # noqa: F821 *, reason: str = None -- cgit v1.2.3 From 3e73fd76d73b7e84888af46e0b6b47a1dd4003d3 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 8 Nov 2020 15:16:30 +0800 Subject: Raise BadArgument in the Infraction converter --- bot/converters.py | 9 ++++----- bot/exts/moderation/infraction/management.py | 6 ------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/bot/converters.py b/bot/converters.py index 962416238..f350e863e 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -568,12 +568,11 @@ class Infraction(Converter): infractions = await ctx.bot.api_client.get("bot/infractions", params=params) if not infractions: - await ctx.send( - ":x: Couldn't find most recent infraction; you have never given an infraction." + raise BadArgument( + "Couldn't find most recent infraction; you have never given an infraction." ) - return None - - return infractions[0] + else: + return infractions[0] else: return ctx.bot.api_client.get(f"bot/infractions/{arg}") diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 97fc7b1d8..49ddfa473 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -73,9 +73,6 @@ 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 not infraction: - return - await self.infraction_edit( ctx=ctx, infraction=infraction, @@ -115,9 +112,6 @@ 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.") - if not infraction: - return - old_infraction = infraction infraction_id = infraction["id"] -- cgit v1.2.3 From de0b6984cc1947f5454939b4e20a09e6eeaffa98 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 8 Nov 2020 15:23:03 +0800 Subject: Refactor redundant code in infraction_edit --- bot/exts/moderation/infraction/management.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 49ddfa473..88b2f98c6 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -112,14 +112,13 @@ 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.") - old_infraction = infraction infraction_id = infraction["id"] request_data = {} confirm_messages = [] log_text = "" - if duration is not None and not old_infraction['active']: + if duration is not None and not infraction['active']: if reason is None: await ctx.send(":x: Cannot edit the expiration of an expired infraction.") return @@ -138,7 +137,7 @@ class ModManagement(commands.Cog): request_data['reason'] = reason confirm_messages.append("set a new reason") log_text += f""" - Previous reason: {old_infraction['reason']} + Previous reason: {infraction['reason']} New reason: {reason} """.rstrip() else: @@ -153,7 +152,7 @@ class ModManagement(commands.Cog): # Re-schedule infraction if the expiration has been updated if 'expires_at' in request_data: # A scheduled task should only exist if the old infraction wasn't permanent - if old_infraction['expires_at']: + if infraction['expires_at']: self.infractions_cog.scheduler.cancel(new_infraction['id']) # If the infraction was not marked as permanent, schedule a new expiration task @@ -161,7 +160,7 @@ class ModManagement(commands.Cog): self.infractions_cog.schedule_expiration(new_infraction) log_text += f""" - Previous expiry: {old_infraction['expires_at'] or "Permanent"} + Previous expiry: {infraction['expires_at'] or "Permanent"} New expiry: {new_infraction['expires_at'] or "Permanent"} """.rstrip() -- cgit v1.2.3 From af7cfd35945f7885a7cd36490aa0ffcf91218c8b Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 8 Nov 2020 16:03:11 +0800 Subject: Automatically add periods as visual buffers --- bot/exts/moderation/infraction/management.py | 17 +++++++++++------ bot/utils/regex.py | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 88b2f98c6..e6513c32d 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -16,6 +16,7 @@ from bot.exts.moderation.modlog import ModLog from bot.pagination import LinePaginator from bot.utils import messages, time from bot.utils.checks import in_whitelist_check +from bot.utils.regex import END_PUNCTUATION_RE log = logging.getLogger(__name__) @@ -72,13 +73,17 @@ 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 a previous infraction reason does not end with an ending punctuation mark, this automatically + adds a period before the amended reason. """ - await self.infraction_edit( - ctx=ctx, - infraction=infraction, - duration=duration, - reason=fr"{infraction['reason']} **\|\|** {reason}", - ) + add_period = not END_PUNCTUATION_RE.match(infraction["reason"]) + + new_reason = "".join(( + infraction["reason"], ". " if add_period else " ", reason, + )) + + await self.infraction_edit(ctx, infraction, duration, reason=new_reason) @infraction_group.command(name='edit') async def infraction_edit( diff --git a/bot/utils/regex.py b/bot/utils/regex.py index 0d2068f90..cfce52bb3 100644 --- a/bot/utils/regex.py +++ b/bot/utils/regex.py @@ -10,3 +10,5 @@ INVITE_RE = re.compile( r"([a-zA-Z0-9\-]+)", # the invite code itself flags=re.IGNORECASE ) + +END_PUNCTUATION_RE = re.compile("^.+?[.?!]$") -- cgit v1.2.3 From 6204906c734e0f0d44f7c1c544fbf4eb2443acc8 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Tue, 24 Nov 2020 21:56:34 +0300 Subject: Adds VoiceChannels and Related Chats to Config Updates config-default.yml to include voice channels, and the text chat channel they map to. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- bot/constants.py | 7 +++++++ config-default.yml | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 6bb6aacd2..ecbf5f98e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -398,6 +398,9 @@ class Channels(metaclass=YAMLGetter): change_log: int code_help_voice: int code_help_voice_2: int + general_voice: int + admins_voice: int + staff_voice: int cooldown: int defcon: int dev_contrib: int @@ -430,7 +433,11 @@ class Channels(metaclass=YAMLGetter): user_event_announcements: int user_log: int verification: int + code_help_chat: int + code_help_chat_2: int voice_chat: int + admins_voice_chat: int + staff_voice_chat: int voice_gate: int voice_log: int diff --git a/config-default.yml b/config-default.yml index 60eb437af..8ba3b7175 100644 --- a/config-default.yml +++ b/config-default.yml @@ -196,10 +196,17 @@ guild: mod_announcements: &MOD_ANNOUNCEMENTS 372115205867700225 admin_announcements: &ADMIN_ANNOUNCEMENTS 749736155569848370 - # Voice - code_help_voice: 755154969761677312 - code_help_voice_2: 766330079135268884 + # Voice Chat + code_help_chat: 755154969761677312 + code_help_chat_2: 766330079135268884 voice_chat: 412357430186344448 + admins_voice_chat: 000000000000000000 # FIXME + staff_voice_chat: 541638762007101470 + + # Voice Channels + code_help_voice: 751592231726481530 + code_help_voice_2: 764232549840846858 + general_voice: 751591688538947646 admins_voice: &ADMINS_VOICE 500734494840717332 staff_voice: &STAFF_VOICE 412375055910043655 -- cgit v1.2.3 From fde6dd9a37cf5f5a98eed7ffcb05f43dca6886a3 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 28 Nov 2020 21:18:13 +0300 Subject: Removes Non-Existent Channel Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- bot/constants.py | 1 - config-default.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index ecbf5f98e..5b3779eb6 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -436,7 +436,6 @@ class Channels(metaclass=YAMLGetter): code_help_chat: int code_help_chat_2: int voice_chat: int - admins_voice_chat: int staff_voice_chat: int voice_gate: int voice_log: int diff --git a/config-default.yml b/config-default.yml index 8ba3b7175..563244819 100644 --- a/config-default.yml +++ b/config-default.yml @@ -200,7 +200,6 @@ guild: code_help_chat: 755154969761677312 code_help_chat_2: 766330079135268884 voice_chat: 412357430186344448 - admins_voice_chat: 000000000000000000 # FIXME staff_voice_chat: 541638762007101470 # Voice Channels -- cgit v1.2.3 From cd8b4b91fbfe69b9370fec1a89dc82688f7d317b Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 28 Nov 2020 21:19:34 +0300 Subject: Renames Code Help Channel Renames code_help_channel to be more inline with channel 2. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- bot/constants.py | 4 ++-- config-default.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 5b3779eb6..42b3d7008 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -396,7 +396,7 @@ class Channels(metaclass=YAMLGetter): big_brother_logs: int bot_commands: int change_log: int - code_help_voice: int + code_help_voice_1: int code_help_voice_2: int general_voice: int admins_voice: int @@ -433,7 +433,7 @@ class Channels(metaclass=YAMLGetter): user_event_announcements: int user_log: int verification: int - code_help_chat: int + code_help_chat_1: int code_help_chat_2: int voice_chat: int staff_voice_chat: int diff --git a/config-default.yml b/config-default.yml index 563244819..f18d08126 100644 --- a/config-default.yml +++ b/config-default.yml @@ -197,13 +197,13 @@ guild: admin_announcements: &ADMIN_ANNOUNCEMENTS 749736155569848370 # Voice Chat - code_help_chat: 755154969761677312 + code_help_chat_1: 755154969761677312 code_help_chat_2: 766330079135268884 voice_chat: 412357430186344448 staff_voice_chat: 541638762007101470 # Voice Channels - code_help_voice: 751592231726481530 + code_help_voice_1: 751592231726481530 code_help_voice_2: 764232549840846858 general_voice: 751591688538947646 admins_voice: &ADMINS_VOICE 500734494840717332 -- cgit v1.2.3 From d190056ac6fa39ac54b4eafc566c2f05fc0b6f8e Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 28 Nov 2020 21:48:51 +0300 Subject: Fixes Alignment Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- config-default.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config-default.yml b/config-default.yml index f18d08126..df3d971ff 100644 --- a/config-default.yml +++ b/config-default.yml @@ -197,13 +197,13 @@ guild: admin_announcements: &ADMIN_ANNOUNCEMENTS 749736155569848370 # Voice Chat - code_help_chat_1: 755154969761677312 + code_help_chat_1: 755154969761677312 code_help_chat_2: 766330079135268884 voice_chat: 412357430186344448 staff_voice_chat: 541638762007101470 # Voice Channels - code_help_voice_1: 751592231726481530 + code_help_voice_1: 751592231726481530 code_help_voice_2: 764232549840846858 general_voice: 751591688538947646 admins_voice: &ADMINS_VOICE 500734494840717332 -- cgit v1.2.3 From 114e3058ca18cf45a55d7dcdf7d509de44d7ad1a Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 28 Nov 2020 23:52:30 +0300 Subject: Alphabetizes Channel Ordering Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- bot/constants.py | 12 ++++++------ config-default.yml | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 42b3d7008..a33939537 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -391,16 +391,16 @@ class Channels(metaclass=YAMLGetter): admin_announcements: int admin_spam: int admins: int + admins_voice: int announcements: int attachment_log: int big_brother_logs: int bot_commands: int change_log: int + code_help_chat_1: int + code_help_chat_2: int code_help_voice_1: int code_help_voice_2: int - general_voice: int - admins_voice: int - staff_voice: int cooldown: int defcon: int dev_contrib: int @@ -408,6 +408,7 @@ class Channels(metaclass=YAMLGetter): dev_log: int dm_log: int esoteric: int + general_voice: int helpers: int how_to_get_help: int incidents: int @@ -429,14 +430,13 @@ class Channels(metaclass=YAMLGetter): python_news: int reddit: int staff_announcements: int + staff_voice: int + staff_voice_chat: int talent_pool: int user_event_announcements: int user_log: int verification: int - code_help_chat_1: int - code_help_chat_2: int voice_chat: int - staff_voice_chat: int voice_gate: int voice_log: int diff --git a/config-default.yml b/config-default.yml index df3d971ff..9dc1ac18e 100644 --- a/config-default.yml +++ b/config-default.yml @@ -196,19 +196,19 @@ guild: mod_announcements: &MOD_ANNOUNCEMENTS 372115205867700225 admin_announcements: &ADMIN_ANNOUNCEMENTS 749736155569848370 - # Voice Chat - code_help_chat_1: 755154969761677312 - code_help_chat_2: 766330079135268884 - voice_chat: 412357430186344448 - staff_voice_chat: 541638762007101470 - # Voice Channels + admins_voice: &ADMINS_VOICE 500734494840717332 code_help_voice_1: 751592231726481530 code_help_voice_2: 764232549840846858 general_voice: 751591688538947646 - admins_voice: &ADMINS_VOICE 500734494840717332 staff_voice: &STAFF_VOICE 412375055910043655 + # Voice Chat + code_help_chat_1: 755154969761677312 + code_help_chat_2: 766330079135268884 + staff_voice_chat: 541638762007101470 + voice_chat: 412357430186344448 + # Watch big_brother_logs: &BB_LOGS 468507907357409333 talent_pool: &TALENT_POOL 534321732593647616 -- cgit v1.2.3 From 65366ead766fa6533fe6c59310a39ca3ee3a06b2 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Mon, 30 Nov 2020 00:47:34 +0800 Subject: Fix unawaited coroutine in Infraction --- bot/converters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/converters.py b/bot/converters.py index f350e863e..d0a9731d6 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -575,7 +575,7 @@ class Infraction(Converter): return infractions[0] else: - return ctx.bot.api_client.get(f"bot/infractions/{arg}") + return await ctx.bot.api_client.get(f"bot/infractions/{arg}") Expiry = t.Union[Duration, ISODateTime] -- cgit v1.2.3 From db2136cd5bd1b86b05f249177e7a68a731404d16 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Mon, 30 Nov 2020 00:49:47 +0800 Subject: Refactor flow for automatically adding punctuation --- bot/exts/moderation/infraction/management.py | 11 +++++------ bot/utils/regex.py | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index bb7a6737a..10bca5fc5 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -16,7 +16,6 @@ from bot.exts.moderation.modlog import ModLog from bot.pagination import LinePaginator from bot.utils import messages, time from bot.utils.channel import is_mod_channel -from bot.utils.regex import END_PUNCTUATION_RE log = logging.getLogger(__name__) @@ -77,13 +76,13 @@ class ModManagement(commands.Cog): If a previous infraction reason does not end with an ending punctuation mark, this automatically adds a period before the amended reason. """ - add_period = not END_PUNCTUATION_RE.match(infraction["reason"]) + old_reason = infraction["reason"] - new_reason = "".join(( - infraction["reason"], ". " if add_period else " ", reason, - )) + if old_reason is not None: + add_period = not old_reason.endswith((".", "!", "?")) + reason = old_reason + (". " if add_period else " ") + reason - await self.infraction_edit(ctx, infraction, duration, reason=new_reason) + await self.infraction_edit(ctx, infraction, duration, reason=reason) @infraction_group.command(name='edit') async def infraction_edit( diff --git a/bot/utils/regex.py b/bot/utils/regex.py index cfce52bb3..0d2068f90 100644 --- a/bot/utils/regex.py +++ b/bot/utils/regex.py @@ -10,5 +10,3 @@ INVITE_RE = re.compile( r"([a-zA-Z0-9\-]+)", # the invite code itself flags=re.IGNORECASE ) - -END_PUNCTUATION_RE = re.compile("^.+?[.?!]$") -- cgit v1.2.3 From ae976d56bd3ce89c1da69f42f59680f7b4763771 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Mon, 30 Nov 2020 17:52:22 +0800 Subject: Remove unused get_latest_infraction helper method --- bot/exts/moderation/infraction/management.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 10bca5fc5..3b0719ed2 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -310,20 +310,6 @@ class ModManagement(commands.Cog): return lines.strip() - async def get_latest_infraction(self, actor: int) -> t.Optional[dict]: - """Obtains the latest infraction from an actor.""" - params = { - "actor__id": actor, - "ordering": "-inserted_at" - } - - infractions = await self.bot.api_client.get("bot/infractions", params=params) - - if infractions: - return infractions[0] - - return None - # endregion # This cannot be static (must have a __func__ attribute). -- cgit v1.2.3