Skip to content

Commit

Permalink
Improve MessageConverter to convert channelid-messageid format. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Dec 9, 2022
1 parent dba32bc commit af12cdf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lightbulb/converters/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
ROLE_MENTION_REGEX: t.Final[re.Pattern[str]] = re.compile(r"<@&(\d+)>")
EMOJI_MENTION_REGEX: t.Final[re.Pattern[str]] = re.compile(r"<a?:\w+:(\d+)>")
TIMESTAMP_MENTION_REGEX: t.Final[re.Pattern[str]] = re.compile(r"<t:(\d+)(?::[tTdDfFR])?>")
CHANNEL_MESSAGE_REGEX: t.Final[re.Pattern[str]] = re.compile(r"(\d+)-(\d+)")

BOOLEAN_MAPPING: t.Dict[str, bool] = {"yes": True, "y": True, "1": True, "no": False, "n": False, "0": False}

Expand Down Expand Up @@ -252,9 +253,11 @@ class MessageConverter(base.BaseConverter[hikari.Message]):
__slots__ = ()

async def convert(self, arg: str) -> hikari.Message:
try:
if arg.isdigit():
m_id, c_id = int(arg), int(self.context.channel_id)
except ValueError:
elif match := CHANNEL_MESSAGE_REGEX.match(arg):
m_id, c_id = int(match.group(2)), int(match.group(1))
else:
parts = arg.rstrip("/").split("/")
m_id, c_id = int(parts[-1]), int(parts[-2])

Expand Down

0 comments on commit af12cdf

Please sign in to comment.