Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra_event for unknown plugin events #263

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Added
- :meth:`wavelink.Node.fetch_player_info`
- :meth:`wavelink.Node.fetch_players`
- :attr:`wavelink.Playable.extras`
- :func:`wavelink.on_wavelink_extra_event`


Connecting
Expand Down
17 changes: 17 additions & 0 deletions docs/wavelink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ An event listener in a cog.
Called when a node has been closed and cleaned-up. The second parameter ``disconnected`` is a list of
:class:`wavelink.Player` that were connected on this Node and are now disconnected.

.. function:: on_wavelink_extra_event(payload: wavelink.ExtraEventPayload)

Called when an ``Unknown`` and/or ``Unhandled`` event is recevied via Lavalink. This is most likely due to
a plugin like SponsorBlock sending custom event data. The payload includes the raw data sent from Lavalink.

.. note::

Please see the documentation for your Lavalink plugins to determine what data they send.


.. versionadded:: 3.1.0


Types
-----
Expand Down Expand Up @@ -190,6 +202,11 @@ Payloads
.. autoclass:: InfoResponsePayload
:members:

.. attributetable:: ExtraEventPayload

.. autoclass:: ExtraEventPayload
:members:


Enums
-----
Expand Down
31 changes: 31 additions & 0 deletions wavelink/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"PlayerStatePayload",
"VoiceStatePayload",
"PlayerResponsePayload",
"ExtraEventPayload",
)


Expand Down Expand Up @@ -520,3 +521,33 @@ def __init__(self, data: InfoResponse) -> None:
self.source_managers: list[str] = data["sourceManagers"]
self.filters: list[str] = data["filters"]
self.plugins: list[PluginResponsePayload] = [PluginResponsePayload(p) for p in data["plugins"]]


class ExtraEventPayload:
"""Payload received in the :func:`on_wavelink_extra_event` event.

This payload is created when an ``Unknown`` and ``Unhandled`` event is received from Lavalink, most likely via
a plugin.

.. note::

See the appropriate documentation of the plugin for the data sent with these events.


Attributes
----------
node: :class:`~wavelink.Node`
The node that the event pertains to.
player: :class:`~wavelink.Player` | None
The player associated with this event. Could be None.
data: dict[str, Any]
The raw data sent from Lavalink for this event.


.. versionadded:: 3.1.0
"""

def __init__(self, *, node: Node, player: Player | None, data: dict[str, Any]) -> None:
self.node = node
self.player = player
self.data = data
3 changes: 2 additions & 1 deletion wavelink/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ async def keep_alive(self) -> None:
self.dispatch("websocket_closed", wcpayload)

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

Expand Down