defmodule LSG.IRC.NpHandler do @moduledoc """ # np * **!np** chanson/émission actuellement sur le stream de 115ans.net """ def short_irc_doc, do: "!np (en ce moment sur 115ans)" def irc_doc, do: @moduledoc 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