Skip to content
Browse files

Fix errors around statically starting the bot.

  • Loading branch information...
1 parent d990c88 commit d2ee6385d3b28fa2a0a04aa4be08e7dd794b15bf @jlouis committed
Showing with 13 additions and 14 deletions.
  1. +10 −11 src/irc_bot.erl
  2. +1 −1 src/irc_bot_sup.erl
  3. +2 −2 src/test_bot.erl
View
21 src/irc_bot.erl
@@ -101,12 +101,12 @@ init([Conf]) ->
end,
Connections = case look_conf(connections, Conf) of
{ok, Conns} ->
- connect_servers(Conns);
+ connect_servers(Conns, dict:new());
not_found ->
[]
end,
{ok, #state{ conf=Conf,
- connections = dict:from_list(Connections),
+ connections = Connections,
plugin_mgr = PGMgr }}.
%%--------------------------------------------------------------------
@@ -136,10 +136,10 @@ handle_call({add_plugin, Plugin, Args}, _From, #state { plugin_mgr = Name } = St
{reply, Reply, State};
handle_call(connections, _From, State = #state{connections=C}) ->
{reply, {ok, dict:to_list(C)}, State};
-handle_call({connect, Host, Port}, _From, State) ->
- [{Pid, ConInfo}] = connect_servers([{Host, Port}]),
- {reply, {ok, Pid},
- State#state{ connections = dict:append(Pid, ConInfo, State#state.connections) }};
+handle_call({connect, Host, Port}, _From, #state { connections = Connections } = State) ->
+ NewConnections = connect_servers([{Host, Port}], Connections),
+ {reply, ok,
+ State#state{ connections = NewConnections }};
handle_call(Call, _From, State) ->
?WARN("Unexpected call ~p.", [Call]),
{noreply, State}.
@@ -259,12 +259,11 @@ add_plugins(PMgr, [{Plugin, Args} | Rest]) ->
ok = irc_bot_plugin_mgr:add_plugin(PMgr, Plugin, Args),
add_plugins(PMgr, Rest).
-connect_servers([]) ->
- [];
-connect_servers([{Host, Port} | Rest]) ->
+connect_servers([], D) -> D;
+connect_servers([{Host, Port} | Rest], Dict) ->
{ok, Pid} = irc_connection:start_link(Host, Port, [{sendfn, fun client_cmd/2}]),
- [{Pid, #coninfo { host = Host, port = Port }} |
- connect_servers(Rest)].
+ connect_servers(Rest,
+ dict:append(Pid, #coninfo { host = Host, port = Port }, Dict)).
info(Host, Port, Command) ->
?INFO("~s:~p -- command:~n ~s", [Host, Port, irc_cmd:format(Command)]).
View
2 src/irc_bot_sup.erl
@@ -62,7 +62,7 @@ init([Name, PlugMgrName, Opts]) ->
PluginMgr = {'Plugin Manager', {irc_bot_plugin_mgr, start_link, [{local, PlugMgrName}]},
permanent, 2000, worker, [irc_bot_plugin_mgr]},
- {ok, {SupFlags, [BotClient, PluginMgr]}}.
+ {ok, {SupFlags, [PluginMgr, BotClient]}}.
%%%===================================================================
%%% Internal functions
View
4 src/test_bot.erl
@@ -11,5 +11,5 @@ t() ->
{username, "My Bot Username"},
{nick, "erlangbot"},
{connections, [{"irc.baconsvin.dk", 6667}]},
- {plugins, [{irc_chan_handler, [Args]}]}],
- {ok, Pid} = irc_bot_sup:start_link(test_bot, test_bot_plgin, Opts).
+ {plugins, [{ircb_chan_handler, [Args]}]}],
+ {ok, Pid} = irc_bot_sup:start_link(test_bot, test_bot_plugin, Opts).

0 comments on commit d2ee638

Please sign in to comment.
Something went wrong with that request. Please try again.