add factoid serialization
This commit is contained in:
parent
379fd34768
commit
bebd9e6adc
26
irc.lamb
26
irc.lamb
|
@ -58,9 +58,6 @@ ircnick'("!"::xs, acc) -> acc.
|
|||
ircnick'(x::xs, acc) -> ircnick'(xs, acc + x).
|
||||
ircnick(str) -> ircnick'(str, "").
|
||||
|
||||
-- state stuff
|
||||
initialState = ([]).
|
||||
|
||||
-- state getters
|
||||
getFactoids(state) -> do
|
||||
(factoids) = state;
|
||||
|
@ -72,6 +69,26 @@ setFactoids(state, factoids) -> do
|
|||
(factoids)
|
||||
end.
|
||||
|
||||
-- factoid serialization
|
||||
-- basic "key value" (space-separated) format
|
||||
saveFactoids(factoids) -> do
|
||||
file = fopen("factoids.txt", "w");
|
||||
map(\(k,v) -> fputstr(file, k + " " + v + "\n"), factoids);
|
||||
fclose(file)
|
||||
end.
|
||||
|
||||
loadFactoids() -> do
|
||||
file = fopen("factoids.txt", "r");
|
||||
fact = loop(\pairs ->
|
||||
if feof(file) != true then do
|
||||
line = fgetline(file);
|
||||
pair = takeUntilSpace(line);
|
||||
pair :: pairs
|
||||
end else false, []);
|
||||
fclose(file);
|
||||
fact
|
||||
end.
|
||||
|
||||
-- event handling
|
||||
|
||||
say(chan, msg) -> fputstr(sock, "PRIVMSG " + chan + " :" + msg + "\r\n").
|
||||
|
@ -187,6 +204,9 @@ mainloop(state) ->
|
|||
else
|
||||
false.
|
||||
|
||||
putstrln("initializing").
|
||||
initialState = (loadFactoids()).
|
||||
|
||||
putstrln("beginning mainloop").
|
||||
loop(mainloop, initialState).
|
||||
fclose(sock).
|
||||
|
|
Loading…
Reference in New Issue