summaryrefslogblamecommitdiff
path: root/lib/lsg_irc.ex
blob: b988e04a61feb3480ae742c02cfd9a1073d54828 (plain) (tree)
1
                    


























                                                                                            
   
defmodule LSG.IRC do

  def application_childs do
    {:ok, irc_client} = ExIRC.start_link!
    import Supervisor.Spec
    [
      worker(LSG.IRC.UserTrack.Storage, []),
      worker(LSG.IRC.ConnectionHandler, [irc_client]),
      worker(LSG.IRC.LoginHandler, [irc_client]),
      worker(LSG.IRC.UserTrackHandler, [irc_client]),
    ]
    ++
    for handler <- Application.get_env(:lsg, :irc)[:handlers] do
      worker(handler, [irc_client])
    end
  end

  def admin?(%{nick: nick, user: user, host: host}) do
    for {n, u, h} <- Application.get_env(:lsg, :irc, [])[:admins]||[] do
      admin_part_match?(n, nick) && admin_part_match?(u, user) && admin_part_match?(h, host)
    end
    |> Enum.any?
  end

  defp admin_part_match?(:_, _), do: true
  defp admin_part_match?(a, a), do: true
  defp admin_part_match?(_, _), do: false

end