Skip to content

Commit

Permalink
added version module
Browse files Browse the repository at this point in the history
  • Loading branch information
dnet committed Jun 19, 2011
1 parent 65eff1a commit d6b14e0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions version.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-module(version).
-export([ircmain/1, ircproc/1, reload/2]).

ircmain(Contact) ->
Pid = spawn(?MODULE, ircproc, [Contact]),
Contact ! {subscribe, Pid},
Pid.

reload(Contact, Pid) ->
Pid ! reloaded,
ircproc(Contact).

ircproc(Contact) ->
receive
quit -> quit;
{incoming, <<":", Data/binary>>} ->
case string:tokens(binary_to_list(Data), " ") of
[From, "PRIVMSG", _, [58, 1, 86, 69, 82, 83, 73, 79, 78, 1 | _]] ->
[Nick | _] = string:tokens(From, "!"),
Contact ! {raw, lists:flatten(io_lib:format(
"NOTICE ~s :\x01VERSION jimm-erlang-bot running " ++
"on Erlang emulator ~s OTP release ~s\x01",
[Nick, erlang:system_info(version),
erlang:system_info(otp_release)]))};
_ -> nop
end,
ircproc(Contact);
{ident, Pid} ->
Pid ! {ident, "version"},
ircproc(Contact);
{reload, Pid} ->
?MODULE:reload(Contact, Pid);
_ -> ircproc(Contact)
end.

0 comments on commit d6b14e0

Please sign in to comment.