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
4 changes: 2 additions & 2 deletions bot/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class ValidDiscordServerInvite(Converter):

async def convert(self, ctx: Context, server_invite: str) -> dict:
"""Check whether the string is a valid Discord server invite."""
invite_code = INVITE_RE.search(server_invite)
invite_code = INVITE_RE.match(server_invite)
if invite_code:
response = await ctx.bot.http_session.get(
f"{URLs.discord_invite_api}/{invite_code[1]}"
f"{URLs.discord_invite_api}/{invite_code.group('invite')}"
)
if response.status != 404:
invite_data = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/filters/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ async def _has_invites(self, text: str) -> Union[dict, bool]:
# discord\.gg/gdudes-pony-farm
text = text.replace("\\", "")

invites = INVITE_RE.findall(text)
invites = [m.group("invite") for m in INVITE_RE.finditer(text)]
invite_data = dict()
for invite in invites:
if invite in invite_data:
Expand Down
18 changes: 9 additions & 9 deletions bot/utils/regex.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import re

INVITE_RE = re.compile(
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)me|" # or discord.me
r"discord(?:[\.,]|dot)li|" # or discord.li
r"discord(?:[\.,]|dot)io|" # or discord.io.
r"(?:[\.,]|dot)gg" # or .gg/
r")(?:[\/]|slash)" # / or 'slash'
r"([a-zA-Z0-9\-]+)", # the invite code itself
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)me|" # or discord.me
r"discord([\.,]|dot)li|" # or discord.li
r"discord([\.,]|dot)io|" # or discord.io.
r"((?<!\w)([\.,]|dot))gg" # or .gg/
r")([\/]|slash)" # / or 'slash'
r"(?P<invite>[a-zA-Z0-9\-]+)", # the invite code itself
flags=re.IGNORECASE
)