diff options
Diffstat (limited to 'lib/lsg_irc/connection_handler.ex')
-rw-r--r-- | lib/lsg_irc/connection_handler.ex | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/lsg_irc/connection_handler.ex b/lib/lsg_irc/connection_handler.ex new file mode 100644 index 0000000..f3bb1d4 --- /dev/null +++ b/lib/lsg_irc/connection_handler.ex @@ -0,0 +1,36 @@ +defmodule LSG.IRC.ConnectionHandler do + defmodule State do + defstruct host: "irc.quakenet.org", + port: 6667, + pass: "", + nick: "bot115ans", + user: "115ans", + name: "115ans.net", + client: nil + end + + def start_link(client) do + GenServer.start_link(__MODULE__, [%State{client: client}]) + end + + def init([state]) do + ExIRC.Client.add_handler state.client, self + ExIRC.Client.connect! state.client, state.host, state.port + {:ok, state} + end + + def handle_info({:connected, server, port}, state) do + debug "Connected to #{server}:#{port}" + ExIRC.Client.logon state.client, state.pass, state.nick, state.user, state.name + {:noreply, state} + end + + # Catch-all for messages you don't care about + def handle_info(msg, state) do + {:noreply, state} + end + + defp debug(msg) do + IO.puts IO.ANSI.yellow() <> msg <> IO.ANSI.reset() + end +end |