mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-09 11:31:58 +00:00
Fix typing in voice related files
This commit is contained in:
parent
437d451d4e
commit
70b577e94b
@ -104,7 +104,7 @@ if TYPE_CHECKING:
|
|||||||
from .voice_client import VoiceProtocol
|
from .voice_client import VoiceProtocol
|
||||||
|
|
||||||
VocalGuildChannel = Union[VoiceChannel, StageChannel]
|
VocalGuildChannel = Union[VoiceChannel, StageChannel]
|
||||||
GuildChannel = Union[VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel]
|
GuildChannel = Union[VocalGuildChannel, TextChannel, CategoryChannel, StoreChannel]
|
||||||
ByCategoryItem = Tuple[Optional[CategoryChannel], List[GuildChannel]]
|
ByCategoryItem = Tuple[Optional[CategoryChannel], List[GuildChannel]]
|
||||||
|
|
||||||
|
|
||||||
@ -3069,7 +3069,7 @@ class Guild(Hashable):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def change_voice_state(
|
async def change_voice_state(
|
||||||
self, *, channel: Optional[VocalGuildChannel], self_mute: bool = False, self_deaf: bool = False
|
self, *, channel: Optional[abc.Snowflake], self_mute: bool = False, self_deaf: bool = False
|
||||||
):
|
):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -3079,7 +3079,7 @@ class Guild(Hashable):
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
channel: Optional[:class:`VoiceChannel`]
|
channel: Optional[:class:`abc.Snowflake`]
|
||||||
Channel the client wants to join. Use ``None`` to disconnect.
|
Channel the client wants to join. Use ``None`` to disconnect.
|
||||||
self_mute: :class:`bool`
|
self_mute: :class:`bool`
|
||||||
Indicates if the client should be self-muted.
|
Indicates if the client should be self-muted.
|
||||||
|
@ -69,7 +69,7 @@ c_int_ptr = ctypes.POINTER(ctypes.c_int)
|
|||||||
c_int16_ptr = ctypes.POINTER(ctypes.c_int16)
|
c_int16_ptr = ctypes.POINTER(ctypes.c_int16)
|
||||||
c_float_ptr = ctypes.POINTER(ctypes.c_float)
|
c_float_ptr = ctypes.POINTER(ctypes.c_float)
|
||||||
|
|
||||||
_lib = None
|
_lib: Any = None
|
||||||
|
|
||||||
|
|
||||||
class EncoderStruct(ctypes.Structure):
|
class EncoderStruct(ctypes.Structure):
|
||||||
|
@ -161,7 +161,7 @@ class FFmpegAudio(AudioSource):
|
|||||||
kwargs.update(subprocess_kwargs)
|
kwargs.update(subprocess_kwargs)
|
||||||
|
|
||||||
self._process: subprocess.Popen = self._spawn_process(args, **kwargs)
|
self._process: subprocess.Popen = self._spawn_process(args, **kwargs)
|
||||||
self._stdout: IO[bytes] = self._process.stdout # type: ignore
|
self._stdout: IO[bytes] = self._process.stdout # type: ignore - process stdout is explicitly set
|
||||||
self._stdin: Optional[IO[bytes]] = None
|
self._stdin: Optional[IO[bytes]] = None
|
||||||
self._pipe_thread: Optional[threading.Thread] = None
|
self._pipe_thread: Optional[threading.Thread] = None
|
||||||
|
|
||||||
@ -210,7 +210,8 @@ class FFmpegAudio(AudioSource):
|
|||||||
self._process.terminate()
|
self._process.terminate()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self._stdin.write(data) # type: ignore
|
if self._stdin is not None:
|
||||||
|
self._stdin.write(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
_log.debug('Write error for %s, this is probably not a problem', self, exc_info=True)
|
_log.debug('Write error for %s, this is probably not a problem', self, exc_info=True)
|
||||||
# at this point the source data is either exhausted or the process is fubar
|
# at this point the source data is either exhausted or the process is fubar
|
||||||
@ -359,7 +360,7 @@ class FFmpegOpusAudio(FFmpegAudio):
|
|||||||
self,
|
self,
|
||||||
source: Union[str, io.BufferedIOBase],
|
source: Union[str, io.BufferedIOBase],
|
||||||
*,
|
*,
|
||||||
bitrate: int = 128,
|
bitrate: Optional[int] = None,
|
||||||
codec: Optional[str] = None,
|
codec: Optional[str] = None,
|
||||||
executable: str = 'ffmpeg',
|
executable: str = 'ffmpeg',
|
||||||
pipe=False,
|
pipe=False,
|
||||||
@ -378,6 +379,7 @@ class FFmpegOpusAudio(FFmpegAudio):
|
|||||||
args.append('-' if pipe else source)
|
args.append('-' if pipe else source)
|
||||||
|
|
||||||
codec = 'copy' if codec in ('opus', 'libopus') else 'libopus'
|
codec = 'copy' if codec in ('opus', 'libopus') else 'libopus'
|
||||||
|
bitrate = bitrate if bitrate is not None else 128
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
args.extend(('-map_metadata', '-1',
|
args.extend(('-map_metadata', '-1',
|
||||||
@ -462,7 +464,7 @@ class FFmpegOpusAudio(FFmpegAudio):
|
|||||||
|
|
||||||
executable = kwargs.get('executable')
|
executable = kwargs.get('executable')
|
||||||
codec, bitrate = await cls.probe(source, method=method, executable=executable)
|
codec, bitrate = await cls.probe(source, method=method, executable=executable)
|
||||||
return cls(source, bitrate=bitrate, codec=codec, **kwargs) # type: ignore
|
return cls(source, bitrate=bitrate, codec=codec, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def probe(
|
async def probe(
|
||||||
@ -494,7 +496,7 @@ class FFmpegOpusAudio(FFmpegAudio):
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
---------
|
---------
|
||||||
Optional[Tuple[Optional[:class:`str`], Optional[:class:`int`]]]
|
Optional[Tuple[Optional[:class:`str`], :class:`int`]]
|
||||||
A 2-tuple with the codec and bitrate of the input source.
|
A 2-tuple with the codec and bitrate of the input source.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import socket
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
import threading
|
import threading
|
||||||
from typing import Any, Callable, List, Optional, TYPE_CHECKING, Tuple
|
from typing import Any, Callable, List, Optional, TYPE_CHECKING, Tuple, Union
|
||||||
|
|
||||||
from . import opus, utils
|
from . import opus, utils
|
||||||
from .backoff import ExponentialBackoff
|
from .backoff import ExponentialBackoff
|
||||||
@ -59,6 +59,7 @@ if TYPE_CHECKING:
|
|||||||
from .state import ConnectionState
|
from .state import ConnectionState
|
||||||
from .user import ClientUser
|
from .user import ClientUser
|
||||||
from .opus import Encoder
|
from .opus import Encoder
|
||||||
|
from .channel import StageChannel, VoiceChannel
|
||||||
from . import abc
|
from . import abc
|
||||||
|
|
||||||
from .types.voice import (
|
from .types.voice import (
|
||||||
@ -67,6 +68,8 @@ if TYPE_CHECKING:
|
|||||||
SupportedModes,
|
SupportedModes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
VocalGuildChannel = Union[VoiceChannel, StageChannel]
|
||||||
|
|
||||||
|
|
||||||
has_nacl: bool
|
has_nacl: bool
|
||||||
|
|
||||||
@ -217,18 +220,19 @@ class VoiceClient(VoiceProtocol):
|
|||||||
The voice connection token.
|
The voice connection token.
|
||||||
endpoint: :class:`str`
|
endpoint: :class:`str`
|
||||||
The endpoint we are connecting to.
|
The endpoint we are connecting to.
|
||||||
channel: :class:`abc.Connectable`
|
channel: Union[:class:`VoiceChannel`, :class:`StageChannel`]
|
||||||
The voice channel connected to.
|
The voice channel connected to.
|
||||||
loop: :class:`asyncio.AbstractEventLoop`
|
loop: :class:`asyncio.AbstractEventLoop`
|
||||||
The event loop that the voice client is running on.
|
The event loop that the voice client is running on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
channel: VocalGuildChannel
|
||||||
endpoint_ip: str
|
endpoint_ip: str
|
||||||
voice_port: int
|
voice_port: int
|
||||||
secret_key: List[int]
|
secret_key: List[int]
|
||||||
ssrc: int
|
ssrc: int
|
||||||
|
|
||||||
def __init__(self, client: Client, channel: abc.Connectable):
|
def __init__(self, client: Client, channel: VocalGuildChannel):
|
||||||
if not has_nacl:
|
if not has_nacl:
|
||||||
raise RuntimeError("PyNaCl library needed in order to use voice")
|
raise RuntimeError("PyNaCl library needed in order to use voice")
|
||||||
|
|
||||||
@ -265,14 +269,14 @@ class VoiceClient(VoiceProtocol):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def guild(self) -> Optional[Guild]:
|
def guild(self) -> Guild:
|
||||||
"""Optional[:class:`Guild`]: The guild we're connected to, if applicable."""
|
""":class:`Guild`: The guild we're connected to."""
|
||||||
return getattr(self.channel, 'guild', None)
|
return self.channel.guild
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user(self) -> ClientUser:
|
def user(self) -> ClientUser:
|
||||||
""":class:`ClientUser`: The user connected to voice (i.e. ourselves)."""
|
""":class:`ClientUser`: The user connected to voice (i.e. ourselves)."""
|
||||||
return self._state.user
|
return self._state.user # type: ignore - user can't be None after login
|
||||||
|
|
||||||
def checked_add(self, attr, value, limit):
|
def checked_add(self, attr, value, limit):
|
||||||
val = getattr(self, attr)
|
val = getattr(self, attr)
|
||||||
@ -295,8 +299,7 @@ class VoiceClient(VoiceProtocol):
|
|||||||
# We're being disconnected so cleanup
|
# We're being disconnected so cleanup
|
||||||
await self.disconnect()
|
await self.disconnect()
|
||||||
else:
|
else:
|
||||||
guild = self.guild
|
self.channel = channel_id and self.guild.get_channel(int(channel_id)) # type: ignore - this won't be None
|
||||||
self.channel = channel_id and guild and guild.get_channel(int(channel_id)) # type: ignore
|
|
||||||
else:
|
else:
|
||||||
self._voice_state_complete.set()
|
self._voice_state_complete.set()
|
||||||
|
|
||||||
@ -305,7 +308,7 @@ class VoiceClient(VoiceProtocol):
|
|||||||
_log.info('Ignoring extraneous voice server update.')
|
_log.info('Ignoring extraneous voice server update.')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.token = data.get('token')
|
self.token = data['token']
|
||||||
self.server_id = int(data['guild_id'])
|
self.server_id = int(data['guild_id'])
|
||||||
endpoint = data.get('endpoint')
|
endpoint = data.get('endpoint')
|
||||||
|
|
||||||
@ -506,14 +509,14 @@ class VoiceClient(VoiceProtocol):
|
|||||||
if self.socket:
|
if self.socket:
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
|
|
||||||
async def move_to(self, channel: abc.Snowflake) -> None:
|
async def move_to(self, channel: Optional[abc.Snowflake]) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Moves you to a different voice channel.
|
Moves you to a different voice channel.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
channel: :class:`abc.Snowflake`
|
channel: Optional[:class:`abc.Snowflake`]
|
||||||
The channel to move to. Must be a voice channel.
|
The channel to move to. Must be a voice channel.
|
||||||
"""
|
"""
|
||||||
await self.channel.guild.change_voice_state(channel=channel)
|
await self.channel.guild.change_voice_state(channel=channel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user