diff options
| author | 2020-11-30 00:49:47 +0800 | |
|---|---|---|
| committer | 2020-11-30 01:22:05 +0800 | |
| commit | db2136cd5bd1b86b05f249177e7a68a731404d16 (patch) | |
| tree | 4a4731c381693621f0916a9ce811007ff58dc5e2 | |
| parent | Fix unawaited coroutine in Infraction (diff) | |
Refactor flow for automatically adding punctuation
| -rw-r--r-- | bot/exts/moderation/infraction/management.py | 11 | ||||
| -rw-r--r-- | 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("^.+?[.?!]$") |