Skip to content

Commit 8ec08e5

Browse files
committed
Discord API
1 parent 95dd434 commit 8ec08e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3332
-1516
lines changed

docs/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Glossary
3232
Releases
3333
----------------------
3434

35+
v2.3.6
36+
=============
37+
- Fixed voice not working due to Discord's API changes.
38+
39+
3540
v2.3.5
3641
=============
3742
- Fixed ``typechecked`` module error

src/_discord/__init__.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
__author__ = "Pycord Development"
1313
__license__ = "MIT"
1414
__copyright__ = "Copyright 2015-2021 Rapptz & Copyright 2021-present Pycord Development"
15-
__version__ = "2.2.2"
1615

1716
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1817

1918
import logging
20-
from typing import Literal, NamedTuple
19+
20+
# We need __version__ to be imported first
21+
# isort: off
22+
from ._version import *
23+
24+
# isort: on
25+
2126

2227
from . import abc, opus, sinks, ui, utils
2328
from .activity import *
2429
from .appinfo import *
30+
from .application_role_connection import *
2531
from .asset import *
2632
from .audit_logs import *
2733
from .automod import *
@@ -66,17 +72,4 @@
6672
from .welcome_screen import *
6773
from .widget import *
6874

69-
70-
class VersionInfo(NamedTuple):
71-
major: int
72-
minor: int
73-
micro: int
74-
releaselevel: Literal["alpha", "beta", "candidate", "final"]
75-
serial: int
76-
77-
78-
version_info: VersionInfo = VersionInfo(
79-
major=2, minor=2, micro=2, releaselevel="final", serial=0
80-
)
81-
8275
logging.getLogger(__name__).addHandler(logging.NullHandler())

src/_discord/_typed_dict.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021-present Pycord Development
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
23+
"""
24+
import sys
25+
26+
# PEP 655 Required and NotRequired were added in python 3.11. This file is simply a
27+
# shortcut import, so we don't have to repeat this import logic across files.
28+
if sys.version_info >= (3, 11):
29+
from typing import NotRequired, Required, TypedDict
30+
else:
31+
from typing_extensions import NotRequired, Required, TypedDict
32+
33+
__all__ = (
34+
"Required",
35+
"NotRequired",
36+
"TypedDict",
37+
)

src/_discord/_version.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-2021 Rapptz
5+
Copyright (c) 2021-present Pycord Development
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the "Software"),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
"""
25+
from __future__ import annotations
26+
27+
import datetime
28+
import re
29+
import warnings
30+
from importlib.metadata import PackageNotFoundError, version
31+
32+
from ._typed_dict import TypedDict
33+
34+
__all__ = ("__version__", "VersionInfo", "version_info")
35+
36+
from typing import Literal, NamedTuple
37+
38+
from .utils import deprecated
39+
40+
__version__ = "2.4.1"
41+
42+
43+
class AdvancedVersionInfo(TypedDict):
44+
serial: int
45+
build: int | None
46+
commit: str | None
47+
date: datetime.date | None
48+
49+
50+
class VersionInfo(NamedTuple):
51+
major: int
52+
minor: int
53+
micro: int
54+
releaselevel: Literal["alpha", "beta", "candidate", "final"]
55+
56+
# We can't set instance attributes on a NamedTuple, so we have to use a
57+
# global variable to store the advanced version info.
58+
@property
59+
def advanced(self) -> AdvancedVersionInfo:
60+
return _advanced
61+
62+
@advanced.setter
63+
def advanced(self, value: object) -> None:
64+
global _advanced
65+
_advanced = value
66+
67+
@property
68+
@deprecated("releaselevel", "2.4")
69+
def release_level(self) -> Literal["alpha", "beta", "candidate", "final"]:
70+
return self.releaselevel
71+
72+
@property
73+
@deprecated('.advanced["serial"]', "2.4")
74+
def serial(self) -> int:
75+
return self.advanced["serial"]
76+
77+
@property
78+
@deprecated('.advanced["build"]', "2.4")
79+
def build(self) -> int | None:
80+
return self.advanced["build"]
81+
82+
@property
83+
@deprecated('.advanced["commit"]', "2.4")
84+
def commit(self) -> str | None:
85+
return self.advanced["commit"]
86+
87+
@property
88+
@deprecated('.advanced["date"]', "2.4")
89+
def date(self) -> datetime.date | None:
90+
return self.advanced["date"]
91+
92+
93+
version_regex = re.compile(
94+
r"^(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<patch>\d+))?"
95+
r"(?:(?P<level>rc|a|b)(?P<serial>\d+))?"
96+
r"(?:\.dev(?P<build>\d+))?"
97+
r"(?:\+(?:(?:g(?P<commit>[a-fA-F0-9]{4,40})(?:\.d(?P<date>\d{4}\d{2}\d{2})|))|d(?P<date1>\d{4}\d{2}\d{2})))?$"
98+
)
99+
version_match = version_regex.match(__version__)
100+
if version_match is None:
101+
raise RuntimeError(f"Invalid version string: {__version__}")
102+
raw_info = version_match.groupdict()
103+
104+
level_info: Literal["alpha", "beta", "candidate", "final"]
105+
106+
if raw_info["level"] == "a":
107+
level_info = "alpha"
108+
elif raw_info["level"] == "b":
109+
level_info = "beta"
110+
elif raw_info["level"] == "rc":
111+
level_info = "candidate"
112+
elif raw_info["level"] is None:
113+
level_info = "final"
114+
else:
115+
raise RuntimeError("Invalid release level")
116+
117+
if (raw_date := raw_info["date"] or raw_info["date1"]) is not None:
118+
date_info = datetime.date(
119+
int(raw_date[:4]),
120+
int(raw_date[4:6]),
121+
int(raw_date[6:]),
122+
)
123+
else:
124+
date_info = None
125+
126+
version_info: VersionInfo = VersionInfo(
127+
major=int(raw_info["major"] or 0) or None,
128+
minor=int(raw_info["minor"] or 0) or None,
129+
micro=int(raw_info["patch"] or 0) or None,
130+
releaselevel=level_info,
131+
)
132+
133+
_advanced = AdvancedVersionInfo(
134+
serial=raw_info["serial"],
135+
build=int(raw_info["build"] or 0) or None,
136+
commit=raw_info["commit"],
137+
date=date_info,
138+
)

0 commit comments

Comments
 (0)