refactor: remove legacy volume_boost references in favor of generalized player effects API
This commit is contained in:
12 files changed
+27
-112
No files matched your search
@@ -7,7 +7,6 @@ from zyrarbot.audio.effects.distortion import DistortionEffect
|
||||
from zyrarbot.audio.effects.fourth_density import FourthDensityEffect
|
||||
from zyrarbot.audio.effects.muffled import MuffledEffect
|
||||
from zyrarbot.audio.effects.tremolo import TremoloEffect
|
||||
from zyrarbot.music.guild_music_state import VOLUME_BOOST_MULTIPLIER
|
||||
|
||||
|
||||
def create_default_effects() -> list[AudioEffect]:
|
||||
@@ -15,7 +14,7 @@ def create_default_effects() -> list[AudioEffect]:
|
||||
return [
|
||||
MuffledEffect(),
|
||||
FourthDensityEffect(),
|
||||
DistortionEffect(multiplier=VOLUME_BOOST_MULTIPLIER),
|
||||
DistortionEffect(),
|
||||
TremoloEffect(),
|
||||
]
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@ from zyrarbot.music.loop_mode import LoopMode
|
||||
if TYPE_CHECKING:
|
||||
from zyrarbot.audio.ytdl_source import YTDLSource
|
||||
|
||||
VOLUME_BOOST_MULTIPLIER: float = 10.0
|
||||
|
||||
|
||||
@dataclass
|
||||
class GuildMusicState:
|
||||
"""Stan odtwarzania jednego serwera Discord.
|
||||
@@ -31,28 +28,12 @@ class GuildMusicState:
|
||||
jump_pending: bool = False
|
||||
notification_channel: discord.abc.Messageable | None = None
|
||||
|
||||
@property
|
||||
def volume_boost(self) -> bool:
|
||||
return "distortion" in self.active_effects
|
||||
|
||||
@volume_boost.setter
|
||||
def volume_boost(self, value: bool) -> None:
|
||||
if value:
|
||||
self.active_effects.add("distortion")
|
||||
else:
|
||||
self.active_effects.discard("distortion")
|
||||
|
||||
@property
|
||||
def effective_volume(self) -> float:
|
||||
"""Zwraca głośność z uwzględnieniem trybu podbicia (mnożnik VOLUME_BOOST_MULTIPLIER)."""
|
||||
return self.volume * VOLUME_BOOST_MULTIPLIER if self.volume_boost else self.volume
|
||||
|
||||
|
||||
def reset(self) -> None:
|
||||
self.queue.clear()
|
||||
self.current = None
|
||||
self.index = -1
|
||||
|
||||
|
||||
def find(self, track_id: str) -> YTDLSource | None:
|
||||
return next((track for track in self.queue if track.id == track_id), None)
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ class MusicPlayer:
|
||||
state = self.state(guild_id)
|
||||
voice_client = self.voice_client(guild_id)
|
||||
if voice_client and voice_client.source:
|
||||
voice_client.source.volume = state.effective_volume
|
||||
voice_client.source.volume = state.volume
|
||||
if hasattr(voice_client.source, "set_active_effects"):
|
||||
voice_client.source.set_active_effects(state.active_effects)
|
||||
|
||||
@@ -236,11 +236,6 @@ class MusicPlayer:
|
||||
def is_effect_active(self, guild_id: int, effect_id: str) -> bool:
|
||||
return effect_id in self.state(guild_id).active_effects
|
||||
|
||||
def set_volume_boost(self, guild_id: int, boost: bool) -> bool:
|
||||
return self.set_effect(guild_id, "distortion", boost)
|
||||
|
||||
def toggle_volume_boost(self, guild_id: int) -> bool:
|
||||
return self.toggle_effect(guild_id, "distortion")
|
||||
|
||||
|
||||
def set_loop_mode(self, guild_id: int, mode: LoopMode) -> None:
|
||||
@@ -350,7 +345,7 @@ class MusicPlayer:
|
||||
|
||||
track = await self._tracks.recreate(current, loop=self._bot.loop, start_at=position)
|
||||
track.played = True
|
||||
track.volume = state.effective_volume
|
||||
track.volume = state.volume
|
||||
if hasattr(track, "set_active_effects"):
|
||||
track.set_active_effects(state.active_effects)
|
||||
track.plays_left = self.plays_left(current, guild_id)
|
||||
@@ -458,7 +453,7 @@ class MusicPlayer:
|
||||
|
||||
track.played = True
|
||||
track.plays_left = self.plays_left(track, guild_id)
|
||||
track.volume = state.effective_volume
|
||||
track.volume = state.volume
|
||||
if hasattr(track, "set_active_effects"):
|
||||
track.set_active_effects(state.active_effects)
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class VolumeBoostRequest(BaseModel):
|
||||
"""Włączenie, wyłączenie lub przełączenie trybu 500% głośności."""
|
||||
|
||||
enabled: bool | None = None
|
||||
@@ -22,7 +22,6 @@ from zyrarbot.ui.api.requests.loop_request import LoopRequest
|
||||
from zyrarbot.ui.api.requests.play_file_request import PlayFileRequest
|
||||
from zyrarbot.ui.api.requests.play_request import PlayRequest
|
||||
from zyrarbot.ui.api.requests.seek_request import SeekRequest
|
||||
from zyrarbot.ui.api.requests.volume_boost_request import VolumeBoostRequest
|
||||
from zyrarbot.ui.api.requests.volume_request import VolumeRequest
|
||||
from zyrarbot.ui.api.status_broadcaster import StatusBroadcaster
|
||||
|
||||
@@ -175,21 +174,6 @@ async def set_volume(
|
||||
return {"status": "success", "volume": request.volume}
|
||||
|
||||
|
||||
@router.post("/volume_boost")
|
||||
async def set_volume_boost(
|
||||
request: VolumeBoostRequest | None = None,
|
||||
guild: discord.Guild = Depends(get_active_guild),
|
||||
player: MusicPlayer = Depends(get_player),
|
||||
broadcaster: StatusBroadcaster = Depends(get_broadcaster),
|
||||
) -> dict[str, Any]:
|
||||
if request is not None and request.enabled is not None:
|
||||
boost = player.set_volume_boost(guild.id, request.enabled)
|
||||
else:
|
||||
boost = player.toggle_volume_boost(guild.id)
|
||||
await broadcaster.broadcast()
|
||||
return {"status": "success", "volume_boost": boost}
|
||||
|
||||
|
||||
@router.post("/effects/toggle")
|
||||
async def toggle_effect(
|
||||
request: EffectToggleRequest,
|
||||
|
||||
@@ -6,7 +6,6 @@ import discord
|
||||
|
||||
from zyrarbot.audio.effects import get_available_effects_metadata
|
||||
from zyrarbot.audio.ytdl_source import YTDLSource
|
||||
from zyrarbot.music.guild_music_state import VOLUME_BOOST_MULTIPLIER
|
||||
from zyrarbot.music.music_player import MusicPlayer
|
||||
from zyrarbot.music.notification_channel_resolver import NotificationChannelResolver
|
||||
from zyrarbot.ui.bot.guild_resolver import GuildResolver
|
||||
@@ -51,8 +50,6 @@ class StatusService:
|
||||
"loop_single": False,
|
||||
"loop_playlist": False,
|
||||
"volume": 100,
|
||||
"volume_boost": False,
|
||||
"volume_boost_multiplier": VOLUME_BOOST_MULTIPLIER,
|
||||
"effects": [{**meta, "active": False} for meta in get_available_effects_metadata()],
|
||||
"active_effects": [],
|
||||
"current": None,
|
||||
@@ -76,8 +73,6 @@ class StatusService:
|
||||
"loop_single": state.loop_mode.loops_track,
|
||||
"loop_playlist": state.loop_mode.loops_queue,
|
||||
"volume": int(state.volume * 100),
|
||||
"volume_boost": state.volume_boost,
|
||||
"volume_boost_multiplier": VOLUME_BOOST_MULTIPLIER,
|
||||
"effects": [
|
||||
{**meta, "active": meta["id"] in state.active_effects}
|
||||
for meta in get_available_effects_metadata()
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
import discord
|
||||
from discord import app_commands
|
||||
|
||||
from zyrarbot.music.guild_music_state import VOLUME_BOOST_MULTIPLIER
|
||||
from zyrarbot.music.loop_mode import LoopMode
|
||||
from zyrarbot.ui.bot.cogs.common import MusicCogBase
|
||||
from zyrarbot.ui.bot.discord_theme import message_embed
|
||||
@@ -112,19 +111,6 @@ class ControlCog(MusicCogBase, name="Control"):
|
||||
embed=message_embed("Głośność", f"Ustawiono głośność na {volume}%.")
|
||||
)
|
||||
|
||||
@app_commands.command(name="volumeboost", description="Przełącz tryb podbicia głośności")
|
||||
async def volume_boost(self, interaction: discord.Interaction) -> None:
|
||||
boost = self.player.toggle_volume_boost(interaction.guild.id)
|
||||
await self.player.trigger_state_change()
|
||||
boost_percent = int(VOLUME_BOOST_MULTIPLIER * 100)
|
||||
status_text = f"włączony ({boost_percent}%)" if boost else "wyłączony (100%)"
|
||||
await interaction.response.send_message(
|
||||
embed=message_embed(
|
||||
"Podbicie głośności",
|
||||
f"⚡ Tryb podbicia głośności ({boost_percent}%) jest teraz **{status_text}**.",
|
||||
)
|
||||
)
|
||||
|
||||
@app_commands.command(name="efekt", description="Włącz lub wyłącz efekt dźwiękowy odtwarzacza")
|
||||
@app_commands.describe(nazwa="Wybierz efekt audio do przełączenia")
|
||||
@app_commands.choices(
|
||||
|
||||
Reference in new issue
Block a user