%% as PRIVMSG to a particular destination
-module(irc_amqp_listener).
-behavior(gen_server).
--vsn(2).
+-vsn(3).
-define(EXCHANGE, <<"irc">>).
-export([
init/1,
- handle_info/2
+ handle_info/2,
+ code_change/3
]).
-include("irc_util.hrl").
irc_conn:send_command(ConnectionPid, Command),
{noreply, State}.
+code_change(2, {ConnectionPid}, _) ->
+ case process_info(self(), monitors) of
+ {monitors, [{process, ListeningChannel}]} ->
+ {ok, {ConnectionPid, ListeningChannel}};
+ _ ->
+ {error, cant_find_listening_channel}
+ end;
+
+code_change({down, 2}, {ConnectionPid, _ListeningChannel}, _) ->
+ {ok, {ConnectionPid}}.
+
%% @doc Sends a message with the given routing key and body to the proper
%% exchange
send_message(RoutingKey, ReplyTo, Body) ->