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

Commit 52b863c

Browse files
authored
Fix/plugin filters (#307)
* Add support for plugin filters * Bump version * Add missing PluginFilters to docs
1 parent f548a3b commit 52b863c

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

docs/wavelink.rst

+5
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ Filters
387387
.. autoclass:: LowPass
388388
:members:
389389

390+
.. attributetable:: PluginFilters
391+
392+
.. autoclass:: PluginFilters
393+
:members:
394+
390395

391396
Utils
392397
-----

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "wavelink"
7-
version = "3.3.0"
7+
version = "3.4.0"
88
authors = [
99
{ name="PythonistaGuild, EvieePy", email="[email protected]" },
1010
]

wavelink/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__author__ = "PythonistaGuild, EvieePy"
2727
__license__ = "MIT"
2828
__copyright__ = "Copyright 2019-Present (c) PythonistaGuild, EvieePy"
29-
__version__ = "3.3.0"
29+
__version__ = "3.4.0"
3030

3131

3232
from .enums import *

wavelink/filters.py

+81-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING, TypedDict
27+
from typing import TYPE_CHECKING, Any, TypedDict
2828

2929

3030
if TYPE_CHECKING:
@@ -56,6 +56,7 @@
5656
"Distortion",
5757
"ChannelMix",
5858
"LowPass",
59+
"PluginFilters",
5960
)
6061

6162

@@ -70,6 +71,7 @@ class FiltersOptions(TypedDict, total=False):
7071
distortion: Distortion
7172
channel_mix: ChannelMix
7273
low_pass: LowPass
74+
plugin_filters: PluginFilters
7375
reset: bool
7476

7577

@@ -583,6 +585,68 @@ def __repr__(self) -> str:
583585
return f"<LowPass: {self._payload}>"
584586

585587

