Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bot/exts/moderation/infraction/_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async def apply_infraction(
icon = _utils.INFRACTION_ICONS[infr_type][0]
reason = infraction["reason"]
id_ = infraction['id']
jump_url = infraction['jump_url']
expiry = time.format_with_duration(
infraction["expires_at"],
infraction["last_applied"]
Expand Down Expand Up @@ -261,6 +262,12 @@ async def apply_infraction(
mentions = discord.AllowedMentions(users=[user], roles=False)
await ctx.send(f"{dm_result}{confirm_msg}{infr_message}.", allowed_mentions=mentions)

if jump_url is None:
# Infraction issued in ModMail category.
jump_url = "N/A"
else:
jump_url = f"[Click here.]({jump_url})"

# Send a log message to the mod log.
# Don't use ctx.message.author for the actor; antispam only patches ctx.author.
log.trace(f"Sending apply mod log for infraction #{id_}.")
Expand All @@ -273,6 +280,7 @@ async def apply_infraction(
Member: {messages.format_user(user)}
Actor: {ctx.author.mention}{dm_log_text}{expiry_log_text}
Reason: {reason}
Jump URL: {jump_url}
{additional_info}
"""),
content=log_content,
Expand Down
28 changes: 19 additions & 9 deletions bot/exts/moderation/infraction/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from pydis_core.site_api import ResponseCodeError

import bot
from bot.constants import Colours, Icons
from bot.constants import Categories, Colours, Icons
from bot.converters import DurationOrExpiry, MemberOrUser
from bot.errors import InvalidInfractedUserError
from bot.log import get_logger
from bot.utils import time
from bot.utils.channel import is_in_category
from bot.utils.time import unpack_duration

log = get_logger(__name__)
Expand Down Expand Up @@ -77,14 +78,14 @@ async def post_user(ctx: Context, user: MemberOrUser) -> t.Optional[dict]:


async def post_infraction(
ctx: Context,
user: MemberOrUser,
infr_type: str,
reason: str,
duration_or_expiry: t.Optional[DurationOrExpiry] = None,
hidden: bool = False,
active: bool = True,
dm_sent: bool = False,
ctx: Context,
user: MemberOrUser,
infr_type: str,
reason: str,
duration_or_expiry: t.Optional[DurationOrExpiry] = None,
hidden: bool = False,
active: bool = True,
dm_sent: bool = False,
) -> t.Optional[dict]:
"""Posts an infraction to the API."""
if isinstance(user, (discord.Member, discord.User)) and user.bot:
Expand All @@ -95,6 +96,14 @@ async def post_infraction(

current_time = arrow.utcnow()

if any(
is_in_category(ctx.channel, category)
for category in (Categories.modmail, Categories.appeals, Categories.appeals_2)
):
jump_url = None
else:
jump_url = ctx.message.jump_url

payload = {
"actor": ctx.author.id, # Don't use ctx.message.author; antispam only patches ctx.author.
"hidden": hidden,
Expand All @@ -103,6 +112,7 @@ async def post_infraction(
"user": user.id,
"active": active,
"dm_sent": dm_sent,
"jump_url": jump_url,
"inserted_at": current_time.isoformat(),
"last_applied": current_time.isoformat(),
}
Expand Down
9 changes: 9 additions & 0 deletions bot/exts/moderation/infraction/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str:
applied = time.discord_timestamp(last_applied)
duration_edited = arrow.get(last_applied) > arrow.get(inserted_at)
dm_sent = infraction["dm_sent"]
jump_url = infraction["jump_url"]

# Format the user string.
if user_obj := self.bot.get_user(user["id"]):
Expand Down Expand Up @@ -420,6 +421,13 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str:
else:
dm_sent_text = "Yes" if dm_sent else "No"

if jump_url is None:
# Infraction was issued prior to jump urls being stored in the database
# or infraction was issued in ModMail category.
jump_url = "N/A"
else:
jump_url = f"[Click here.]({jump_url})"

lines = textwrap.dedent(f"""
{"**===============**" if active else "==============="}
Status: {"__**Active**__" if active else "Inactive"}
Expand All @@ -432,6 +440,7 @@ def infraction_to_string(self, infraction: t.Dict[str, t.Any]) -> str:
Duration: {duration}
Actor: <@{infraction["actor"]["id"]}>
ID: `{infraction["id"]}`
Jump URL: {jump_url}
Reason: {infraction["reason"] or "*None*"}
{"**===============**" if active else "==============="}
""")
Expand Down