Created
September 22, 2013 14:11
-
-
Save dnet/6660260 to your computer and use it in GitHub Desktop.
Ticket number reporter for dnet's fork of jimm-erlang-bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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