From a907e198d9540634ebefaa0e263b1c47920f6299 Mon Sep 17 00:00:00 2001 From: fisher60 Date: Sun, 10 Aug 2025 13:42:37 -0500 Subject: [PATCH 1/2] extend regex for new discord shenanigans Chris is traveling abroad and is unable to access. Therefore, I have become his proxy. An 'apprentice' if you will. Shame because I have years more software engineering experience compared to him. Co-authored-by: Chris Lovering --- docs/changelog.rst | 3 +++ pydis_core/utils/regex.py | 4 +++- pyproject.toml | 2 +- tests/pydis_core/utils/test_regex.py | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 311850e5d..cb5d8e705 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,9 @@ Changelog ========= +- :release:`11.7.0 <10th August 2025>` +- :bug:`304` Update Discord invite regex to handle new protocol. + - :release:`11.6.1 <13th July 2025>` - :bug:`303` Update Discord invite regex to handle cases with additional slashes. diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index ba6b9b01b..11f8e3cdc 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -3,7 +3,9 @@ import re DISCORD_INVITE = re.compile( - r"(https?:\/\/)?(www\.)?" # Optional http(s) and www. + r"(https?:\/\/)?(discord:\/*)?" # Optional protocols + r"(www\.)?" # Optional www + r"[@#]*" # Optional @ or # symbols r"(\B|discord(app)?)" # Optional discord(app) r"([.,]|dot)" # Various characters to cover dots r"(" diff --git a/pyproject.toml b/pyproject.toml index 727f6e9c1..ed1ed117c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pydis_core" -version = "11.6.1" +version = "11.7.0" description = "PyDis core provides core functionality and utility to the bots of the Python Discord community." authors = ["Python Discord "] license = "MIT" diff --git a/tests/pydis_core/utils/test_regex.py b/tests/pydis_core/utils/test_regex.py index 79c1d7436..26fe23ea6 100644 --- a/tests/pydis_core/utils/test_regex.py +++ b/tests/pydis_core/utils/test_regex.py @@ -49,6 +49,11 @@ def test_discord_invite_positives(self): self.assertEqual(search_regex("https://discord.gg/python with whitespace"), "python") self.assertEqual(search_regex(" https://discord.gg/python "), "python") + self.assertEqual(search_regex("discord:#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord:/#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord://#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord://@#discordapp.com/invite/python"), "python") + def test_discord_invite_negatives(self): """Test the DISCORD_INVITE regex on a set of strings we would expect to not capture.""" From 9b95fb9f3fd27d57776edc03cac909b2f58b0ca5 Mon Sep 17 00:00:00 2001 From: fisher60 Date: Sun, 10 Aug 2025 14:09:23 -0500 Subject: [PATCH 2/2] fix comment styling in comments These got borked by me and also previously, cleaning it up. Brain enjoy uniform format. --- pydis_core/utils/regex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index 11f8e3cdc..26b1a547b 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -3,7 +3,7 @@ import re DISCORD_INVITE = re.compile( - r"(https?:\/\/)?(discord:\/*)?" # Optional protocols + r"(https?:\/\/)?(discord:\/*)?" # Optional protocols r"(www\.)?" # Optional www r"[@#]*" # Optional @ or # symbols r"(\B|discord(app)?)" # Optional discord(app) @@ -12,7 +12,7 @@ r"(gg|me)" # TLDs that embed within discord r"|com(\/|slash|\\)invite" # Only match com/invite r")" - r"(/|slash|\\+)" # / or 'slash' or 1+ of \ + r"(/|slash|\\+)" # / or 'slash' or 1+ of \ r"(?P\S+)", # the invite code itself flags=re.IGNORECASE )