From dcee567e1d2d98173df6ec022ec1ed5f66c92b9d Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Wed, 30 Mar 2016 23:16:33 -0700 Subject: handle QUIT messages Prior to this commit ExIrc did not know what to do with QUIT messages, which would result in nicks remaining in the `Channels` data structure when they should not. This commit implements handling of the QUIT message and ensures that the new `Channels.user_quit` function is called to flush the departing user from all known channels. Close #40 --- lib/exirc/client.ex | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/exirc/client.ex') diff --git a/lib/exirc/client.ex b/lib/exirc/client.ex index 0ef50cc..7fb9122 100644 --- a/lib/exirc/client.ex +++ b/lib/exirc/client.ex @@ -637,6 +637,15 @@ defmodule ExIrc.Client do send_event {:parted, channel, sender}, new_state {:noreply, new_state} end + def handle_data(%IrcMessage{cmd: "QUIT", nick: from, host: host, user: user} = msg, state) do + sender = %SenderInfo{nick: from, host: host, user: user} + reason = msg.args |> List.first + if state.debug?, do: debug "#{from} QUIT" + channels = Channels.user_quit(state.channels, from) + new_state = %{state | channels: channels} + send_event {:quit, reason, sender}, new_state + {:noreply, new_state} + end # Called when we receive a PING def handle_data(%IrcMessage{cmd: "PING"} = msg, %ClientState{autoping: true} = state) do if state.debug?, do: debug "RECEIVED A PING!" -- cgit v1.2.3