Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

admin: added insmod

  • Loading branch information...
commit 39147cb351b3106de48f9999dd955a7e5b7752df 1 parent fe11812
@dnet authored
Showing with 28 additions and 1 deletion.
  1. +17 −1 admin.erl
  2. +11 −0 ircbot.erl
View
18 admin.erl
@@ -1,5 +1,5 @@
-module(admin).
--export([ircmain/1, ircproc/1, lsmod/2, rmmod/3]).
+-export([ircmain/1, ircproc/1, lsmod/2, rmmod/3, insmod/3]).
-include("nick.hrl").
ircmain(Contact) ->
@@ -93,6 +93,13 @@ process_privmsg("rmmod", Remainder, ReplyTo, Prefix, Contact) ->
false ->
noreply
end;
+process_privmsg("insmod", Remainder, ReplyTo, Prefix, Contact) ->
+ case admin(Prefix) of
+ true ->
+ spawn(?MODULE, insmod, [ReplyTo, Remainder, Contact]), noreply;
+ false ->
+ noreply
+ end;
process_privmsg(_, _, _, _, _) ->
noreply.
@@ -124,6 +131,15 @@ rmmod(To, [FirstParam | _], Contact) ->
Contact ! {raw, "PRIVMSG " ++ To ++ " :(timeout)"}
end.
+insmod(To, [ModName | Params], Contact) ->
+ Contact ! {insmod, ModName, Params, self()},
+ receive
+ {insmod, Resp} ->
+ Contact ! {raw, "PRIVMSG " ++ To ++ " :" ++ Resp}
+ after 1500 ->
+ Contact ! {raw, "PRIVMSG " ++ To ++ " :(timeout)"}
+ end.
+
strip_crlf(Str) ->
string:strip(string:strip(Str, right, $\n), right, $\r).
View
11 ircbot.erl
@@ -78,6 +78,17 @@ master(State = #ms{socket = Socket}) ->
RespPid ! {killmod, "invalid module"},
State
end);
+ {insmod, ModName, Params, Pid} ->
+ ModAtom = list_to_atom(ModName),
+ case erlang:function_exported(ModAtom, ircmain, length(Params) + 1) of
+ true ->
+ ModPid = apply(ModAtom, ircmain, [self() | Params]),
+ Pid ! {insmod, "inserted module " ++ ModName ++ " as PID " ++ pid_to_list(ModPid)},
+ master(State#ms{modpids = [ModPid | State#ms.modpids]});
+ false ->
+ Pid ! {insmod, "invalid module or parameter count"},
+ master(State)
+ end;
{tcp, Socket, Data} ->
lists:foreach(fun(P) -> P ! {incoming, Data} end, State#ms.rawsubscribers),
master(State);
Please sign in to comment.
Something went wrong with that request. Please try again.