From e985aa804c70ff5d69e187b39cb9c4b9fa423321 Mon Sep 17 00:00:00 2001 From: L3viathan Date: Thu, 12 Jun 2025 17:29:55 +0200 Subject: [PATCH] mdlink: Add option to send mobile-friendly link When copying a message on mobile, you have to copy the entire message anyways, and then you have to remove the backticks. This option allows the link to be sent escaped instead of in backticks, i.e., \[foo](http:\/\/bar.com) instead of `[foo](http://bar.com)` --- mdlink/mdlink.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mdlink/mdlink.py b/mdlink/mdlink.py index bd6b5e1..3701d11 100644 --- a/mdlink/mdlink.py +++ b/mdlink/mdlink.py @@ -1,4 +1,7 @@ +import typing as t + from discord.ext import commands +from discord.utils import escape_markdown from bot import ModmailBot from core import checks @@ -14,10 +17,19 @@ def __init__(self, bot: ModmailBot): @commands.command() @checks.has_permissions(PermissionLevel.MODERATOR) @checks.thread_only() - async def mdlink(self, ctx: commands.Context, *, text: str = "ModMail") -> None: + async def mdlink( + self, + ctx: commands.Context, + plain: t.Optional[t.Literal["plain", "p", "mobile", "m"]] = None, + *, + text: str = "ModMail", + ) -> None: """Return a link to the modmail thread in markdown syntax.""" link = await self.bot.api.get_log_link(ctx.channel.id) - await ctx.send(f"`[{text}]({link})`") + if plain: + await ctx.send(escape_markdown(f"[{text}]({link})", as_needed=True, ignore_links=False)) + else: + await ctx.send(f"`[{text}]({link})`") async def setup(bot: ModmailBot) -> None: