% end of MOTD, which should normally be sent on connect
error_logger:info_msg("Joining my channels now.", []),
{_, _, _, _, Channels} = State#irc_state.config,
- lists:foreach(fun join_channel/1, Channels),
+ lists:foreach(fun(Channel) -> join_channel(Channel, State) end, Channels),
State#irc_state{joined = true};
"PRIVMSG" ->
do_privmsg(Command),
send_command(Command) ->
gen_server:cast(self(), {send_command, Command}).
-join_channel(Channel) ->
+join_channel(Channel, State) ->
Command = #irc_command{command = "JOIN", middles = [Channel]},
send_command(Command),
- irc_amqp_listener:start_link(self(), Channel, "foobar"). %% TODO: fix routing key
+ #irc_state{ object_sup = ObjectSup } = State,
+ {ok, _ChildPid} = irc_object_sup:add_amqp_listener(ObjectSup, self(), Channel).
%% @doc Splits a buffer into full lines, keeping whatever is left over
%% Returns either {ok, [Line], Remaining} or none.