Skip to content

Commit

Permalink
updates for py3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhnsy committed Jan 22, 2024
1 parent d1433d0 commit 7b61aa3
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 404 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-present Aaron Hennessey (Axelancerr/Axel)
Copyright (c) 2019-present Aaron Hennessey (aaronhnsy)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ pip install discord-ext-lava
## Support

- [Documentation](https://discord-ext-lava.readthedocs.io/)
- [GitHub](https://github.com/Axelancerr/discord-ext-lava)
- [Discord](https://discord.com/invite/w9f6NkQbde)
- [GitHub](https://github.com/aaronhnsy/discord-ext-lava)
8 changes: 4 additions & 4 deletions discord/ext/lava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class VersionInfo(NamedTuple):
__version__: str = "1.0.0a1"

__title__: str = "discord-ext-lava"
__url__: str = "https://github.com/Axelancerr/discord-ext-lava"
__url__: str = "https://github.com/aaronhnsy/discord-ext-lava"

__author__: str = "Aaron Hennessey (Axelancerr)"
__email__: str = "axelancerr@gmail.com"
__author__: str = "Aaron Hennessey (aaronhnsy)"
__email__: str = "aaronhnsy@gmail.com"

__license__: str = "MIT"
__copyright__: str = "Copyright (c) 2019-present Aaron Hennessey (Axelancerr/Axel)"
__copyright__: str = "Copyright (c) 2019-present Aaron Hennessey (aaronhnsy)"

logging.getLogger("discord.ext.lava")
29 changes: 10 additions & 19 deletions discord/ext/lava/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
from .objects.stats import Stats
from .objects.track import Track
from .types.common import JSON, JSONDumps, JSONLoads, SpotifySearchType
from .types.rest import (
EmptyResultData, ErrorResultData, PlaylistResultData, RequestData, RequestKwargs, RequestMethod, RequestParameters,
SearchData, SearchResultData, TrackResultData,
)
from .types.websocket import EventPayload, Payload, PlayerUpdatePayload, ReadyPayload, StatsPayload
from .types.rest import RequestData, RequestKwargs, RequestMethod, RequestParameters, SearchData
from .types.websocket import Payload

if TYPE_CHECKING:
from .player import Player # type: ignore
# noinspection PyUnresolvedReferences
from .player import Player


__all__ = ["Link"]
Expand Down Expand Up @@ -178,15 +176,13 @@ async def _process_payload(self, payload: Payload, /) -> None:
f"Link '{self.identifier}' received a '{payload['op']}' payload.\n%s",
DeferredMessage(_json.dumps, payload, indent=4),
)
match op := payload["op"]:
match payload["op"]:
case "ready":
assert isinstance(payload, ReadyPayload)
self._session_id = payload["sessionId"]
self._ready_event.set()
__ws_log__.info(f"Link '{self.identifier}' is ready.")

case "playerUpdate":
assert isinstance(payload, PlayerUpdatePayload)
if not (player := self._players.get(int(payload["guildId"]))):
__ws_log__.warning(
f"Link '{self.identifier}' received a player update for a non-existent player "
Expand All @@ -196,11 +192,9 @@ async def _process_payload(self, payload: Payload, /) -> None:
await player._handle_player_update(payload)

case "stats":
assert isinstance(payload, StatsPayload)
self._stats = Stats(payload)

case "event":
assert isinstance(payload, EventPayload)
if not (player := self._players.get(int(payload["guildId"]))):
__ws_log__.warning(
f"Link '{self.identifier}' received a '{payload['type']}' event for a non-existent player "
Expand All @@ -210,7 +204,9 @@ async def _process_payload(self, payload: Payload, /) -> None:
await player._handle_event(payload)

case _: # pyright: ignore - lavalink could add new op codes.
__ws_log__.error(f"Link '{self.identifier}' received a payload with an unhandled op code: '{op}'.")
__ws_log__.error(
f"Link '{self.identifier}' received a payload with an unhandled op code: '{payload["op"]}'."
)

async def _listen(self) -> None:
while True:
Expand Down Expand Up @@ -343,27 +339,22 @@ async def _lavalink_search(self, search: str, /) -> Result:
SearchData,
await self._request("GET", "/v4/loadtracks", parameters={"identifier": search})
)
match load_type := data["loadType"]:
match data["loadType"]:
case "track":
assert isinstance(data, TrackResultData)
source = Track(data["data"])
tracks = [source]
case "playlist":
assert isinstance(data, PlaylistResultData)
source = Playlist(data["data"])
tracks = source.tracks
case "search":
assert isinstance(data, SearchResultData)
source = [Track(track) for track in data["data"]]
tracks = source
case "empty":
assert isinstance(data, EmptyResultData)
raise NoSearchResults(search=search)
case "error":
assert isinstance(data, ErrorResultData)
raise SearchFailed(data["data"])
case _: # pyright: ignore - lavalink could add new load types
msg = f"Unknown load type: '{load_type}'. Please report this to the library author."
msg = f"Unknown load type: '{data["load_type"]}'. Please report this to the library author."
__rest_log__.error(msg)
raise SearchError(msg)
return Result(source=source, tracks=tracks)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</svg>
"""

_GITHUB: str = "https://github.com/Axelancerr/discord-ext-lava"
_GITHUB: str = "https://github.com/aaronhnsy/discord-ext-lava"
_GITHUB_SVG: str = """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ Development

.. code-block:: shell
pip install -U git+https://github.com/Axelancerr/discord-ext-lava.git@main
pip install -U git+https://github.com/aaronhnsy/discord-ext-lava.git@main
.. tab:: Branch

.. code-block:: shell
pip install -U git+https://github.com/Axelancerr/[email protected]
pip install -U git+https://github.com/aaronhnsy/[email protected]
.. tab:: Tag

.. code-block:: shell
pip install -U git+https://github.com/Axelancerr/[email protected]
pip install -U git+https://github.com/aaronhnsy/[email protected]
.. tab:: Commit

.. code-block:: shell
pip install -U git+https://github.com/Axelancerr/discord-ext-lava.git@1ce8768
pip install -U git+https://github.com/aaronhnsy/discord-ext-lava.git@1ce8768
Loading

0 comments on commit 7b61aa3

Please sign in to comment.