Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 4 additions & 2 deletions pydis_core/utils/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
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"("
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<invite>\S+)", # the invite code itself
flags=re.IGNORECASE
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <info@pythondiscord.com>"]
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions tests/pydis_core/utils/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down