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'(x::xs, acc) -> ircnick'(xs, acc + x).
|
||||||
ircnick(str) -> ircnick'(str, "").
|
ircnick(str) -> ircnick'(str, "").
|
||||||
|
|
||||||
-- state stuff
|
|
||||||
initialState = ([]).
|
|
||||||
|
|
||||||
-- state getters
|
-- state getters
|
||||||
getFactoids(state) -> do
|
getFactoids(state) -> do
|
||||||
(factoids) = state;
|
(factoids) = state;
|
||||||
|
@ -72,6 +69,26 @@ setFactoids(state, factoids) -> do
|
||||||
(factoids)
|
(factoids)
|
||||||
end.
|
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
|
-- event handling
|
||||||
|
|
||||||
say(chan, msg) -> fputstr(sock, "PRIVMSG " + chan + " :" + msg + "\r\n").
|
say(chan, msg) -> fputstr(sock, "PRIVMSG " + chan + " :" + msg + "\r\n").
|
||||||
|
@ -187,6 +204,9 @@ mainloop(state) ->
|
||||||
else
|
else
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
putstrln("initializing").
|
||||||
|
initialState = (loadFactoids()).
|
||||||
|
|
||||||
putstrln("beginning mainloop").
|
putstrln("beginning mainloop").
|
||||||
loop(mainloop, initialState).
|
loop(mainloop, initialState).
|
||||||
fclose(sock).
|
fclose(sock).
|
||||||
|
|
Loading…
Reference in New Issue