Skip to content

Commit

Permalink
Support specifying timeout for HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Sep 22, 2024
1 parent 64a538e commit fa80322
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lavalink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = 'Devoxin'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017-present Devoxin'
__version__ = '5.8.1'
__version__ = '5.9.0'


from typing import Type
Expand Down
9 changes: 6 additions & 3 deletions lavalink/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Client(Generic[PlayerT]):
the player was moved via the failover mechanism, the player will still move back to the original
node when it becomes available. This behaviour can be avoided in custom player implementations by
setting ``self._original_node`` to ``None`` in the :func:`BasePlayer.change_node` function.
request_timeout: Optional[:class:`aiohttp.ClientTimeout`]
A ``ClientTimeout`` object to be used for requests. If unspecified, defaults will be used.
Attributes
----------
Expand All @@ -90,15 +92,16 @@ class Client(Generic[PlayerT]):
__slots__ = ('_session', '_user_id', '_event_hooks', 'node_manager', 'player_manager', 'sources')

def __init__(self, user_id: Union[int, str], player: Type[PlayerT] = DefaultPlayer,
regions: Optional[Dict[str, Tuple[str]]] = None, connect_back: bool = False):
regions: Optional[Dict[str, Tuple[str]]] = None, connect_back: bool = False,
request_timeout: Optional[aiohttp.ClientTimeout] = None):
if not isinstance(user_id, (str, int)) or isinstance(user_id, bool):
# bool has special handling because it subclasses `int`, so will return True for the first isinstance check.
raise TypeError(f'user_id must be either an int or str (not {type(user_id).__name__}). If the type is None, '
'ensure your bot has fired "on_ready" before instantiating '
'the Lavalink client. Alternatively, you can hardcode your user ID.')

self._session: aiohttp.ClientSession = aiohttp.ClientSession()
self._user_id: int = int(user_id)
self._session = aiohttp.ClientSession(timeout=request_timeout)
self._user_id = int(user_id)
self._event_hooks = defaultdict(list)
self.node_manager: NodeManager = NodeManager(self, regions, connect_back)
self.player_manager: PlayerManager[PlayerT] = PlayerManager(self, player)
Expand Down
22 changes: 21 additions & 1 deletion lavalink/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,29 @@ class RawPlayerVoiceState(TypedDict):
sessionId: str


class RawTrackInfo(TypedDict):
identifier: str
isSeekable: bool
author: str
length: int
isStream: bool
position: int
title: str
uri: Optional[str]
artworkUrl: Optional[str]
isrc: Optional[str]
sourceName: str


class RawTrack(TypedDict):
encoded: str
info: RawTrackInfo
pluginInfo: Dict[str, Any]
userData: Dict[Any, Any]

class RawPlayer(TypedDict):
guildId: str
track: Optional[Dict[str, Any]] # TODO
track: Optional[RawTrack]
volume: int
paused: bool
state: RawPlayerState
Expand Down

0 comments on commit fa80322

Please sign in to comment.