Skip to content

Commit 4c4a2bc

Browse files
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 <[email protected]>
1 parent eecf952 commit 4c4a2bc

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
Changelog
55
=========
66

7+
- :release:`11.7.0 <10th August 2025>`
8+
- :bug:`304` Update Discord invite regex to handle new protocol.
9+
710
- :release:`11.6.1 <13th July 2025>`
811
- :bug:`303` Update Discord invite regex to handle cases with additional slashes.
912

pydis_core/utils/regex.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import re
44

55
DISCORD_INVITE = re.compile(
6-
r"(https?:\/\/)?(www\.)?" # Optional http(s) and www.
6+
r"(https?:\/\/)?(discord:\/*)?" # Optional protocols
7+
r"(www\.)?" # Optional www
8+
r"[@#]*" # Optional @ or # symbols
79
r"(\B|discord(app)?)" # Optional discord(app)
810
r"([.,]|dot)" # Various characters to cover dots
911
r"("

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pydis_core"
3-
version = "11.6.1"
3+
version = "11.7.0"
44
description = "PyDis core provides core functionality and utility to the bots of the Python Discord community."
55
authors = ["Python Discord <[email protected]>"]
66
license = "MIT"

tests/pydis_core/utils/test_regex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def test_discord_invite_positives(self):
4949
self.assertEqual(search_regex("https://discord.gg/python with whitespace"), "python")
5050
self.assertEqual(search_regex(" https://discord.gg/python "), "python")
5151

52+
self.assertEqual(search_regex("discord:#@discordapp.com/invite/python"), "python")
53+
self.assertEqual(search_regex("discord:/#@discordapp.com/invite/python"), "python")
54+
self.assertEqual(search_regex("discord://#@discordapp.com/invite/python"), "python")
55+
self.assertEqual(search_regex("discord://@#discordapp.com/invite/python"), "python")
56+
5257
def test_discord_invite_negatives(self):
5358
"""Test the DISCORD_INVITE regex on a set of strings we would expect to not capture."""
5459

0 commit comments

Comments
 (0)