Skip to content

Instantly share code, notes, and snippets.

@dnet
Created September 22, 2013 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnet/6660260 to your computer and use it in GitHub Desktop.
Save dnet/6660260 to your computer and use it in GitHub Desktop.
Ticket number reporter for dnet's fork of jimm-erlang-bot
-module(tickets).
-export([ircmain/1, ircproc/1, reload/2]).
-define(TICKETS_DIR, "path/to/campzer0").
tickets() ->
NumTickets = filelib:fold_files(?TICKETS_DIR,
"\\.json$", false, fun (_, A) -> A + 1 end, 0),
integer_to_list(NumTickets).
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} ->
S = binary_to_list(Data),
case string:str(S, ":-tickets") of
0 -> nop;
_ -> spawn(fun() ->
Contact ! {announce, tickets()} end)
end,
ircproc(Contact);
{ident, Pid} ->
Pid ! {ident, "tickets"},
ircproc(Contact);
{reload, Pid} ->
?MODULE:reload(Contact, Pid);
_ -> ircproc(Contact)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment