summaryrefslogblamecommitdiff
path: root/lib/irc.ex
blob: 6ba819ceedb1d0f8773fb73099105f7ecec19f40 (plain) (tree)

































                                                                                            
defmodule IRC do

  defmodule Message do
    defstruct [:text,
               :sender,
               :channel,
               :trigger,
               :replyfun]
  end
  defmodule Trigger do
    defstruct [:type, :trigger, :args]
  end

  def register(key) do
    case Registry.register(IRC.PubSub, key, []) do
      {:ok, _} -> :ok
      error -> error
    end
  end

  def admin?(%Message{sender: sender}), do: admin?(sender)

  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