mirror of
https://codeberg.org/godmaire/sergei.git
synced 2024-09-20 00:08:25 +00:00
feat: add /song command
/song command will show the song currently playing.
This commit is contained in:
parent
c4834abfe3
commit
ffcc3f6b66
2 changed files with 30 additions and 1 deletions
|
@ -18,7 +18,8 @@ defmodule Sergei.Consumer do
|
||||||
{"ping", "Pong", []},
|
{"ping", "Pong", []},
|
||||||
{"play", "Play a song or resume playback", @play_opts},
|
{"play", "Play a song or resume playback", @play_opts},
|
||||||
{"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?", []}
|
||||||
]
|
]
|
||||||
|
|
||||||
def start_link do
|
def start_link do
|
||||||
|
@ -159,4 +160,15 @@ defmodule Sergei.Consumer do
|
||||||
{:error, "This is embarrasing..."}
|
{:error, "This is embarrasing..."}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# /song
|
||||||
|
def do_command(%{guild_id: guild_id, data: %{name: "song"}}) do
|
||||||
|
case Sergei.Player.get_current_song(guild_id) do
|
||||||
|
:not_playing ->
|
||||||
|
{:ok, "I'm not playing anything right now."}
|
||||||
|
|
||||||
|
url ->
|
||||||
|
{:ok, url}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,11 @@ defmodule Sergei.Player do
|
||||||
GenServer.call(__MODULE__, {:stop, guild_id})
|
GenServer.call(__MODULE__, {:stop, guild_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_current_song(integer()) :: String.t() | :not_playing
|
||||||
|
def get_current_song(guild_id) do
|
||||||
|
GenServer.call(__MODULE__, {:get_current_song, guild_id})
|
||||||
|
end
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info(:tick, state) do
|
def handle_info(:tick, state) do
|
||||||
|
@ -103,6 +108,18 @@ defmodule Sergei.Player do
|
||||||
{:reply, :ok, Map.delete(state, guild_id)}
|
{:reply, :ok, Map.delete(state, guild_id)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_call({:get_current_song, guild_id}, _from, state) do
|
||||||
|
res =
|
||||||
|
case Map.get(state, guild_id) do
|
||||||
|
%{url: url} -> url
|
||||||
|
nil -> :not_playing
|
||||||
|
_ -> Logger.error("error: Guild found, but no URL is given")
|
||||||
|
end
|
||||||
|
|
||||||
|
{:reply, res, state}
|
||||||
|
end
|
||||||
|
|
||||||
def play_music(guild_id, channel_id, url) do
|
def play_music(guild_id, channel_id, url) do
|
||||||
cond do
|
cond do
|
||||||
Voice.get_channel_id(guild_id) != channel_id ->
|
Voice.get_channel_id(guild_id) != channel_id ->
|
||||||
|
|
Loading…
Reference in a new issue