Added 100% coverage of all filters and exception field for TrackExceptionEvent for Lavalink 3.4 release

This commit is contained in:
cloudwithax 2021-10-30 12:02:45 -04:00
parent 10506a1fbe
commit 36bddc1de6
5 changed files with 164 additions and 13 deletions

View File

@ -11,7 +11,7 @@ if discord.__version__ != "2.0.0a":
"using 'pip install git+https://github.com/Rapptz/discord.py@master'"
)
__version__ = "1.1.0"
__version__ = "1.1.1"
__title__ = "pomice"
__author__ = "cloudwithax"

View File

@ -85,13 +85,18 @@ class TrackExceptionEvent(PomiceEvent):
def __init__(self, data: dict):
self.player = NodePool.get_node().get_player(int(data["guildId"]))
self.track = self.player._ending_track
self.error: str = data["error"]
if data.get('error'):
# User is running Lavalink <= 3.3
self.exception: str = data["error"]
else:
# User is running Lavalink >=3.4
self.exception: str = data["exception"]
# on_pomice_track_exception(player, track, error)
self.handler_args = self.player, self.track, self.error
self.handler_args = self.player, self.track, self.exception
def __repr__(self) -> str:
return f"<Pomice.TrackExceptionEvent player={self.player!r} error={self.error!r}>"
return f"<Pomice.TrackExceptionEvent player={self.player!r} exception={self.exception!r}>"
class WebSocketClosedPayload:

View File

@ -44,7 +44,13 @@ class Timescale(Filter):
This is not the library's fault.
"""
def __init__(self, *, speed: float = 1.0, pitch: float = 1.0, rate: float = 1.0):
def __init__(
self,
*,
speed: float = 1.0,
pitch: float = 1.0,
rate: float = 1.0
):
super().__init__()
if speed < 0:
@ -74,10 +80,10 @@ class Karaoke(Filter):
def __init__(
self,
*,
level: float,
mono_level: float,
filter_band: float,
filter_width: float
level: float = 1.0,
mono_level: float = 1.0,
filter_band: float = 220.0,
filter_width: float = 100.0
):
super().__init__()
@ -103,7 +109,12 @@ class Tremolo(Filter):
causing it to sound like the music is changing in volume rapidly.
"""
def __init__(self, *, frequency: float, depth: float):
def __init__(
self,
*,
frequency: float = 2.0,
depth: float = 0.5
):
super().__init__()
if frequency < 0:
@ -128,7 +139,12 @@ class Vibrato(Filter):
but changes in pitch rather than volume.
"""
def __init__(self, *, frequency: float, depth: float):
def __init__(
self,
*,
frequency: float = 2.0,
depth: float = 0.5
):
super().__init__()
if frequency < 0 or frequency > 14:
@ -146,3 +162,127 @@ class Vibrato(Filter):
def __repr__(self):
return f"<Pomice.VibratoFilter frequency={self.frequency} depth={self.depth}>"
class Rotation(Filter):
"""Filter which produces a stereo-like panning effect, which sounds like
the audio is being rotated around the listener's head
"""
def __init__(self, *, rotation_hertz: float = 5):
super().__init__()
self.rotation_hertz = rotation_hertz
self.payload = {"rotation": {"rotationHz": self.rotation_hertz}}
def __repr__(self) -> str:
return f"<Pomice.RotationFilter rotation_hertz={self.rotation_hertz}>"
class ChannelMix(Filter):
"""Filter which manually adjusts the panning of the audio, which can make
for some cool effects when done correctly.
"""
def __init__(
self,
*,
left_to_left: float = 1,
right_to_right: float = 1,
left_to_right: float = 0,
right_to_left: float = 0
):
super().__init__()
if 0 > left_to_left > 1:
raise ValueError(
"'left_to_left' value must be more than or equal to 0 or less than or equal to 1.")
if 0 > right_to_right > 1:
raise ValueError(
"'right_to_right' value must be more than or equal to 0 or less than or equal to 1.")
if 0 > left_to_right > 1:
raise ValueError(
"'left_to_right' value must be more than or equal to 0 or less than or equal to 1.")
if 0 > right_to_left > 1:
raise ValueError(
"'right_to_left' value must be more than or equal to 0 or less than or equal to 1.")
self.left_to_left = left_to_left
self.left_to_right = left_to_right
self.right_to_left = right_to_left
self.right_to_right = right_to_right
self.payload = {"channelMix": {"leftToLeft": self.left_to_left,
"leftToRight": self.left_to_right,
"rightToLeft": self.right_to_left,
"rightToRight": self.right_to_right}
}
def __repr__(self) -> str:
return (
f"<Pomice.ChannelMix left_to_left={self.left_to_left} left_to_right={self.left_to_right} "
f"right_to_left={self.right_to_left} right_to_right={self.right_to_right}>"
)
class Distortion(Filter):
"""Filter which generates a distortion effect. Useful for certain filter implementations where
distortion is needed.
"""
def __init__(
self,
*,
sin_offset: float = 0,
sin_scale: float = 1,
cos_offset: float = 0,
cos_scale: float = 1,
tan_offset: float = 0,
tan_scale: float = 1,
offset: float = 0,
scale: float = 1
):
super().__init__()
self.sin_offset = sin_offset
self.sin_scale = sin_scale
self.cos_offset = cos_offset
self.cos_scale = cos_scale
self.tan_offset = tan_offset
self.tan_scale = tan_scale
self.offset = offset
self.scale = scale
self.payload = {"distortion": {
"sinOffset": self.sin_offset,
"sinScale": self.sin_scale,
"cosOffset": self.cos_offset,
"cosScale": self.cos_scale,
"tanOffset": self.tan_offset,
"tanScale": self.tan_scale,
"offset": self.offset,
"scale": self.scale
}}
def __repr__(self) -> str:
return (
f"<Pomice.Distortion sin_offset={self.sin_offset} sin_scale={self.sin_scale}> "
f"cos_offset={self.cos_offset} cos_scale={self.cos_scale} tan_offset={self.tan_offset} "
f"tan_scale={self.tan_scale} offset={self.offset} scale={self.scale}"
)
class LowPass(Filter):
"""Filter which supresses higher frequencies and allows lower frequencies to pass.
You can also do this with the Equalizer filter, but this is an easier way to do it.
"""
def __init__(self, *, smoothing: float = 20):
super().__init__()
self.smoothing = smoothing
self.payload = {"lowPass": {"smoothing": self.smoothing}}
def __repr__(self) -> str:
return f"<Pomice.LowPass smoothing={self.smoothing}>"

View File

@ -4,3 +4,9 @@ requires = [
"wheel"
]
build-backend = "setuptools.build_meta"
[tool.autopep8]
max_line_length = 100
in-place = true
recursive = true
aggressive = 3

View File

@ -6,7 +6,7 @@ with open("README.md") as f:
setuptools.setup(
name="pomice",
author="cloudwithax",
version="1.1.0",
version="1.1.1",
url="https://github.com/cloudwithax/pomice",
packages=setuptools.find_packages(),
license="GPL",