aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar bast <[email protected]>2020-09-25 12:16:12 -0700
committerGravatar bast <[email protected]>2020-09-25 12:16:12 -0700
commit67bc58c1cc50fdf479274f4eb3e9f394363a7e6d (patch)
tree3bdb22a3ec30667816975e04e4bac361e26ff0a2
parentMerge pull request #449 from gustavwilliam/ext-managment (diff)
Make .bm handle embed-suppression syntax for message links <link>
[link] and [<link>] are also supported
-rw-r--r--bot/exts/evergreen/bookmark.py4
-rw-r--r--bot/utils/converters.py15
2 files changed, 18 insertions, 1 deletions
diff --git a/bot/exts/evergreen/bookmark.py b/bot/exts/evergreen/bookmark.py
index 73908702..0adf1e68 100644
--- a/bot/exts/evergreen/bookmark.py
+++ b/bot/exts/evergreen/bookmark.py
@@ -6,6 +6,8 @@ from discord.ext import commands
from bot.constants import Colours, ERROR_REPLIES, Emojis, Icons
+from bot.utils.converters import BetterMessageConverter
+
log = logging.getLogger(__name__)
@@ -19,7 +21,7 @@ class Bookmark(commands.Cog):
async def bookmark(
self,
ctx: commands.Context,
- target_message: discord.Message,
+ target_message: BetterMessageConverter,
*,
title: str = "Bookmark"
) -> None:
diff --git a/bot/utils/converters.py b/bot/utils/converters.py
new file mode 100644
index 00000000..74a0b5b7
--- /dev/null
+++ b/bot/utils/converters.py
@@ -0,0 +1,15 @@
+import discord
+
+from discord.ext.commands.converter import MessageConverter
+
+
+class BetterMessageConverter(MessageConverter):
+ """A converter that handles embed-suppressed links like <http://example.com>"""
+ async def convert(self, ctx, argument: str) -> discord.Message:
+ # It's possible to wrap a message in [<>] as well, and it's supported because its easy
+ if argument.startswith("[") and argument.endswith("]"):
+ argument = argument[1:-1]
+ if argument.startswith("<") and argument.endswith(">"):
+ argument = argument[1:-1]
+
+ return await super().convert(ctx, argument)