       'PRIVMSG' ->
         [_chan, msg] = args
         {:msg, sender, msg}
-      '332' ->
-        {:reply, "Greetings, apprentices"}
+      #'332' ->
+        #{:reply, "Greetings, apprentices"}
       'PING' ->
         :pong
       _ -> nil

        end
        state

      other ->
        raise RuntimeError[message: "unhandled msg #{inspect other}"]
    end
    message_loop(sock, state)
  end

  def process_hooks({sender, msg}, %State{hooks: hooks}, sock) do

    send(__MODULE__, {:internal, {:remove_hook, id}})
  end


  @nsec 10
  @ping_sec 5 * 60
  @maxattempts 30

  defp sleep_sec(n), do: :timer.sleep(n * 1000)

  defp connect(host \\ 'irc.freenode.net', port \\ 6667) do
    case :gen_tcp.connect(host, port, packet: :line, active: true) do
      {:ok, sock} ->
        Process.delete(:connect_attempts)
        handshake(sock)

      other ->
        IO.puts "Failed to connect: #{inspect other}"
        nattempts = Process.get(:connect_attempts, 0)
        if nattempts >= @maxattempts do
          IO.puts "FAILED TO CONNECT #{@maxattempts} TIMES IN A ROW. SHUTTING DOWN"
          :erlang.halt()
        else
          Process.put(:connect_attempts, nattempts+1)
          IO.puts "RETRYING IN #{@nsec} SECONDS"
          sleep_sec(@nsec)
          connect(host, port)
        end
    end
  end

  defp handshake(sock) do
    :random.seed(:erlang.now())

    sock
