add isAdmin function
This commit is contained in:
parent
04f84d8815
commit
f1b48d77df
1 changed files with 29 additions and 7 deletions
30
irc.lamb
30
irc.lamb
|
@ -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
|
||||||
|
if isAdmin(nick) then do
|
||||||
saveFactoids(getFactoids(s));
|
saveFactoids(getFactoids(s));
|
||||||
say(chan, "factoids saved.");
|
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
|
|
||||||
|
handleMessage(s, nick, chan, "$quit") -> do
|
||||||
|
if isAdmin(nick) then do
|
||||||
say(chan, "bye!");
|
say(chan, "bye!");
|
||||||
fputstr(sock, "QUIT\r\n");
|
fputstr(sock, "QUIT\r\n");
|
||||||
fclose(sock);
|
fclose(sock)
|
||||||
|
end
|
||||||
|
else say(chan, nick + ": you are not an admin");
|
||||||
s
|
s
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue