mirror of
https://codeberg.org/godmaire/sergei.git
synced 2024-09-19 15:58:26 +00:00
feat: show current queue
When given a `/queue show` command, Sergei will print out a list of songs in the current queue. As this only outputs the URLs, we rely on Discord to add the embeds and therefore title of the tracks.
This commit is contained in:
parent
79cd041435
commit
684292eb3b
2 changed files with 38 additions and 1 deletions
|
@ -11,7 +11,8 @@ defmodule Sergei.Commands.Queue do
|
|||
|
||||
@queue_commands [
|
||||
opt.(1, "add", "Add a song to the queue", options: @queue_add_opts),
|
||||
opt.(1, "clear", "Clear the queue", [])
|
||||
opt.(1, "clear", "Clear the queue", []),
|
||||
opt.(1, "show", "Show the queue", [])
|
||||
]
|
||||
|
||||
def subcommands() do
|
||||
|
@ -43,4 +44,22 @@ defmodule Sergei.Commands.Queue do
|
|||
{:ok, "I'm not playing anything right now."}
|
||||
end
|
||||
end
|
||||
|
||||
def handle(guild_id, "show", _opts) do
|
||||
case Sergei.Player.queue_list(guild_id) do
|
||||
:not_playing ->
|
||||
{:ok, "I'm not playing anything right now."}
|
||||
|
||||
[] ->
|
||||
{:ok, "The queue is empty."}
|
||||
|
||||
songs_in_queue ->
|
||||
song_list =
|
||||
songs_in_queue
|
||||
|> Enum.with_index(1)
|
||||
|> Enum.reduce("", fn {song, idx}, acc -> acc <> "\n#{idx}. #{song}" end)
|
||||
|
||||
{:ok, song_list}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,6 +34,11 @@ defmodule Sergei.Player do
|
|||
GenServer.call(__MODULE__, {:queue_clear, guild_id})
|
||||
end
|
||||
|
||||
@spec queue_list(integer()) :: [String.t()] | :not_playing
|
||||
def queue_list(guild_id) do
|
||||
GenServer.call(__MODULE__, {:queue_list, guild_id})
|
||||
end
|
||||
|
||||
@spec pause(integer()) :: :ok | :not_playing | {:error, String.t()}
|
||||
def pause(guild_id) do
|
||||
GenServer.call(__MODULE__, {:pause, guild_id})
|
||||
|
@ -173,6 +178,19 @@ defmodule Sergei.Player do
|
|||
}
|
||||
end
|
||||
|
||||
# Queue List
|
||||
@impl true
|
||||
def handle_call({:queue_list, guild_id}, _from, state) do
|
||||
{
|
||||
:reply,
|
||||
state
|
||||
|> Map.get(guild_id)
|
||||
|> Map.get(:queue)
|
||||
|> :queue.to_list(),
|
||||
state
|
||||
}
|
||||
end
|
||||
|
||||
# Pause
|
||||
@impl true
|
||||
def handle_call({:pause, guild_id}, _from, state) do
|
||||
|
|
Loading…
Reference in a new issue