simple factoid lookups
This commit is contained in:
parent
17aad66b8f
commit
379fd34768
1 changed files with 27 additions and 0 deletions
27
irc.lamb
27
irc.lamb
|
@ -5,6 +5,16 @@ map(f, x::xs) -> f(x) :: map(f, xs).
|
||||||
|
|
||||||
fst((x, _)) -> x.
|
fst((x, _)) -> x.
|
||||||
|
|
||||||
|
-- maybe stuff
|
||||||
|
|
||||||
|
is_just(("just", _)) -> true.
|
||||||
|
is_just(_) -> false.
|
||||||
|
|
||||||
|
is_nothing(("nothing")) -> true.
|
||||||
|
is_nothing(_) -> false.
|
||||||
|
|
||||||
|
unwrap_maybe(("just", x)) -> x.
|
||||||
|
|
||||||
-- association list
|
-- association list
|
||||||
|
|
||||||
-- insert a pair into a map
|
-- insert a pair into a map
|
||||||
|
@ -38,6 +48,7 @@ splitirc'(x::xs, stracc, acc) -> splitirc'(xs, stracc + x, acc).
|
||||||
splitirc(str) -> splitirc'(str, "", []).
|
splitirc(str) -> splitirc'(str, "", []).
|
||||||
|
|
||||||
-- (result, rest)
|
-- (result, rest)
|
||||||
|
takeUntilSpace'("", acc) -> (acc, ""). -- no spaces
|
||||||
takeUntilSpace'(" "::xs, acc) -> (acc, xs).
|
takeUntilSpace'(" "::xs, acc) -> (acc, xs).
|
||||||
takeUntilSpace'(x::xs, acc) -> takeUntilSpace'(xs, acc + x).
|
takeUntilSpace'(x::xs, acc) -> takeUntilSpace'(xs, acc + x).
|
||||||
takeUntilSpace(str) -> takeUntilSpace'(str, "").
|
takeUntilSpace(str) -> takeUntilSpace'(str, "").
|
||||||
|
@ -85,6 +96,22 @@ handleMessage(s, "darkf", chan, "$quit") -> do
|
||||||
fclose(sock);
|
fclose(sock);
|
||||||
s
|
s
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-- unknown command, search factoids
|
||||||
|
handleMessage(s, nick, chan, "$"::line) -> do
|
||||||
|
(fact, rest) = takeUntilSpace(line);
|
||||||
|
if rest != "" then s -- it had spaces after it, might not want a factoid
|
||||||
|
else do
|
||||||
|
factoids = getFactoids(s);
|
||||||
|
factoid = map_lookup(factoids, fact);
|
||||||
|
if is_just(factoid) then do
|
||||||
|
say(chan, unwrap_maybe(factoid));
|
||||||
|
s
|
||||||
|
end
|
||||||
|
else s
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
handleMessage(s, nick, chan, msg) -> s.
|
handleMessage(s, nick, chan, msg) -> s.
|
||||||
|
|
||||||
-- handleCommand(source, cmd, args)
|
-- handleCommand(source, cmd, args)
|
||||||
|
|
Loading…
Reference in a new issue