add isAdmin function

This commit is contained in:
darkf 2013-10-27 02:11:08 -07:00
parent 04f84d8815
commit f1b48d77df
1 changed files with 29 additions and 7 deletions

View File

@ -1,3 +1,8 @@
-- global data stuff
-- nicks of administrators
ADMINS = ["darkf"].
-- First we'll define some helper functions -- First we'll define some helper functions
map(f, []) -> []. map(f, []) -> [].
@ -15,6 +20,12 @@ is_nothing(_) -> false.
unwrap_maybe(("just", x)) -> x. unwrap_maybe(("just", x)) -> x.
-- list membership test
is_member([], _) -> false.
is_member(x::xs, member) ->
if x == member then true
else is_member(xs, member).
-- association list -- association list
-- insert a pair into a map -- insert a pair into a map
@ -58,6 +69,10 @@ 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, "").
isAdmin(nick) -> do
is_member(ADMINS, nick)
end.
-- state getters -- state getters
getFactoids(state) -> do getFactoids(state) -> do
(factoids) = state; (factoids) = state;
@ -106,17 +121,24 @@ handleMessage(s, nick, chan, "$defact "::line) -> do
setFactoids(s, map_insert(factoids, k, v)) setFactoids(s, map_insert(factoids, k, v))
end. end.
handleMessage(s, "darkf", chan, "$savefacts") -> do handleMessage(s, nick, chan, "$savefacts") -> do
saveFactoids(getFactoids(s)); if isAdmin(nick) then do
say(chan, "factoids saved."); saveFactoids(getFactoids(s));
say(chan, "factoids saved.")
end
else say(chan, nick + ": you are not an admin");
s s
end. end.
handleMessage(s, nick, chan, "$ping") -> do say(chan, nick + ": pong"); s end. handleMessage(s, nick, chan, "$ping") -> do say(chan, nick + ": pong"); s end.
handleMessage(s, "darkf", chan, "$quit") -> do
say(chan, "bye!"); handleMessage(s, nick, chan, "$quit") -> do
fputstr(sock, "QUIT\r\n"); if isAdmin(nick) then do
fclose(sock); say(chan, "bye!");
fputstr(sock, "QUIT\r\n");
fclose(sock)
end
else say(chan, nick + ": you are not an admin");
s s
end. end.