From 9723754282f8329c6cc491242e2f3b135a15d8f8 Mon Sep 17 00:00:00 2001 From: raylu Date: Wed, 3 Nov 2010 17:17:46 -0400 Subject: [PATCH] Added listaccess command --- README.md | 3 ++- cmd-access.go | 25 +++++++++++++++++++++++++ handler.go | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86767ad..0b01c35 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The following is a description of the commands enabled by each flag: - `t`: topic appendtopic - `s`: say -In addition, a user must have at least one flag to use `flags` (so users without access can't spam the bot). +In addition, a user must have at least one flag to use `flags` and `list` (so users without access can't spam the bot). ### Commands @@ -45,6 +45,7 @@ Access related commands: - `remove raylu t`: removes the t flag from raylu - `remove raylu`: removes all of raylu's flags - `say text`: says text to the channel +- `list`: lists all users and their access Op commands: diff --git a/cmd-access.go b/cmd-access.go index 104f77c..f5c75c0 100644 --- a/cmd-access.go +++ b/cmd-access.go @@ -77,6 +77,31 @@ func flags(conn *irc.Conn, nick *irc.Nick, args, target string) { } } +func accesslist(conn *irc.Conn, nick *irc.Nick, args, target string) { + channel, args := parseAccess(conn, nick, target, args, "") + if channel == "" { + return + } + + owner, err := auth.String(conn.Network, "owner") + if err != nil { + say(conn, nick.Nick, "%s is the owner", owner) + } + + section := conn.Network + " " + channel + users, err := auth.Options(section) + if err != nil { + say(conn, nick.Nick, "%s: Error while getting users") + return + } + for _, u := range users { + flags, err := auth.String(section, u) + if err == nil { + say(conn, nick.Nick, "%s: %s", u, flags) + } + } +} + func csay(conn *irc.Conn, nick *irc.Nick, args, target string) { channel, args := parseAccess(conn, nick, target, args, "s") if channel != "" { diff --git a/handler.go b/handler.go index 0e8e17b..ea99275 100644 --- a/handler.go +++ b/handler.go @@ -14,6 +14,7 @@ var commands = map [string]func(*irc.Conn, *irc.Nick, string, string) { "flags": flags, "add": add, "remove": remove, + "list": accesslist, "say": csay, // op