summaryrefslogblamecommitdiff
path: root/lib/nola_plugins/admin_handler.ex
blob: 9a5d55791d8a4ff0a70d2fbbe330e5f93f239be3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
                                  














                                              
                            


                 










                                                                                                                          





                                                        



                      
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 = IRC.register("op")
    {:ok, client}
  end

  def handle_info({:irc, :trigger, "op", m = %IRC.Message{trigger: %IRC.Trigger{type: :bang}, sender: sender}}, client) do
    if 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 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