diff --git a/docs/lavalink.rst b/docs/lavalink.rst index eaeaca0b..0254641a 100644 --- a/docs/lavalink.rst +++ b/docs/lavalink.rst @@ -124,6 +124,9 @@ Models .. autoclass:: DefaultPlayer :members: +.. autoclass:: Plugin + :members: + Node ---- .. autoclass:: Node diff --git a/lavalink/client.py b/lavalink/client.py index 6ac29699..8d458997 100644 --- a/lavalink/client.py +++ b/lavalink/client.py @@ -27,14 +27,14 @@ import random from collections import defaultdict from inspect import getmembers, ismethod -from typing import Set, Union +from typing import List, Set, Union from urllib.parse import quote import aiohttp from .errors import AuthenticationError, NodeError from .events import Event -from .models import DefaultPlayer, LoadResult, Source +from .models import DefaultPlayer, LoadResult, Plugin, Source from .node import Node from .nodemanager import NodeManager from .playermanager import PlayerManager @@ -329,6 +329,24 @@ async def routeplanner_free_all_failing(self, node: Node) -> bool: return await self._post_request('{}/routeplanner/free/all'.format(node.http_uri), headers={'Authorization': node.password}) + async def get_node_plugins(self, node: Node) -> List[Plugin]: + """|coro| + Retrieves a list of plugins active on the target node. + + Parameters + ---------- + node: :class:`Node` + The node to use for the query. + + Returns + ------- + List[:class:`Plugin`] + A list of Plugins active on the target node. + """ + data = await self._get_request('{}/plugins'.format(node.http_uri), + headers={'Authorization': node.password}) + return [Plugin(plugin) for plugin in data] + async def voice_update_handler(self, data): """|coro| This function intercepts websocket data from your Discord library and diff --git a/lavalink/models.py b/lavalink/models.py index 8b5a54d5..8e1fd341 100644 --- a/lavalink/models.py +++ b/lavalink/models.py @@ -985,3 +985,32 @@ async def change_node(self, node): def __repr__(self): return ''.format(self) + + +class Plugin: + """ + Represents a Lavalink server plugin. + + Parameters + ---------- + data: :class:`dict` + The data to initialise a Plugin from. + + Attributes + ---------- + name: :class:`str` + The name of the plugin. + version: :class:`str` + The version of the plugin. + """ + __slots__ = ('name', 'version') + + def __init__(self, data: dict): + self.name: str = data['name'] + self.version: str = data['version'] + + def __str__(self): + return '{0.name} v{0.version}'.format(self) + + def __repr__(self): + return ''.format(self) diff --git a/lavalink/node.py b/lavalink/node.py index 90f1e154..352801ce 100644 --- a/lavalink/node.py +++ b/lavalink/node.py @@ -164,6 +164,17 @@ async def routeplanner_free_all_failing(self): """ return await self._manager._lavalink.routeplanner_free_all_failing(self) + async def get_plugins(self): + """|coro| + Retrieves a list of plugins active on this node. + + Returns + ------- + List[:class:`Plugin`] + A list of active plugins. + """ + return await self._manager._lavalink.get_node_plugins(self) + async def _dispatch_event(self, event: Event): """|coro| Dispatches the given event to all registered hooks.