-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcog.py
More file actions
1363 lines (1300 loc) · 57.9 KB
/
cog.py
File metadata and controls
1363 lines (1300 loc) · 57.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import typing
from pathlib import Path
import discord
from discord import app_commands
from discord.app_commands import Range
from redbot.core import Config, commands
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import box
from tabulate import tabulate
from pylav.constants.misc import EQ_BAND_MAPPING
from pylav.core.context import PyLavContext
from pylav.exceptions.node import NodeHasNoFiltersException
from pylav.extension.red.converters.equalizer import BassBoostConverter
from pylav.extension.red.utils.decorators import invoker_is_dj, requires_player
from pylav.helpers.format.ascii import EightBitANSI
from pylav.helpers.format.strings import shorten_string
from pylav.logging import getLogger
from pylav.players.filters import Equalizer
from pylav.storage.models.equilizer import Equalizer as Equalizer_namespace_conflict
from pylav.type_hints.bot import DISCORD_BOT_TYPE, DISCORD_COG_TYPE_MIXIN, DISCORD_INTERACTION_TYPE
from pylav.type_hints.dict_typing import JSON_DICT_TYPE
LOGGER = getLogger("PyLav.cog.Effects")
_ = Translator("PyLavEffects", Path(__file__))
@cog_i18n(_)
class PyLavEffects(DISCORD_COG_TYPE_MIXIN):
"""Apply filters and effects to the PyLav player"""
__version__ = "1.0.0"
slash_fx = app_commands.Group(name="fx", description="Apply or remove filters", extras={"red_force_enable": True})
def __init__(self, bot: DISCORD_BOT_TYPE, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bot = bot
self._config = Config.get_conf(self, identifier=208903205982044161)
self._config.register_global(enable_slash=True)
self._config.register_guild(persist_fx=False, persist_eq=False)
@commands.group(name="fxset")
@commands.guild_only()
@commands.guildowner_or_permissions(manage_guild=True)
async def command_fxset(self, ctx: PyLavContext) -> None:
"""Configure the Player behaviour when an effect is set"""
@command_fxset.command(name="version")
async def command_fxset_version(self, context: PyLavContext) -> None:
"""Show the version of the Cog and PyLav"""
if isinstance(context, discord.Interaction):
context = await self.bot.get_context(context)
if context.interaction and not context.interaction.response.is_done():
await context.defer(ephemeral=True)
data = [
(EightBitANSI.paint_white(self.__class__.__name__), EightBitANSI.paint_blue(self.__version__)),
(EightBitANSI.paint_white("PyLav"), EightBitANSI.paint_blue(context.pylav.lib_version)),
]
await context.send(
embed=await context.pylav.construct_embed(
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Library / Cog"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Version"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
messageable=context,
),
ephemeral=True,
)
@commands.group(name="eq")
@commands.guild_only()
@commands.guildowner_or_permissions(manage_guild=True)
async def command_fxset_eq(self, ctx: PyLavContext) -> None:
"""Configure the Player behaviour when an equalizer preset is set"""
@command_fxset_eq.command(name="persist")
async def command_fxset_eq_persist(self, context: PyLavContext) -> None:
"""Persist the last used preset"""
if isinstance(context, discord.Interaction):
context = await self.bot.get_context(context)
if context.interaction and not context.interaction.response.is_done():
await context.defer(ephemeral=True)
async with self._config.guild(context.guild).all() as guild_config:
guild_config["persist_eq"] = state = not guild_config["persist_eq"]
if state:
if context.player:
effects = await context.player.config.fetch_effects()
effects["equalizer"] = {}
await context.player.config.update_effects(effects)
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The player will now apply the last used preset when it is created"),
),
ephemeral=True,
)
else:
if context.player:
effects = await context.player.config.fetch_effects()
effects["equalizer"] = context.player.equalizer.to_dict()
await context.player.config.update_effects(effects)
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("Last used preset will no longer be saved"),
),
ephemeral=True,
)
@slash_fx.command(
name="nightcore",
description=shorten_string(max_length=100, string=_("Apply a Nightcore preset to the player")),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_nightcore(self, interaction: DISCORD_INTERACTION_TYPE) -> None:
"""Apply a Nightcore filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if context.player.equalizer.name == "Nightcore":
await context.player.remove_nightcore(requester=context.author)
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("Nightcore effect has been disabled"),
),
ephemeral=True,
)
else:
try:
await context.player.apply_nightcore(requester=context.author)
except NodeHasNoFiltersException as exc:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=exc.message,
),
ephemeral=True,
)
else:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("Nightcore effect has been enabled"),
),
ephemeral=True,
)
@slash_fx.command(name="varporwave", description=_("Apply a Vaporwave preset to the player"))
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_varporwave(self, interaction: DISCORD_INTERACTION_TYPE) -> None:
"""Apply a Vaporwave filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if context.player.equalizer.name == "Vaporwave":
await context.player.remove_vaporwave(requester=context.author)
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("Vaporwave effect has been disabled"),
),
ephemeral=True,
)
else:
try:
await context.player.apply_vaporwave(requester=context.author)
except NodeHasNoFiltersException as exc:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=exc.message,
),
ephemeral=True,
)
else:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("Vaporwave effect has been enabled"),
),
ephemeral=True,
)
@slash_fx.command(name="vibrato", description=_("Apply a vibrato filter to the player"))
@app_commands.describe(
frequency=_("The vibrato frequency"),
depth=_("The vibrato depth value"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_vibrato(
self,
interaction: DISCORD_INTERACTION_TYPE,
frequency: Range[float, 0.01, 14.0] = None,
depth: Range[float, 0.01, 1.0] = None,
reset: bool = False,
) -> None:
"""Apply a vibrato filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("vibrato"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Vibrato functionality enabled"),
),
ephemeral=True,
)
return
context.player.vibrato.frequency = frequency or context.player.vibrato.frequency
context.player.vibrato.depth = depth or context.player.vibrato.depth
await context.player.set_vibrato(vibrato=context.player.vibrato, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Frequency")),
EightBitANSI.paint_blue(context.player.vibrato.frequency or default),
),
(EightBitANSI.paint_white(_("Depth")), EightBitANSI.paint_blue(context.player.vibrato.depth or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New vibrato effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="tremolo", description=_("Apply a tremolo filter to the player"))
@app_commands.describe(
frequency=_("The tremolo frequency"),
depth=_("The tremolo depth value"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_tremolo(
self,
interaction: DISCORD_INTERACTION_TYPE,
frequency: Range[float, 0.01, None] = None,
depth: Range[float, 0.01, 1.0] = None,
reset: bool = False,
) -> None:
"""Apply a tremolo filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("tremolo"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Tremolo functionality enabled"),
),
ephemeral=True,
)
return
context.player.tremolo.frequency = frequency or context.player.tremolo.frequency
context.player.tremolo.depth = depth or context.player.tremolo.depth
await context.player.set_tremolo(tremolo=context.player.tremolo, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Frequency")),
EightBitANSI.paint_blue(context.player.tremolo.frequency or default),
),
(EightBitANSI.paint_white(_("Depth")), EightBitANSI.paint_blue(context.player.tremolo.depth or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New tremolo effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="timescale", description=_("Apply a timescale filter to the player"))
@app_commands.describe(
speed=_("The timescale speed value"),
pitch=_("The timescale pitch value"),
rate=_("The timescale rate value"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_timescale(
self,
interaction: DISCORD_INTERACTION_TYPE,
speed: Range[float, 0.0, None] = None,
pitch: Range[float, 0.0, None] = None,
rate: Range[float, 0.0, None] = None,
reset: bool = False,
) -> None:
"""Apply a timescale filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("timescale"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Timescale functionality enabled"),
),
ephemeral=True,
)
return
context.player.timescale.speed = speed or context.player.timescale.speed
context.player.timescale.pitch = pitch or context.player.timescale.pitch
context.player.timescale.rate = rate or context.player.timescale.rate
await context.player.set_timescale(timescale=context.player.timescale, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(EightBitANSI.paint_white(_("Speed")), EightBitANSI.paint_blue(context.player.timescale.speed or default)),
(EightBitANSI.paint_white(_("Pitch")), EightBitANSI.paint_blue(context.player.timescale.pitch or default)),
(EightBitANSI.paint_white(_("Rate")), EightBitANSI.paint_blue(context.player.timescale.rate or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New timescale effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="rotation", description=_("Apply a rotation filter to the player"))
@app_commands.describe(
hertz=_("The rotation hertz frequency"), reset=_("Reset any existing effects currently applied to the player")
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_rotation(
self, interaction: DISCORD_INTERACTION_TYPE, hertz: Range[float, 0.0, None] = None, reset: bool = False
) -> None:
"""Apply a rotation filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("rotation"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Rotation functionality enabled"),
),
ephemeral=True,
)
return
context.player.rotation.hertz = hertz or context.player.rotation.hertz
await context.player.set_rotation(rotation=context.player.rotation, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Frequency hertz")),
EightBitANSI.paint_blue(context.player.rotation.hertz or default),
),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New rotation effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="lowpass", description=_("Apply a low pass filter to the player"))
@app_commands.describe(
smoothing=_("The low pass smoothing value"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_lowpass(
self, interaction: DISCORD_INTERACTION_TYPE, smoothing: Range[float, 0.0, None] = None, reset: bool = False
) -> None:
"""Apply a low pass filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("lowPass"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the LowPass functionality enabled"),
),
ephemeral=True,
)
return
context.player.low_pass.smoothing = smoothing or context.player.low_pass.smoothing
await context.player.set_low_pass(low_pass=context.player.low_pass, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Smoothing factor")),
EightBitANSI.paint_blue(context.player.low_pass.smoothing or default),
),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New low pass effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="karaoke", description=_("Apply a karaoke filter to the player"))
@app_commands.describe(
level=_("The level value"),
mono_level=_("The mono level value"),
filter_band=_("The filter band"),
filter_width=_("The filter width value"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_karaoke(
self,
interaction: DISCORD_INTERACTION_TYPE,
level: Range[float, 0.0, None] = None,
mono_level: Range[float, 0.0, None] = None,
filter_band: Range[float, 0.0, None] = None,
filter_width: Range[float, 0.0, None] = None,
reset: bool = False,
) -> None:
"""Apply a karaoke filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("karaoke"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Karaoke functionality enabled"),
),
ephemeral=True,
)
return
context.player.karaoke.level = level or context.player.karaoke.level
context.player.karaoke.mono_level = mono_level or context.player.karaoke.mono_level
context.player.karaoke.filter_band = filter_band or context.player.karaoke.filter_band
context.player.karaoke.filter_width = filter_width or context.player.karaoke.filter_width
await context.player.set_karaoke(karaoke=context.player.karaoke, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(EightBitANSI.paint_white(_("Level")), EightBitANSI.paint_blue(context.player.karaoke.level or default)),
(
EightBitANSI.paint_white(_("Mono Level")),
EightBitANSI.paint_blue(context.player.karaoke.mono_level or default),
),
(
EightBitANSI.paint_white(_("Filter Band")),
EightBitANSI.paint_blue(context.player.karaoke.filter_band or default),
),
(
EightBitANSI.paint_white(_("Filter Width")),
EightBitANSI.paint_blue(context.player.karaoke.filter_width or default),
),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New karaoke effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="channelmix", description=_("Apply a channel mix filter to the player"))
@app_commands.describe(
left_to_left=_("The channel mix left to left weight"),
left_to_right=_("The channel mix left to right weight"),
right_to_left=_("The channel mix right to left weight"),
right_to_right=_("The channel mix right to right weight"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_channelmix(
self,
interaction: DISCORD_INTERACTION_TYPE,
left_to_left: Range[float, 0.0, None] = None,
left_to_right: Range[float, 0.0, None] = None,
right_to_left: Range[float, 0.0, None] = None,
right_to_right: Range[float, 0.0, None] = None,
reset: bool = False,
) -> None:
"""Apply a channel mix filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("channelMix"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the ChannelMix functionality enabled"),
),
ephemeral=True,
)
return
context.player.channel_mix.left_to_left = left_to_left or context.player.channel_mix.left_to_left
context.player.channel_mix.left_to_right = left_to_right or context.player.channel_mix.left_to_right
context.player.channel_mix.right_to_left = right_to_left or context.player.channel_mix.right_to_left
context.player.channel_mix.right_to_right = right_to_right or context.player.channel_mix.right_to_right
await context.player.set_channel_mix(
channel_mix=context.player.channel_mix, requester=context.author, forced=reset
)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Left to Left")),
EightBitANSI.paint_blue(context.player.channel_mix.left_to_left or default),
),
(
EightBitANSI.paint_white(_("Left to Right")),
EightBitANSI.paint_blue(context.player.channel_mix.left_to_right or default),
),
(
EightBitANSI.paint_white(_("Right to Left")),
EightBitANSI.paint_blue(context.player.channel_mix.right_to_left or default),
),
(
EightBitANSI.paint_white(_("Right to Right")),
EightBitANSI.paint_blue(context.player.channel_mix.right_to_right or default),
),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New channel mix effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="distortion", description=_("Apply a distortion filter to the player"))
@app_commands.describe(
sin_offset=_("The distortion Sine offset"),
sin_scale=_("The distortion Sine scale"),
cos_offset=_("The distortion Cosine offset"),
cos_scale=_("The distortion Cosine scale"),
tan_offset=_("The distortion Tangent offset"),
tan_scale=_("The distortion Tangent scale"),
offset=_("The distortion offset"),
scale=_("The distortion scale"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_distortion(
self,
interaction: DISCORD_INTERACTION_TYPE,
sin_offset: Range[float, 0.0, None] = None,
sin_scale: Range[float, 0.0, None] = None,
cos_offset: Range[float, 0.0, None] = None,
cos_scale: Range[float, 0.0, None] = None,
tan_offset: Range[float, 0.0, None] = None,
tan_scale: Range[float, 0.0, None] = None,
offset: Range[float, 0.0, None] = None,
scale: Range[float, 0.0, None] = None,
reset: bool = False,
) -> None: # sourcery skip: low-code-quality
"""Apply a distortion filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("distortion"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Distortion functionality enabled"),
),
ephemeral=True,
)
return
context.player.distortion.sin_offset = sin_offset or context.player.distortion.sin_offset
context.player.distortion.sin_scale = sin_scale or context.player.distortion.sin_scale
context.player.distortion.cos_offset = cos_offset or context.player.distortion.cos_offset
context.player.distortion.cos_scale = cos_scale or context.player.distortion.cos_scale
context.player.distortion.tan_offset = tan_offset or context.player.distortion.tan_offset
context.player.distortion.tan_scale = tan_scale or context.player.distortion.tan_scale
context.player.distortion.offset = offset or context.player.distortion.offset
context.player.distortion.scale = scale or context.player.distortion.scale
await context.player.set_distortion(
distortion=context.player.distortion, requester=context.author, forced=reset
)
default = _("Not changed")
data = [
(
EightBitANSI.paint_white(_("Sine Offset")),
EightBitANSI.paint_blue(context.player.distortion.sin_offset or default),
),
(
EightBitANSI.paint_white(_("Sine Scale")),
EightBitANSI.paint_blue(context.player.distortion.sin_scale or default),
),
(
EightBitANSI.paint_white(_("Cosine Offset")),
EightBitANSI.paint_blue(context.player.distortion.cos_offset or default),
),
(
EightBitANSI.paint_white(_("Cosine Scale")),
EightBitANSI.paint_blue(context.player.distortion.cos_scale or default),
),
(
EightBitANSI.paint_white(_("Tangent Offset")),
EightBitANSI.paint_blue(context.player.distortion.tan_offset or default),
),
(
EightBitANSI.paint_white(_("Tangent Scale")),
EightBitANSI.paint_blue(context.player.distortion.tan_scale or default),
),
(
EightBitANSI.paint_white(_("Offset")),
EightBitANSI.paint_blue(context.player.distortion.offset or default),
),
(EightBitANSI.paint_white(_("Scale")), EightBitANSI.paint_blue(context.player.distortion.scale or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New distortion effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="echo", description=_("Apply a echo filter to the player"))
@app_commands.describe(
delay=_("The delay of the echo"),
decay=_("The decay of the echo"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_echo(
self,
interaction: DISCORD_INTERACTION_TYPE,
delay: Range[float, 0.0, None] = None,
decay: Range[float, 0.0, 1.0] = None,
reset: bool = False,
) -> None:
"""Apply a echo filter to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("echo"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Echo functionality enabled"),
),
ephemeral=True,
)
return
context.player.echo.delay = delay or context.player.echo.delay
context.player.echo.decay = decay or context.player.echo.decay
await context.player.set_echo(echo=context.player.echo, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(EightBitANSI.paint_white(_("Delay")), EightBitANSI.paint_blue(context.player.echo.delay or default)),
(EightBitANSI.paint_white(_("Decay")), EightBitANSI.paint_blue(context.player.echo.decay or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New echo effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="reverb", description=_("Apply a reverb filter to the player"))
@app_commands.describe(
delays=_("The delays of the reverb"),
gains=_("The gains of the reverb"),
reset=_("Reset any existing effects currently applied to the player"),
)
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_reverb(
self,
interaction: DISCORD_INTERACTION_TYPE,
delays: str = None,
gains: str = None,
reset: bool = False,
) -> None:
"""Apply a Reberb filter to the player."""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
if not context.player.node.has_filter("reverb"):
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The current node does not have the Reverb functionality enabled"),
),
ephemeral=True,
)
return
try:
delays: list[float] | None = map(float, delays.split(",")) if delays else None
except Exception:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The delays provided are invalid, it should be a comma separated list of floats"),
),
ephemeral=True,
)
return
try:
gains: list[float] | None = map(float, gains.split(",")) if gains else None
except Exception:
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
description=_("The gains provided are invalid, it should be a comma separated list of floats"),
),
ephemeral=True,
)
return
context.player.reverb.delays = delays or context.player.reverb.delays
context.player.reverb.gains = gains or context.player.reverb.gains
await context.player.set_reverb(reverb=context.player.reverb, requester=context.author, forced=reset)
default = _("Not changed")
data = [
(EightBitANSI.paint_white(_("Delays")), EightBitANSI.paint_blue(context.player.reverb.delays or default)),
(EightBitANSI.paint_white(_("Gains")), EightBitANSI.paint_blue(context.player.reverb.gains or default)),
(
EightBitANSI.paint_white(_("Reset previous filters")),
EightBitANSI.paint_red(_("Yes")) if reset else EightBitANSI.paint_green(_("No")),
),
]
await context.send(
embed=await self.pylav.construct_embed(
messageable=context,
title=_("New reverb effect applied to the player"),
description=box(
tabulate(
data,
headers=(
EightBitANSI.paint_yellow(_("Setting"), bold=True, underline=True),
EightBitANSI.paint_yellow(_("Value"), bold=True, underline=True),
),
tablefmt="fancy_grid",
),
lang="ansi",
),
),
ephemeral=True,
)
@slash_fx.command(name="show", description=_("Show the current filters applied to the player"))
@app_commands.guild_only()
@requires_player(slash=True)
async def slash_fx_show(self, interaction: DISCORD_INTERACTION_TYPE) -> None:
"""Show the current filters applied to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)
t_effect = EightBitANSI.paint_yellow(_("Effect"), bold=True, underline=True)
t_values = EightBitANSI.paint_yellow(_("Values"), bold=True, underline=True)
default = _("Not changed")
data = []
for effect in (
context.player.karaoke,
context.player.timescale,
context.player.tremolo,
context.player.vibrato,
context.player.rotation,
context.player.distortion,
context.player.low_pass,
context.player.channel_mix,
context.player.echo,
context.player.reverb,
):
data_ = {t_effect: effect.__class__.__name__}
if effect:
values = effect.to_dict()
if not isinstance(effect, Equalizer):
data_[t_values] = "\n".join(
f"{EightBitANSI.paint_white(k.title())}: {EightBitANSI.paint_green(v or default)}"
for k, v in values.items()
)
else:
eq_value = typing.cast(list[JSON_DICT_TYPE], values["bands"])
data_[t_values] = "\n".join(
[
"{band}: {gain}".format(
band=EightBitANSI.paint_white(EQ_BAND_MAPPING[band["band"]]),
gain=EightBitANSI.paint_green(band["gain"]),
)
for band in eq_value
if band["gain"]
]
)
else:
data_[t_values] = EightBitANSI.paint_blue(_("N/A"))
data.append(data_)
await context.send(
embed=await self.pylav.construct_embed(
title=_("Current filters applied to the player"),
description="__**{translation}:**__\n{data}".format(
data=(
box(tabulate(data, headers="keys", tablefmt="fancy_grid", maxcolwidths=[10, 18]), lang="ansi") # type: ignore
if data
else _("None")
),
translation=discord.utils.escape_markdown(_("Currently Applied")),
),
messageable=context,
),
ephemeral=True,
)
@slash_fx.command(name="reset", description=_("Reset any existing filters currently applied to the player"))
@app_commands.guild_only()
@requires_player(slash=True)
@invoker_is_dj(slash=True)
async def slash_fx_reset(self, interaction: DISCORD_INTERACTION_TYPE) -> None:
"""Reset any existing filters currently applied to the player"""
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
context = await self.bot.get_context(interaction)