summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/broadcast_handler.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_irc/broadcast_handler.ex')
-rw-r--r--lib/lsg_irc/broadcast_handler.ex43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/lsg_irc/broadcast_handler.ex b/lib/lsg_irc/broadcast_handler.ex
new file mode 100644
index 0000000..22ffbaf
--- /dev/null
+++ b/lib/lsg_irc/broadcast_handler.ex
@@ -0,0 +1,43 @@
+defmodule LSG.IRC.BroadcastHandler 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, ["#lsg"], false}}
+ end
+
+ def handle_info({:icecast, stats = %{live: true}}, s = {client, channels, true}) do
+ for c <- channels do
+ ExIRC.Client.msg(client, :privmsg, c, "en direct: "<>format_genre(stats.genre) <> stats.np)
+ end
+ {:noreply, s}
+ end
+
+ def handle_info({:icecast, stats = %{live: true}}, s = {client, channels, false}) do
+ for c <- channels do
+ ExIRC.Client.msg(client, :privmsg, c, "115ANS EN DIREK! " <> format_genre(stats.genre) <> stats.np)
+ end
+ {:noreply, {client, channels, true}}
+ end
+
+ def handle_info({:icecast, stats = %{live: false}}, s = {client, channels, true}) do
+ for c <- channels do
+ ExIRC.Client.msg(client, :privmsg, c, "Le direct c'est fini, retour aux Smashing Pumpkins...")
+ ExIRC.Client.msg(client, :privmsg, c, "np: " <> stats.np)
+ end
+ {:noreply, {client, channels, false}}
+ end
+
+ # Catch-all for messages you don't care about
+ def handle_info(msg, state) do
+ {:noreply, state}
+ end
+
+ defp format_genre(nil), do: ""
+ defp format_genre(""), do: ""
+ defp format_genre(text), do: "[#{text}] "
+
+end