aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/moderation/utils.py18
-rw-r--r--tests/bot/cogs/moderation/test_utils.py16
2 files changed, 18 insertions, 16 deletions
diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py
index 104baf528..cbef3420a 100644
--- a/bot/cogs/moderation/utils.py
+++ b/bot/cogs/moderation/utils.py
@@ -34,6 +34,12 @@ INFRACTION_TITLE = f"Please review our rules over at {RULES_URL}"
INFRACTION_APPEAL_FOOTER = f"To appeal this infraction, send an e-mail to {APPEAL_EMAIL}"
INFRACTION_AUTHOR_NAME = "Infraction information"
+INFRACTION_DESCRIPTION_TEMPLATE = (
+ "\n**Type:** {type}\n"
+ "**Expires:** {expires}\n"
+ "**Reason:** {reason}\n"
+)
+
async def post_user(ctx: Context, user: UserSnowflake) -> t.Optional[dict]:
"""
@@ -148,11 +154,13 @@ async def notify_infraction(
"""DM a user about their new infraction and return True if the DM is successful."""
log.trace(f"Sending {user} a DM about their {infr_type} infraction.")
- text = textwrap.dedent(f"""
- **Type:** {infr_type.capitalize()}
- **Expires:** {expires_at or "N/A"}
- **Reason:** {reason or "No reason provided."}
- """)
+ text = textwrap.dedent(
+ INFRACTION_DESCRIPTION_TEMPLATE.format(
+ type=infr_type.capitalize(),
+ expires=expires_at or "N/A",
+ reason=reason or "No reason provided."
+ )
+ )
embed = discord.Embed(
description=textwrap.shorten(text, width=2048, placeholder="..."),
diff --git a/tests/bot/cogs/moderation/test_utils.py b/tests/bot/cogs/moderation/test_utils.py
index c4d0d6f16..c35c0edf5 100644
--- a/tests/bot/cogs/moderation/test_utils.py
+++ b/tests/bot/cogs/moderation/test_utils.py
@@ -11,12 +11,6 @@ from bot.cogs.moderation import utils
from bot.constants import Colours, Icons
from tests.helpers import MockBot, MockContext, MockMember, MockUser
-INFRACTION_DESCRIPTION_TEMPLATE = (
- "\n**Type:** {type}\n"
- "**Expires:** {expires}\n"
- "**Reason:** {reason}\n"
-)
-
class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"""Tests Moderation utils."""
@@ -77,7 +71,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"args": (self.user, "ban", "2020-02-26 09:20 (23 hours and 59 minutes)"),
"expected_output": Embed(
title=utils.INFRACTION_TITLE,
- description=textwrap.shorten(INFRACTION_DESCRIPTION_TEMPLATE.format(
+ description=textwrap.shorten(utils.INFRACTION_DESCRIPTION_TEMPLATE.format(
type="Ban",
expires="2020-02-26 09:20 (23 hours and 59 minutes)",
reason="No reason provided."
@@ -95,7 +89,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"args": (self.user, "warning", None, "Test reason."),
"expected_output": Embed(
title=utils.INFRACTION_TITLE,
- description=textwrap.shorten(INFRACTION_DESCRIPTION_TEMPLATE.format(
+ description=textwrap.shorten(utils.INFRACTION_DESCRIPTION_TEMPLATE.format(
type="Warning",
expires="N/A",
reason="Test reason."
@@ -113,7 +107,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"args": (self.user, "note", None, None, Icons.defcon_denied),
"expected_output": Embed(
title=utils.INFRACTION_TITLE,
- description=textwrap.shorten(INFRACTION_DESCRIPTION_TEMPLATE.format(
+ description=textwrap.shorten(utils.INFRACTION_DESCRIPTION_TEMPLATE.format(
type="Note",
expires="N/A",
reason="No reason provided."
@@ -131,7 +125,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"args": (self.user, "mute", "2020-02-26 09:20 (23 hours and 59 minutes)", "Test", Icons.defcon_denied),
"expected_output": Embed(
title=utils.INFRACTION_TITLE,
- description=textwrap.shorten(INFRACTION_DESCRIPTION_TEMPLATE.format(
+ description=textwrap.shorten(utils.INFRACTION_DESCRIPTION_TEMPLATE.format(
type="Mute",
expires="2020-02-26 09:20 (23 hours and 59 minutes)",
reason="Test"
@@ -149,7 +143,7 @@ class ModerationUtilsTests(unittest.IsolatedAsyncioTestCase):
"args": (self.user, "mute", None, "foo bar" * 4000, Icons.defcon_denied),
"expected_output": Embed(
title=utils.INFRACTION_TITLE,
- description=textwrap.shorten(INFRACTION_DESCRIPTION_TEMPLATE.format(
+ description=textwrap.shorten(utils.INFRACTION_DESCRIPTION_TEMPLATE.format(
type="Mute",
expires="N/A",
reason="foo bar" * 4000