Skip to content

Commit cad2251

Browse files
jb3ChrisLoveringfisher60
committed
Update Regex to include Discord protocol format (#304)
Chris is traveling abroad and is unable to access. Therefore, Fisher have become his proxy. An 'apprentice' if you will. Shame because Fisher have years more software engineering experience compared to him. Unfortunately, neither Fisher nor Chris cared to separate the version bump into a separate commit so SENIOR Engineer Joe Banks to JUNIOR Engineer Chris Lovering with INTERN Fisher has had to Get Involved. Co-authored-by: ChrisLovering <[email protected]> Co-authored-by: fisher60 <[email protected]>
1 parent eecf952 commit cad2251

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pydis_core/utils/regex.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
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"("
1012
r"(gg|me)" # TLDs that embed within discord
1113
r"|com(\/|slash|\\)invite" # Only match com/invite
1214
r")"
13-
r"(/|slash|\\+)" # / or 'slash' or 1+ of \
15+
r"(/|slash|\\+)" # / or 'slash' or 1+ of \
1416
r"(?P<invite>\S+)", # the invite code itself
1517
flags=re.IGNORECASE
1618
)

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)