diff --git a/lib/sergei/commands.ex b/lib/sergei/commands.ex index e0da753..65b3ac5 100644 --- a/lib/sergei/commands.ex +++ b/lib/sergei/commands.ex @@ -11,19 +11,10 @@ defmodule Sergei.Commands do 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 [ {"ping", "Pong", []}, {"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", []}, {"stop", "Stop media playback and leave the voice channel", []}, {"song", "What song is currently playing?", []} diff --git a/lib/sergei/commands/queue.ex b/lib/sergei/commands/queue.ex index 3188ece..7cef12d 100644 --- a/lib/sergei/commands/queue.ex +++ b/lib/sergei/commands/queue.ex @@ -1,4 +1,23 @@ 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()}]) :: {:ok, String.t()} | {:err, String.t()} def handle(guild_id, "add", opts) do