Skip to content

Commit 56caff5

Browse files
committed
things
1 parent a98025a commit 56caff5

File tree

10 files changed

+381
-207
lines changed

10 files changed

+381
-207
lines changed

discord/abc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,7 @@ class Connectable(Protocol):
19341934

19351935
__slots__ = ()
19361936
_state: ConnectionState
1937+
id: int
19371938

19381939
def _get_voice_client_key(self) -> tuple[int, str]:
19391940
raise NotImplementedError

discord/channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ def _update(
16111611
self, guild: Guild, data: VoiceChannelPayload | StageChannelPayload
16121612
) -> None:
16131613
# This data will always exist
1614-
self.guild = guild
1614+
self.guild: Guild = guild
16151615
self.name: str = data["name"]
16161616
self.category_id: int | None = utils._get_as_snowflake(data, "parent_id")
16171617

discord/gateway.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,17 @@ def __init__(
137137
interval: float | None = None,
138138
**kwargs: Any,
139139
) -> None:
140-
threading.Thread.__init__(self, *args, **kwargs)
140+
daemon: bool = kwargs.pop('daemon', True)
141+
name: str = kwargs.pop('name', f'keep-alive-handler:shard-{shard_id}')
142+
super().__init__(
143+
*args,
144+
**kwargs,
145+
daemon=daemon,
146+
name=name,
147+
)
141148
self.ws: DiscordWebSocket = ws
142149
self._main_thread_id = ws.thread_id
143150
self.interval = interval
144-
self.daemon = True
145151
self.shard_id = shard_id
146152
self.msg = "Keeping shard ID %s websocket alive with sequence %s."
147153
self.block_msg = "Shard ID %s heartbeat blocked for more than %s seconds."
@@ -153,7 +159,7 @@ def __init__(
153159
self.latency = float("inf")
154160
self.heartbeat_timeout = ws._max_heartbeat_timeout
155161

156-
def run(self):
162+
def run(self) -> None:
157163
while not self._stop_ev.wait(self.interval):
158164
if self._last_recv + self.heartbeat_timeout < time.perf_counter():
159165
_log.warning(
@@ -206,16 +212,16 @@ def run(self):
206212
else:
207213
self._last_send = time.perf_counter()
208214

209-
def get_payload(self):
215+
def get_payload(self) -> dict[str, Any]:
210216
return {"op": self.ws.HEARTBEAT, "d": self.ws.sequence}
211217

212-
def stop(self):
218+
def stop(self) -> None:
213219
self._stop_ev.set()
214220

215-
def tick(self):
221+
def tick(self) -> None:
216222
self._last_recv = time.perf_counter()
217223

218-
def ack(self):
224+
def ack(self) -> None:
219225
ack_time = time.perf_counter()
220226
self._last_ack = ack_time
221227
self.latency = ack_time - self._last_send

discord/member.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
)
5252

5353
if TYPE_CHECKING:
54+
from .client import Client
5455
from .abc import Snowflake
55-
from .channel import DMChannel, StageChannel, VoiceChannel
56+
from .channel import DMChannel, VocalGuildChannel
5657
from .flags import PublicUserFlags
5758
from .guild import Guild
5859
from .message import Message
@@ -63,11 +64,9 @@
6364
from .types.member import MemberWithUser as MemberWithUserPayload
6465
from .types.member import UserWithMember as UserWithMemberPayload
6566
from .types.user import User as UserPayload
66-
from .types.voice import GuildVoiceState as GuildVoiceStatePayload
67+
from .types.voice import VoiceState as GuildVoiceStatePayload
6768
from .types.voice import VoiceState as VoiceStatePayload
6869

69-
VocalGuildChannel = Union[VoiceChannel, StageChannel]
70-
7170

7271
class VoiceState:
7372
"""Represents a Discord user's voice state.
@@ -165,6 +164,20 @@ def __repr__(self) -> str:
165164
inner = " ".join("%s=%r" % t for t in attrs)
166165
return f"<{self.__class__.__name__} {inner}>"
167166

167+
@classmethod
168+
def _create_default(cls, channel: VocalGuildChannel, client: Client) -> VoiceState:
169+
self = cls(
170+
data={
171+
'channel_id': channel.id,
172+
'guild_id': channel.guild.id,
173+
'self_deaf': False,
174+
'self_mute': False,
175+
'user_id': client._connection.self_id, # type: ignore
176+
},
177+
channel=channel,
178+
)
179+
return self
180+
168181

169182
def flatten_user(cls):
170183
for attr, value in itertools.chain(

discord/voice/client.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,5 @@
2424
"""
2525
from __future__ import annotations
2626

27-
from ._types import VoiceProtocol
28-
29-
30-
class VoiceClient(VoiceProtocol):
31-
"""Represents a Discord voice connection.
32-
33-
You do not create these, you typically get them from e.g. :meth:`VoiceChannel.connect`.
34-
35-
Attributes
36-
----------
37-
session_id: :class:`str`
38-
The voice connection session ID. You should not share this.
39-
token: :class:`str`
40-
The voice connection token. You should not share this.
41-
endpoint: :class:`str`
42-
The endpoint the current client is connected to.
43-
channel: :class:`abc.Connectable`
44-
The voice channel connected to.
45-
loop: :class:`asyncio.AbstractEventLoop`
46-
The event loop that the voice client is running on.
47-
48-
Warning
49-
-------
50-
In order to use PCM based AudioSources, you must have the opus library
51-
installed on your system and loaded through :func:`opus.load_opus`.
52-
Otherwise, your AudioSources must be opus encoded (e.g. using :class:`FFmpegOpusAudio`)
53-
or the library will not be able to transmit audio.
54-
"""
27+
# rn this is for typing, will be moved here in some point in the future
28+
from discord.voice_client import VoiceClient

discord/voice/enums.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
from discord.enums import Enum
28+
29+
30+
class OpCodes(Enum):
31+
# fmt: off
32+
identify = 0
33+
select_protocol = 1
34+
ready = 2
35+
heartbeat = 3
36+
session_description = 4
37+
speaking = 5
38+
heartbeat_ack = 6
39+
resume = 7
40+
hello = 8
41+
resumed = 9
42+
client_connect = 10
43+
client_disconnect = 11
44+
# fmt: on
45+
46+
def __eq__(self, other: object) -> bool:
47+
if isinstance(other, int):
48+
return self.value == other
49+
elif isinstance(other, self.__class__):
50+
return self is other
51+
return NotImplemented
52+
53+
def __int__(self) -> int:
54+
return self.value

discord/voice/errors.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)