Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 5f926ea

Browse files
authored
Merge pull request #263 from PythonistaGuild/feature/extra-events
Add extra_event for unknown plugin events
2 parents a9ed696 + 59efffa commit 5f926ea

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

docs/migrating.rst

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Added
8686
- :meth:`wavelink.Node.fetch_player_info`
8787
- :meth:`wavelink.Node.fetch_players`
8888
- :attr:`wavelink.Playable.extras`
89+
- :func:`wavelink.on_wavelink_extra_event`
8990

9091

9192
Connecting

docs/wavelink.rst

+17
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ An event listener in a cog.
7777
Called when a node has been closed and cleaned-up. The second parameter ``disconnected`` is a list of
7878
:class:`wavelink.Player` that were connected on this Node and are now disconnected.
7979

80+
.. function:: on_wavelink_extra_event(payload: wavelink.ExtraEventPayload)
81+
82+
Called when an ``Unknown`` and/or ``Unhandled`` event is recevied via Lavalink. This is most likely due to
83+
a plugin like SponsorBlock sending custom event data. The payload includes the raw data sent from Lavalink.
84+
85+
.. note::
86+
87+
Please see the documentation for your Lavalink plugins to determine what data they send.
88+
89+
90+
.. versionadded:: 3.1.0
91+
8092

8193
Types
8294
-----
@@ -190,6 +202,11 @@ Payloads
190202
.. autoclass:: InfoResponsePayload
191203
:members:
192204

205+
.. attributetable:: ExtraEventPayload
206+
207+
.. autoclass:: ExtraEventPayload
208+
:members:
209+
193210

194211
Enums
195212
-----

wavelink/payloads.py

+31
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"PlayerStatePayload",
6363
"VoiceStatePayload",
6464
"PlayerResponsePayload",
65+
"ExtraEventPayload",
6566
)
6667

6768

@@ -520,3 +521,33 @@ def __init__(self, data: InfoResponse) -> None:
520521
self.source_managers: list[str] = data["sourceManagers"]
521522
self.filters: list[str] = data["filters"]
522523
self.plugins: list[PluginResponsePayload] = [PluginResponsePayload(p) for p in data["plugins"]]
524+
525+
526+
class ExtraEventPayload:
527+
"""Payload received in the :func:`on_wavelink_extra_event` event.
528+
529+
This payload is created when an ``Unknown`` and ``Unhandled`` event is received from Lavalink, most likely via
530+
a plugin.
531+
532+
.. note::
533+
534+
See the appropriate documentation of the plugin for the data sent with these events.
535+
536+
537+
Attributes
538+
----------
539+
node: :class:`~wavelink.Node`
540+
The node that the event pertains to.
541+
player: :class:`~wavelink.Player` | None
542+
The player associated with this event. Could be None.
543+
data: dict[str, Any]
544+
The raw data sent from Lavalink for this event.
545+
546+
547+
.. versionadded:: 3.1.0
548+
"""
549+
550+
def __init__(self, *, node: Node, player: Player | None, data: dict[str, Any]) -> None:
551+
self.node = node
552+
self.player = player
553+
self.data = data

wavelink/websocket.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ async def keep_alive(self) -> None:
239239
self.dispatch("websocket_closed", wcpayload)
240240

241241
else:
242-
logger.debug(f"Received unknown event type from Lavalink '{data['type']}'. Disregarding.")
242+
other_payload: ExtraEventPayload = ExtraEventPayload(node=self.node, player=player, data=data)
243+
self.dispatch("extra_event", other_payload)
243244
else:
244245
logger.debug(f"'Received an unknown OP from Lavalink '{data['op']}'. Disregarding.")
245246

0 commit comments

Comments
 (0)