refactor: Move queue commands to queue.ex

This commit is contained in:
Roman 2023-06-06 17:01:17 -04:00
parent d24e6530b7
commit 7243837cdb
2 changed files with 20 additions and 10 deletions

View file

@ -11,19 +11,10 @@ defmodule Sergei.Commands do
opt.(3, "url", "URL of the audio to play", []) opt.(3, "url", "URL of the audio to play", [])
] ]
@queue_add_opts [
opt.(3, "url", "URL of the audio to queue", required: true)
]
@queue_opts [
opt.(1, "add", "Add a song to the queue", options: @queue_add_opts),
opt.(1, "clear", "Clear the queue", [])
]
@slash_commands [ @slash_commands [
{"ping", "Pong", []}, {"ping", "Pong", []},
{"play", "Play a song or resume playback", @play_opts}, {"play", "Play a song or resume playback", @play_opts},
{"queue", "Manage the song queue", @queue_opts}, {"queue", "Manage the song queue", Sergei.Commands.Queue.subcommands()},
{"pause", "Pause media playback", []}, {"pause", "Pause media playback", []},
{"stop", "Stop media playback and leave the voice channel", []}, {"stop", "Stop media playback and leave the voice channel", []},
{"song", "What song is currently playing?", []} {"song", "What song is currently playing?", []}

View file

@ -1,4 +1,23 @@
defmodule Sergei.Commands.Queue do defmodule Sergei.Commands.Queue do
# Translate params to list of maps
opt = fn type, name, desc, opts ->
%{type: type, name: name, description: desc}
|> Map.merge(Enum.into(opts, %{}))
end
@queue_add_opts [
opt.(3, "url", "URL of the audio to queue", required: true)
]
@queue_commands [
opt.(1, "add", "Add a song to the queue", options: @queue_add_opts),
opt.(1, "clear", "Clear the queue", [])
]
def subcommands() do
@queue_commands
end
@spec handle(integer(), String.t(), [%{name: String.t(), value: String.t()}]) :: @spec handle(integer(), String.t(), [%{name: String.t(), value: String.t()}]) ::
{:ok, String.t()} | {:err, String.t()} {:ok, String.t()} | {:err, String.t()}
def handle(guild_id, "add", opts) do def handle(guild_id, "add", opts) do