24
24
25
25
from __future__ import annotations
26
26
27
- from typing import TYPE_CHECKING , TypedDict
27
+ from typing import TYPE_CHECKING , Any , TypedDict
28
28
29
29
30
30
if TYPE_CHECKING :
56
56
"Distortion" ,
57
57
"ChannelMix" ,
58
58
"LowPass" ,
59
+ "PluginFilters" ,
59
60
)
60
61
61
62
@@ -70,6 +71,7 @@ class FiltersOptions(TypedDict, total=False):
70
71
distortion : Distortion
71
72
channel_mix : ChannelMix
72
73
low_pass : LowPass
74
+ plugin_filters : PluginFilters
73
75
reset : bool
74
76
75
77
@@ -583,6 +585,68 @@ def __repr__(self) -> str:
583
585
return f"<LowPass: { self ._payload } >"
584
586
585
587
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
+
586
650
class Filters :
587
651
"""The wavelink Filters class.
588
652
@@ -659,6 +723,7 @@ def __init__(self, *, data: FilterPayload | None = None) -> None:
659
723
self ._distortion : Distortion = Distortion ({})
660
724
self ._channel_mix : ChannelMix = ChannelMix ({})
661
725
self ._low_pass : LowPass = LowPass ({})
726
+ self ._plugin_filters : PluginFilters = PluginFilters ({})
662
727
663
728
if data :
664
729
self ._create_from (data )
@@ -674,6 +739,7 @@ def _create_from(self, data: FilterPayload) -> None:
674
739
self ._distortion = Distortion (data .get ("distortion" , {}))
675
740
self ._channel_mix = ChannelMix (data .get ("channelMix" , {}))
676
741
self ._low_pass = LowPass (data .get ("lowPass" , {}))
742
+ self ._plugin_filters = PluginFilters (data .get ("pluginFilters" , {}))
677
743
678
744
def _set_with_reset (self , filters : FiltersOptions ) -> None :
679
745
self ._volume = filters .get ("volume" )
@@ -686,6 +752,7 @@ def _set_with_reset(self, filters: FiltersOptions) -> None:
686
752
self ._distortion = filters .get ("distortion" , Distortion ({}))
687
753
self ._channel_mix = filters .get ("channel_mix" , ChannelMix ({}))
688
754
self ._low_pass = filters .get ("low_pass" , LowPass ({}))
755
+ self ._plugin_filters = filters .get ("plugin_filters" , PluginFilters ({}))
689
756
690
757
def set_filters (self , ** filters : Unpack [FiltersOptions ]) -> None :
691
758
"""Set multiple filters at once to a standalone Filter object.
@@ -713,6 +780,8 @@ def set_filters(self, **filters: Unpack[FiltersOptions]) -> None:
713
780
The ChannelMix filter to apply to the player.
714
781
low_pass: :class:`wavelink.LowPass`
715
782
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.
716
785
reset: bool
717
786
Whether to reset all filters that were not specified.
718
787
"""
@@ -732,6 +801,7 @@ def set_filters(self, **filters: Unpack[FiltersOptions]) -> None:
732
801
self ._distortion = filters .get ("distortion" , self ._distortion )
733
802
self ._channel_mix = filters .get ("channel_mix" , self ._channel_mix )
734
803
self ._low_pass = filters .get ("low_pass" , self ._low_pass )
804
+ self ._plugin_filters = filters .get ("plugin_filters" , self ._plugin_filters )
735
805
736
806
def _reset (self ) -> None :
737
807
self ._volume = None
@@ -744,6 +814,7 @@ def _reset(self) -> None:
744
814
self ._distortion = Distortion ({})
745
815
self ._channel_mix = ChannelMix ({})
746
816
self ._low_pass = LowPass ({})
817
+ self ._plugin_filters = PluginFilters ({})
747
818
748
819
def reset (self ) -> None :
749
820
"""Method which resets this object to an original state.
@@ -778,6 +849,8 @@ def from_filters(cls, **filters: Unpack[FiltersOptions]) -> Self:
778
849
The ChannelMix filter to apply to the player.
779
850
low_pass: :class:`wavelink.LowPass`
780
851
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.
781
854
reset: bool
782
855
Whether to reset all filters that were not specified.
783
856
"""
@@ -844,6 +917,11 @@ def low_pass(self) -> LowPass:
844
917
"""Property which returns the :class:`~wavelink.LowPass` filter associated with this Filters payload."""
845
918
return self ._low_pass
846
919
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
+
847
925
def __call__ (self ) -> FilterPayload :
848
926
payload : FilterPayload = {
849
927
"volume" : self ._volume ,
@@ -856,6 +934,7 @@ def __call__(self) -> FilterPayload:
856
934
"distortion" : self ._distortion ._payload ,
857
935
"channelMix" : self ._channel_mix ._payload ,
858
936
"lowPass" : self ._low_pass ._payload ,
937
+ "pluginFilters" : self ._plugin_filters ._payload ,
859
938
}
860
939
861
940
for key , value in payload .copy ().items ():
@@ -869,5 +948,5 @@ def __repr__(self) -> str:
869
948
f"<Filters: volume={ self ._volume } , equalizer={ self ._equalizer !r} , karaoke={ self ._karaoke !r} ,"
870
949
f" timescale={ self ._timescale !r} , tremolo={ self ._tremolo !r} , vibrato={ self ._vibrato !r} ,"
871
950
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 } >"
873
952
)
0 commit comments