summaryrefslogtreecommitdiff
path: root/lib/irc/admin_handler.ex
blob: cb953dbd37dcd565f22f558505de6a17f6154162 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
defmodule Nola.Irc.AdminHandler do
  @moduledoc """
  # admin

      !op
          op; requiert admin
  """

  def irc_doc, do: nil

  def start_link(client) do
    GenServer.start_link(__MODULE__, [client])
  end

  def init([client]) do
    ExIRC.Client.add_handler client, self
    {:ok, _} = Registry.register(Nola.PubSub, "op", [])
    {:ok, client}
  end

  def handle_info({:irc, :trigger, "op", m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}, sender: sender}}, client) do
    if Nola.Irc.admin?(sender) do
      m.replyfun.({:mode, "+o"})
    else
      m.replyfun.({:kick, "non"})
    end
    {:noreply, client}
  end

  def handle_info({:joined, chan, sender}, client) do
    if Nola.Irc.admin?(sender) do
      ExIRC.Client.mode(client, chan, "+o", sender.nick)
    end
    {:noreply, client}
  end

  def handle_info(msg, client) do
    {:noreply, client}
  end

end