feat: improve Discord player controls and docs
This commit is contained in:
2 files changed
+71
-1
No files matched your search
@@ -28,6 +28,36 @@ uploady w katalogach `uploads/<guild_id>/`.
|
|||||||
Ostatnia kolejka jest zapisywana w `config/queues/<guild_id>.json` przy zatrzymaniu
|
Ostatnia kolejka jest zapisywana w `config/queues/<guild_id>.json` przy zatrzymaniu
|
||||||
lub rozłączeniu i może zostać przywrócona z widoku kolejki.
|
lub rozłączeniu i może zostać przywrócona z widoku kolejki.
|
||||||
|
|
||||||
|
## Komendy Discorda
|
||||||
|
|
||||||
|
Wszystkie komendy działają w kontekście bieżącego serwera. Discord pokazuje wybór
|
||||||
|
utworów przez autocomplete, a kanały przez natywne selektory — nie trzeba wpisywać
|
||||||
|
indeksów ręcznie.
|
||||||
|
|
||||||
|
| Komenda | Działanie |
|
||||||
|
| --- | --- |
|
||||||
|
| `/player` | Publiczny panel odtwarzacza z przyciskami sterowania |
|
||||||
|
| `/play query` | Dodaje utwór, link lub zapytanie wyszukiwania |
|
||||||
|
| `/playfile filename` | Odtwarza plik z biblioteki serwera |
|
||||||
|
| `/replay track_id` | Ponownie odtwarza utwór z historii |
|
||||||
|
| `/queue` | Pokazuje kolejkę w embedzie |
|
||||||
|
| `/history` | Pokazuje historię odtwarzania |
|
||||||
|
| `/restorequeue` | Przywraca ostatnią zapisaną kolejkę |
|
||||||
|
| `/jump track_id` | Rozpoczyna wybrany utwór z kolejki |
|
||||||
|
| `/remove track_id` | Usuwa wybrany utwór z kolejki |
|
||||||
|
| `/trackplays track_id count` | Ustawia liczbę odtworzeń utworu |
|
||||||
|
| `/pause`, `/resume` | Wstrzymuje lub wznawia odtwarzanie |
|
||||||
|
| `/skip` | Pomija bieżący utwór |
|
||||||
|
| `/stop` | Zatrzymuje odtwarzanie i czyści kolejkę |
|
||||||
|
| `/volume volume` | Ustawia głośność w zakresie 1–100 |
|
||||||
|
| `/nowplaying` | Pokazuje bieżący utwór |
|
||||||
|
| `/loop` | Przełącza tryb zapętlania |
|
||||||
|
| `/loopplaylist` | Włącza lub wyłącza zapętlanie kolejki |
|
||||||
|
| `/defaultplays count` | Ustawia domyślną liczbę odtworzeń dla nowych utworów |
|
||||||
|
| `/connect channel` | Łączy bota z wybranym kanałem głosowym |
|
||||||
|
| `/notificationchannel channel` | Ustawia kanał powiadomień |
|
||||||
|
| `/leave` | Rozłącza bota z kanału głosowego |
|
||||||
|
|
||||||
## Testy
|
## Testy
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@@ -84,7 +85,20 @@ class PlayerView(discord.ui.View):
|
|||||||
"Nic nie jest obecnie odtwarzane.", ephemeral=True
|
"Nic nie jest obecnie odtwarzane.", ephemeral=True
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
await self.action(interaction, lambda: self.player.skip(self.guild_id))
|
previous = self.player.state(self.guild_id).current
|
||||||
|
self.player.skip(self.guild_id)
|
||||||
|
for _ in range(20):
|
||||||
|
await asyncio.sleep(0.05)
|
||||||
|
if self.player.state(self.guild_id).current is not previous:
|
||||||
|
break
|
||||||
|
await self.player.trigger_state_change()
|
||||||
|
await interaction.response.edit_message(
|
||||||
|
embed=player_embed(self.player, interaction.guild), view=self
|
||||||
|
)
|
||||||
|
|
||||||
|
@discord.ui.button(label="Głośność", emoji="🔊", style=discord.ButtonStyle.secondary, row=1)
|
||||||
|
async def volume(self, interaction: discord.Interaction, _: discord.ui.Button) -> None:
|
||||||
|
await interaction.response.send_modal(VolumeModal(self))
|
||||||
|
|
||||||
@discord.ui.button(label="Stop", emoji="⏹️", style=discord.ButtonStyle.danger)
|
@discord.ui.button(label="Stop", emoji="⏹️", style=discord.ButtonStyle.danger)
|
||||||
async def stop(self, interaction: discord.Interaction, _: discord.ui.Button) -> None:
|
async def stop(self, interaction: discord.Interaction, _: discord.ui.Button) -> None:
|
||||||
@@ -144,6 +158,32 @@ class PlayerView(discord.ui.View):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class VolumeModal(discord.ui.Modal, title="Ustaw głośność"):
|
||||||
|
volume = discord.ui.TextInput(
|
||||||
|
label="Głośność (1-100)", placeholder="np. 75", min_length=1, max_length=3
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, view: PlayerView):
|
||||||
|
super().__init__()
|
||||||
|
self.player_view = view
|
||||||
|
|
||||||
|
async def on_submit(self, interaction: discord.Interaction) -> None:
|
||||||
|
try:
|
||||||
|
value = int(self.volume.value)
|
||||||
|
except ValueError:
|
||||||
|
await interaction.response.send_message("Podaj liczbę od 1 do 100.", ephemeral=True)
|
||||||
|
return
|
||||||
|
if not 1 <= value <= 100:
|
||||||
|
await interaction.response.send_message("Podaj liczbę od 1 do 100.", ephemeral=True)
|
||||||
|
return
|
||||||
|
self.player_view.player.set_volume(self.player_view.guild_id, value / 100)
|
||||||
|
await self.player_view.player.trigger_state_change()
|
||||||
|
await interaction.response.edit_message(
|
||||||
|
embed=player_embed(self.player_view.player, interaction.guild),
|
||||||
|
view=self.player_view,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PlayerCog(MusicCogBase, name="Player"):
|
class PlayerCog(MusicCogBase, name="Player"):
|
||||||
"""Publiczny panel sterowania odtwarzaczem na Discordzie."""
|
"""Publiczny panel sterowania odtwarzaczem na Discordzie."""
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user