588+
class PluginFilters:
589+
"""The PluginFilters class.
590+
591+
This class handles setting filters on plugins that support setting filter values.
592+
See the documentation of the Lavalink Plugin for more information on the values that can be set.
593+
594+
This class takes in a ``dict[str, Any]`` usually in the form of:
595+
596+
.. code:: python3
597+
598+
{"pluginName": {"filterKey": "filterValue"}, ...}
599+
600+
601+
.. warning::
602+
603+
Do NOT include the ``"pluginFilters"`` top level key when setting your values for this class.
604+
"""
605+
606+
def __init__(self, payload: dict[str, Any]) -> None:
607+
self._payload = payload
608+
609+
def set(self, **options: dict[str, Any]) -> Self:
610+
"""Set the properties of this filter.
611+
612+
This method accepts keyword argument pairs OR you can alternatively unpack a dictionary.
613+
See the documentation of the Lavalink Plugin for more information on the values that can be set.
614+
615+
Examples
616+
--------
617+
618+
.. code:: python3
619+
620+
plugin_filters: PluginFilters = PluginFilters()
621+
plugin_filters.set(pluginName={"filterKey": "filterValue", ...})
622+
623+
# OR...
624+
625+
plugin_filters.set(**{"pluginName": {"filterKey": "filterValue", ...}})
626+
"""
627+
self._payload.update(options)
628+
return self
629+
630+
def reset(self) -> Self:
631+
"""Reset this filter to its defaults."""
632+
self._payload: dict[str, Any] = {}
633+
return self
634+
635+
@property
636+
def payload(self) -> dict[str, Any]:
637+
"""The raw payload associated with this filter.
638+
639+
This property returns a copy.
640+
"""
641+
return self._payload.copy()
642+
643+
def __str__(self) -> str:
644+
return "PluginFilters"
645+
646+
def __repr__(self) -> str:
647+
return f"<PluginFilters: {self._payload}"
648+
649+
586650
class Filters:
587651
"""The wavelink Filters class.
588652
@@ -659,6 +723,7 @@ def __init__(self, *, data: FilterPayload | None = None) -> None:
659723
self._distortion: Distortion = Distortion({})
660724
self._channel_mix: ChannelMix = ChannelMix({})
661725
self._low_pass: LowPass = LowPass({})
726+
self._plugin_filters: PluginFilters = PluginFilters({})
662727

663728
if data:
664729
self._create_from(data)
@@ -674,6 +739,7 @@ def _create_from(self, data: FilterPayload) -> None:
674739
self._distortion = Distortion(data.get("distortion", {}))
675740
self._channel_mix = ChannelMix(data.get("channelMix", {}))
676741
self._low_pass = LowPass(data.get("lowPass", {}))
742+
self._plugin_filters = PluginFilters(data.get("pluginFilters", {}))
677743

678744
def _set_with_reset(self, filters: FiltersOptions) -> None:
679745
self._volume = filters.get("volume")
@@ -686,6 +752,7 @@ def _set_with_reset(self, filters: FiltersOptions) -> None:
686752
self._distortion = filters.get("distortion", Distortion({}))
687753
self._channel_mix = filters.get("channel_mix", ChannelMix({}))
688754
self._low_pass = filters.get("low_pass", LowPass({}))
755+
self._plugin_filters = filters.get("plugin_filters", PluginFilters({}))
689756

690757
def set_filters(self, **filters: Unpack[FiltersOptions]) -> None:
691758
"""Set multiple filters at once to a standalone Filter object.
@@ -713,6 +780,8 @@ def set_filters(self, **filters: Unpack[FiltersOptions]) -> None:
713780
The ChannelMix filter to apply to the player.
714781
low_pass: :class:`wavelink.LowPass`
715782
The LowPass filter to apply to the player.
783+
plugin_filters: :class:`wavelink.PluginFilters`
784+
The extra Plugin Filters to apply to the player. See :class:`~wavelink.PluginFilters` for more details.
716785
reset: bool
717786
Whether to reset all filters that were not specified.
718787
"""
@@ -732,6 +801,7 @@ def set_filters(self, **filters: Unpack[FiltersOptions]) -> None:
732801
self._distortion = filters.get("distortion", self._distortion)
733802
self._channel_mix = filters.get("channel_mix", self._channel_mix)
734803
self._low_pass = filters.get("low_pass", self._low_pass)
804+
self._plugin_filters = filters.get("plugin_filters", self._plugin_filters)
735805

736806
def _reset(self) -> None:
737807
self._volume = None
@@ -744,6 +814,7 @@ def _reset(self) -> None:
744814
self._distortion = Distortion({})
745815
self._channel_mix = ChannelMix({})
746816
self._low_pass = LowPass({})
817+
self._plugin_filters = PluginFilters({})
747818

748819
def reset(self) -> None:
749820
"""Method which resets this object to an original state.
@@ -778,6 +849,8 @@ def from_filters(cls, **filters: Unpack[FiltersOptions]) -> Self:
778849
The ChannelMix filter to apply to the player.
779850
low_pass: :class:`wavelink.LowPass`
780851
The LowPass filter to apply to the player.
852+
plugin_filters: :class:`wavelink.PluginFilters`
853+
The extra Plugin Filters to apply to the player. See :class:`~wavelink.PluginFilters` for more details.
781854
reset: bool
782855
Whether to reset all filters that were not specified.
783856
"""
@@ -844,6 +917,11 @@ def low_pass(self) -> LowPass:
844917
"""Property which returns the :class:`~wavelink.LowPass` filter associated with this Filters payload."""
845918
return self._low_pass
846919

920+
@property
921+
def plugin_filters(self) -> PluginFilters:
922+
"""Property which returns the :class:`~wavelink.PluginFilters` filters associated with this Filters payload."""
923+
return self._plugin_filters
924+
847925
def __call__(self) -> FilterPayload:
848926
payload: FilterPayload = {
849927
"volume": self._volume,
@@ -856,6 +934,7 @@ def __call__(self) -> FilterPayload:
856934
"distortion": self._distortion._payload,
857935
"channelMix": self._channel_mix._payload,
858936
"lowPass": self._low_pass._payload,
937+
"pluginFilters": self._plugin_filters._payload,
859938
}
860939

861940
for key, value in payload.copy().items():
@@ -869,5 +948,5 @@ def __repr__(self) -> str:
869948
f"<Filters: volume={self._volume}, equalizer={self._equalizer!r}, karaoke={self._karaoke!r},"
870949
f" timescale={self._timescale!r}, tremolo={self._tremolo!r}, vibrato={self._vibrato!r},"
871950
f" rotation={self._rotation!r}, distortion={self._distortion!r}, channel_mix={self._channel_mix!r},"
872-
f" low_pass={self._low_pass!r}>"
951+
f" low_pass={self._low_pass!r}, plugin_filters={self._plugin_filters!r}>"
873952
)

0 commit comments

Comments
 (0)