mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-22 08:23:09 +00:00
Implement Guild Scheduled Events
This commit is contained in:
@@ -40,6 +40,7 @@ from typing import (
|
||||
List,
|
||||
Literal,
|
||||
Mapping,
|
||||
NamedTuple,
|
||||
Optional,
|
||||
Protocol,
|
||||
Sequence,
|
||||
@@ -63,6 +64,8 @@ import sys
|
||||
import types
|
||||
import warnings
|
||||
|
||||
import yarl
|
||||
|
||||
try:
|
||||
import orjson
|
||||
except ModuleNotFoundError:
|
||||
@@ -729,10 +732,19 @@ def _string_width(string: str, *, _IS_ASCII=_IS_ASCII) -> int:
|
||||
return sum(2 if func(char) in UNICODE_WIDE_CHAR_TYPE else 1 for char in string)
|
||||
|
||||
|
||||
def resolve_invite(invite: Union[Invite, str]) -> str:
|
||||
class ResolvedInvite(NamedTuple):
|
||||
code: str
|
||||
event: Optional[int]
|
||||
|
||||
|
||||
def resolve_invite(invite: Union[Invite, str]) -> ResolvedInvite:
|
||||
"""
|
||||
Resolves an invite from a :class:`~discord.Invite`, URL or code.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
Now returns a :class:`.ResolvedInvite` instead of a
|
||||
:class:`str`.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
invite: Union[:class:`~discord.Invite`, :class:`str`]
|
||||
@@ -740,19 +752,24 @@ def resolve_invite(invite: Union[Invite, str]) -> str:
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`str`
|
||||
The invite code.
|
||||
:class:`.ResolvedInvite`
|
||||
A data class containing the invite code and the event ID.
|
||||
"""
|
||||
from .invite import Invite # circular import
|
||||
|
||||
if isinstance(invite, Invite):
|
||||
return invite.code
|
||||
return ResolvedInvite(invite.code, invite.scheduled_event_id)
|
||||
else:
|
||||
rx = r'(?:https?\:\/\/)?discord(?:\.gg|(?:app)?\.com\/invite)\/(.+)'
|
||||
rx = r'(?:https?\:\/\/)?discord(?:\.gg|(?:app)?\.com\/invite)\/[^/]+'
|
||||
m = re.match(rx, invite)
|
||||
|
||||
if m:
|
||||
return m.group(1)
|
||||
return invite
|
||||
url = yarl.URL(invite)
|
||||
code = url.parts[-1]
|
||||
event_id = url.query.get('event')
|
||||
|
||||
return ResolvedInvite(code, int(event_id) if event_id else None)
|
||||
return ResolvedInvite(invite, None)
|
||||
|
||||
|
||||
def resolve_template(code: Union[Template, str]) -> str:
|
||||
|
Reference in New Issue
Block a user