From e0d6f92b55faf779b71a71a06f6d37cccd97542f Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 17 Oct 2024 22:25:59 +0100 Subject: [PATCH 1/6] Drop / from invite regex fragements There is already a fragment that captures slashes further down in the regex --- pydis_core/utils/regex.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index 0901f1f1f..13a6d2209 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -4,13 +4,14 @@ DISCORD_INVITE = re.compile( r"(https?://)?(www\.)?" # Optional http(s) and www. - r"(discord([.,]|dot)gg|" # Could be discord.gg/ - r"discord([.,]|dot)com(/|slash)invite|" # or discord.com/invite/ - r"discordapp([.,]|dot)com(/|slash)invite|" # or discordapp.com/invite/ + r"(discord([.,]|dot)gg|" # Could be discord.gg + r"discord([.,]|dot)com|" # or discord.com/invite + r"discordapp([.,]|dot)com|" # or discordapp.com/invite r"discord([.,]|dot)me|" # or discord.me r"discord([.,]|dot)li|" # or discord.li - r"discord([.,]|dot)io|" # or discord.io. - r"((?\S+)", # the invite code itself flags=re.IGNORECASE From 8528c7f1191905198c2ae9d064137dc339619afc Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 17 Oct 2024 22:27:48 +0100 Subject: [PATCH 2/6] Improve readability of invite regex by indenting the large OR group --- pydis_core/utils/regex.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index 13a6d2209..1ccc0813a 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -4,15 +4,17 @@ DISCORD_INVITE = re.compile( r"(https?://)?(www\.)?" # Optional http(s) and www. - r"(discord([.,]|dot)gg|" # Could be discord.gg - r"discord([.,]|dot)com|" # or discord.com/invite - r"discordapp([.,]|dot)com|" # or discordapp.com/invite - r"discord([.,]|dot)me|" # or discord.me - r"discord([.,]|dot)li|" # or discord.li - r"discord([.,]|dot)io|" # or discord.io - r"((?\S+)", # the invite code itself flags=re.IGNORECASE ) From 9385e911cb7c117f3971171ea45cb4d9d641a1b2 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 17 Oct 2024 22:29:39 +0100 Subject: [PATCH 3/6] Add optional 'app' capture to invite regex OR group --- pydis_core/utils/regex.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index 1ccc0813a..f51b6159e 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -5,12 +5,11 @@ DISCORD_INVITE = re.compile( r"(https?://)?(www\.)?" # Optional http(s) and www. r"(" - r"discord([.,]|dot)gg|" # Could be discord.gg - r"discord([.,]|dot)com|" # or discord.com/invite - r"discordapp([.,]|dot)com|" # or discordapp.com/invite - r"discord([.,]|dot)me|" # or discord.me - r"discord([.,]|dot)li|" # or discord.li - r"discord([.,]|dot)io|" # or discord.io + r"discord(app)?([.,]|dot)gg|" # Could be discord(app).gg + r"discord(app)?([.,]|dot)com|" # or discord(app).com/invite + r"discord(app)?([.,]|dot)me|" # or discord(app).me + r"discord(app)?([.,]|dot)li|" # or discord(app).li + r"discord(app)?([.,]|dot)io|" # or discord(app).io r"((? Date: Thu, 17 Oct 2024 22:35:13 +0100 Subject: [PATCH 4/6] Move discord(app) capture to its own optional group in invite regex --- pydis_core/utils/regex.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index f51b6159e..f78229ff8 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -4,13 +4,13 @@ DISCORD_INVITE = re.compile( r"(https?://)?(www\.)?" # Optional http(s) and www. + r"(discord(app)?)?" # Optional discord(app) r"(" - r"discord(app)?([.,]|dot)gg|" # Could be discord(app).gg - r"discord(app)?([.,]|dot)com|" # or discord(app).com/invite - r"discord(app)?([.,]|dot)me|" # or discord(app).me - r"discord(app)?([.,]|dot)li|" # or discord(app).li - r"discord(app)?([.,]|dot)io|" # or discord(app).io - r"((? Date: Thu, 17 Oct 2024 22:41:20 +0100 Subject: [PATCH 5/6] Remove repetition from the invite regex --- pydis_core/utils/regex.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index f78229ff8..a78f2afbe 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -5,13 +5,8 @@ DISCORD_INVITE = re.compile( r"(https?://)?(www\.)?" # Optional http(s) and www. r"(discord(app)?)?" # Optional discord(app) - r"(" - r"([.,]|dot)gg|" # Could be .gg - r"([.,]|dot)com|" # or .com - r"([.,]|dot)me|" # or .me - r"([.,]|dot)li|" # or .li - r"([.,]|dot)io" # or .io - r")" + r"([.,]|dot)" # Various characters to cover dots + r"(gg|com|me|li|io)" # A few TLDs that embed within discord r"((/|slash|\\)(invite))?" # / or \ or 'slash' invite r"(/|slash|\\)" # / or \ or 'slash' r"(?P\S+)", # the invite code itself From 1f9aa394276a1542168831f763fff6f04eccb01d Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 17 Oct 2024 22:37:17 +0100 Subject: [PATCH 6/6] Bump version and add changelog entry --- docs/changelog.rst | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 010070c07..9c22af6ef 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,10 @@ Changelog ========= +- :release:`11.5.0 <17th October 2024>` +- :feature:`282` Update :obj:`pydis_core.utils.regex.DISCORD_INVITE` to cover more edge cases. + + - :release:`11.4.0 <11th September 2024>` - :feature:`269` Update :obj:`pydis_core.utils.regex.DISCORD_INVITE` to also match backslash before the invite code. diff --git a/pyproject.toml b/pyproject.toml index e3251845e..1f345477c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pydis_core" -version = "11.4.0" +version = "11.5.0" description = "PyDis core provides core functionality and utility to the bots of the Python Discord community." authors = ["Python Discord "] license = "MIT"