From add2e0362afe7e3e908c442f9f63785e79f54b11 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 2 May 2021 23:26:36 -0400 Subject: [PATCH] Pre-compile arkhamdb URL regex --- ahtcg_bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ahtcg_bot.py b/ahtcg_bot.py index f483d89..b762b5e 100755 --- a/ahtcg_bot.py +++ b/ahtcg_bot.py @@ -31,12 +31,14 @@ class ArkhamDBUpdater(discord.Client): async def gather_deck_ids(self, channel: discord.TextChannel) -> dict[int, str]: deck_ids: dict[int, str] = {} + url_regex = re.compile( + r'(?P.*)' + self.arkhamdb_client.origin + r'/deck/view/(?P\d+)') async for message in channel.history(limit=200, oldest_first=True): # ignore the bot's messages if message.author.id == self.user.id: continue - matches = re.finditer(r'(?P.*)' + self.arkhamdb_client.origin + r'/deck/view/(?P\d+)', message.content) + matches = url_regex.finditer(message.content) for match in matches: deck_ids[int(match.group('deck_id'))] = match.group('prefix')