Skip to content
Browse files

added version module

  • Loading branch information...
1 parent 65eff1a commit d6b14e018cc635b289a6a536e6b904aeb5a71da4 @dnet committed Jun 19, 2011
Showing with 34 additions and 0 deletions.
  1. +34 −0 version.erl
View
34 version.erl
@@ -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.
Something went wrong with that request. Please try again.