summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/np_handler.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_irc/np_handler.ex')
-rw-r--r--lib/lsg_irc/np_handler.ex32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/lsg_irc/np_handler.ex b/lib/lsg_irc/np_handler.ex
new file mode 100644
index 0000000..8bde293
--- /dev/null
+++ b/lib/lsg_irc/np_handler.ex
@@ -0,0 +1,32 @@
+defmodule LSG.IRC.NpHandler do
+ def start_link(client) do
+ GenServer.start_link(__MODULE__, [client])
+ end
+
+ def init([client]) do
+ ExIRC.Client.add_handler client, self
+ {:ok, _} = Registry.register(LSG.BroadcastRegistry, "icecast", [])
+ {:ok, client}
+ end
+
+ def handle_info({:received, "!np", _, chan}, client) do
+ stats = LSG.IcecastAgent.get
+ np = if stats.live do
+ "en direct: #{format_genre(stats.genre)}#{stats.np}"
+ else
+ "np: #{stats.np}"
+ end
+ ExIRC.Client.msg(client, :privmsg, chan, np)
+ {:noreply, client}
+ end
+
+ # Catch-all for messages you don't care about
+ def handle_info(msg, client) do
+ {:noreply, client}
+ end
+
+ defp format_genre(nil), do: ""
+ defp format_genre(""), do: ""
+ defp format_genre(text), do: "[#{text}] "
+
+end