refactor: remove legacy volume_boost references in favor of generalized player effects API

This commit is contained in:
mmacierzanka committed 2026-09-11 01:57:26 +02:00
1 parent a12b726648
commit 39403b8238
12 files changed
+27 -112

No files matched your search

-1
View File
@@ -20,7 +20,6 @@ EXPECTED_ENDPOINTS = {
("post", "/api/skip"),
("post", "/api/stop"),
("post", "/api/volume"),
("post", "/api/volume_boost"),
("post", "/api/effects/toggle"),
("post", "/api/loop"),
("post", "/api/loop_playlist"),
+17 -27
View File
@@ -7,7 +7,6 @@ import tempfile
import unittest
from tests.fakes import FakeTrack, build_player
from zyrarbot.music.guild_music_state import VOLUME_BOOST_MULTIPLIER
from zyrarbot.music.loop_mode import LoopMode
from zyrarbot.storage.queue_repository import QueueRepository
@@ -236,36 +235,27 @@ class MusicPlayerQueueTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(track.volume, 0.25)
async def test_volume_boost_multiplies_effective_volume_by_multiplier(self):
async def test_effects_management_in_player(self):
player, _ = build_player()
player.set_volume(GUILD, 0.2)
player.set_volume_boost(GUILD, True)
self.assertFalse(player.is_effect_active(GUILD, "distortion"))
self.assertEqual(player.state(GUILD).volume, 0.2)
self.assertAlmostEqual(
player.state(GUILD).effective_volume, 0.2 * VOLUME_BOOST_MULTIPLIER
)
track = FakeTrack("boosted")
await player.enqueue(GUILD, track)
self.assertAlmostEqual(track.volume, 0.2 * VOLUME_BOOST_MULTIPLIER)
player.set_volume(GUILD, 1.0)
self.assertAlmostEqual(
player.state(GUILD).effective_volume, 1.0 * VOLUME_BOOST_MULTIPLIER
)
async def test_toggle_volume_boost(self):
player, _ = build_player()
self.assertFalse(player.state(GUILD).volume_boost)
res = player.toggle_volume_boost(GUILD)
# Enable effect
res = player.set_effect(GUILD, "distortion", True)
self.assertTrue(res)
self.assertTrue(player.state(GUILD).volume_boost)
self.assertTrue(player.is_effect_active(GUILD, "distortion"))
self.assertIn("distortion", player.state(GUILD).active_effects)
# Toggle effect off
toggled = player.toggle_effect(GUILD, "distortion")
self.assertFalse(toggled)
self.assertFalse(player.is_effect_active(GUILD, "distortion"))
self.assertNotIn("distortion", player.state(GUILD).active_effects)
# Multiple simultaneous effects
player.set_effect(GUILD, "distortion", True)
player.set_effect(GUILD, "fourth_density", True)
self.assertEqual(player.state(GUILD).active_effects, {"distortion", "fourth_density"})
res2 = player.toggle_volume_boost(GUILD)
self.assertFalse(res2)
self.assertFalse(player.state(GUILD).volume_boost)
async def test_default_plays_are_applied_per_guild(self):
player, _ = build_player()
+5 -8
View File
@@ -40,11 +40,7 @@ class TestYTDLSource(unittest.TestCase):
self.assertEqual(empty, b"")
self.assertAlmostEqual(ytdl.elapsed, FRAME_LENGTH_SECONDS)
def test_read_with_volume_boost_over_2_does_not_clamp_to_2(self):
# Sample value 5000:
# At volume 2.0 (discord limit): 5000 * 2 = 10000
# At volume 5.0: 5000 * 5 = 25000
# At volume 10.0: 5000 * 10 = 50000 -> clipped to 32767
def test_read_with_high_volume_does_not_clamp_to_2(self):
pcm = struct.pack("<hh", 5000, -5000)
source = DummyPCM(pcm)
ytdl = YTDLSource(source, data={"title": "distortion test"}, volume=5.0)
@@ -54,11 +50,11 @@ class TestYTDLSource(unittest.TestCase):
self.assertEqual(left, 25000)
self.assertEqual(right, -25000)
def test_read_distortion_clips_at_pcm_limits(self):
# Overdriving large amplitude samples causes clipping / przester at [-32768, 32767]
def test_read_distortion_effect_clips_at_pcm_limits(self):
pcm = struct.pack("<hh", 10000, -10000)
source = DummyPCM(pcm)
ytdl = YTDLSource(source, data={"title": "przester"}, volume=10.0)
ytdl = YTDLSource(source, data={"title": "przester"}, volume=1.0)
ytdl.set_active_effects({"distortion"})
data = ytdl.read()
left, right = struct.unpack("<hh", data)
@@ -66,5 +62,6 @@ class TestYTDLSource(unittest.TestCase):
self.assertEqual(right, -32768)
if __name__ == "__main__":
unittest.main()