Files
zyrarbot/zyrarbot/ui/bot/cogs/control_cog.py
T
mmacierzanka d3a5058fde
Backend / Lint i formatowanie (pull_request) Successful in 3s
Backend / Testy i kontrakt API (pull_request) Failing after 2m19s
Backend / Testowy build obrazu (pull_request) Skipped
Formatting, README and other friends
2026-08-21 13:41:38 +02:00

85 lines
3.9 KiB
Python

from __future__ import annotations
import discord
from discord import app_commands
from zyrarbot.music.loop_mode import LoopMode
from zyrarbot.ui.bot.cogs.common import MusicCogBase
class ControlCog(MusicCogBase, name="Control"):
"""Komendy bezpośredniego sterowania odtwarzaniem."""
@app_commands.command(name="skip", description="Pomiń aktualny utwór")
async def skip(self, interaction: discord.Interaction) -> None:
guild_id = interaction.guild.id
state = self.player.state(guild_id)
if state.loop_mode.loops_track:
state.loop_mode = LoopMode.OFF
if not self.player.is_active(guild_id):
await interaction.response.send_message("Nic nie jest odtwarzane.", ephemeral=True)
return
interaction.guild.voice_client.stop()
await self.player.trigger_state_change()
await interaction.response.send_message("Pominięto aktualny utwór.")
@app_commands.command(name="pause", description="Wstrzymaj odtwarzanie")
async def pause(self, interaction: discord.Interaction) -> None:
voice_client = interaction.guild.voice_client
if not voice_client or not voice_client.is_playing():
await interaction.response.send_message("Nic nie jest odtwarzane.", ephemeral=True)
return
voice_client.pause()
await self.player.trigger_state_change()
await interaction.response.send_message("Odtwarzanie wstrzymane.")
@app_commands.command(name="resume", description="Wznów odtwarzanie")
async def resume(self, interaction: discord.Interaction) -> None:
voice_client = interaction.guild.voice_client
if not voice_client or not voice_client.is_paused():
await interaction.response.send_message(
"Odtwarzanie nie jest wstrzymane.", ephemeral=True
)
return
voice_client.resume()
await self.player.trigger_state_change()
await interaction.response.send_message("Odtwarzanie wznowione.")
@app_commands.command(name="stop", description="Zatrzymaj odtwarzanie i wyczyść kolejkę")
async def stop(self, interaction: discord.Interaction) -> None:
guild_id = interaction.guild.id
voice_client = interaction.guild.voice_client
if voice_client and voice_client.is_playing():
voice_client.stop()
self.player.clear(guild_id)
await self.player.trigger_state_change()
await interaction.response.send_message("Zatrzymano odtwarzanie i wyczyszczono kolejkę.")
@app_commands.command(name="volume", description="Zmień głośność odtwarzacza")
@app_commands.describe(volume="Poziom głośności (1-100)")
async def volume(self, interaction: discord.Interaction, volume: int) -> None:
if interaction.guild.voice_client is None:
await interaction.response.send_message(
"Nie połączono z kanałem głosowym.", ephemeral=True
)
return
if not 0 < volume <= 100:
await interaction.response.send_message(
"Wprowadź wartość z przedziału od 1 do 100.", ephemeral=True
)
return
self.player.set_volume(interaction.guild.id, volume / 100)
await self.player.trigger_state_change()
await interaction.response.send_message(f"Zmieniono głośność na {volume}%")
@app_commands.command(name="nowplaying", description="Pokaż aktualnie odtwarzany utwór")
async def now_playing(self, interaction: discord.Interaction) -> None:
current = self.player.state(interaction.guild.id).current
if not current:
await interaction.response.send_message(
"Nic nie jest obecnie odtwarzane.", ephemeral=True
)
return
title = discord.utils.escape_markdown(current.title or "")
await interaction.response.send_message(f"Teraz odtwarzane: {title}")