Tweaks to !fallow/!fdeny

- You can now use "-cmds" to group by command rather than user. This is
  useful to, say, check who is allowed to use !revealroles.

- The output is now sorted alphabetically, which should make visual
  navigation much easier.

- The command character is no longer prefixed to the commands, as I feel
  like it's just a waste of space.

- Long messages are now broken properly, using var.break_long_message().
This commit is contained in:
nyuszika7h 2015-06-14 14:45:45 +02:00
parent f3ab9b1512
commit 36d2e6b83e

View File

@ -6354,6 +6354,21 @@ def allow_deny(cli, nick, chan, rest, mode):
modes = ("allow", "deny") modes = ("allow", "deny")
assert mode in modes, "mode not in {!r}".format(modes) assert mode in modes, "mode not in {!r}".format(modes)
opts = defaultdict(bool)
if data and data[0].startswith("-"):
if data[0] == "-cmds":
opts["cmds"] = True
else:
if chan == nick:
pm(cli, nick, "Invalid option: {0}".format(data[0][1:]))
else:
cli.notice(nick, "Invalid option: {0}".format(data[0][1:]))
return
data = data[1:]
if data: if data:
lusers = {k.lower(): v for k, v in var.USERS.items()} lusers = {k.lower(): v for k, v in var.USERS.items()}
user = data[0] user = data[0]
@ -6478,7 +6493,7 @@ def allow_deny(cli, nick, chan, rest, mode):
msg = "\u0002{0}\u0002 (Host: {1}) is no longer {2} commands.".format(data[0], cloak, "allowed any special" if mode == "allow" else "denied any") msg = "\u0002{0}\u0002 (Host: {1}) is no longer {2} commands.".format(data[0], cloak, "allowed any special" if mode == "allow" else "denied any")
else: else:
cmds = {} users_to_cmds = {}
if mode == "allow": if mode == "allow":
variable = var.ALLOW_ACCOUNTS variable = var.ALLOW_ACCOUNTS
else: else:
@ -6486,9 +6501,9 @@ def allow_deny(cli, nick, chan, rest, mode):
if variable: if variable:
for acc, varied in variable.items(): for acc, varied in variable.items():
if var.ACCOUNTS_ONLY: if var.ACCOUNTS_ONLY:
cmds[acc] = varied users_to_cmds[acc] = sorted(varied, key=str.lower)
else: else:
cmds[acc+" (Account)"] = varied users_to_cmds[acc+" (Account)"] = sorted(varied, key=str.lower)
if not var.ACCOUNTS_ONLY: if not var.ACCOUNTS_ONLY:
if mode == "allow": if mode == "allow":
variable = var.ALLOW variable = var.ALLOW
@ -6496,13 +6511,24 @@ def allow_deny(cli, nick, chan, rest, mode):
variable = var.DENY variable = var.DENY
if variable: if variable:
for cloak, varied in variable.items(): for cloak, varied in variable.items():
cmds[cloak+" (Host)"] = varied users_to_cmds[cloak+" (Host)"] = sorted(varied, key=str.lower)
if not cmds: # Deny or Allow list is empty
if not users_to_cmds: # Deny or Allow list is empty
msg = "Nobody is {0} commands.".format("allowed any special" if mode == "allow" else "denied any") msg = "Nobody is {0} commands.".format("allowed any special" if mode == "allow" else "denied any")
else: else:
msg = "{0}: {1}".format("Allowed" if mode == "allow" else "Denied", ", ".join("\u0002{0}\u0002 ({1}{2})".format(user, if opts["cmds"]:
botconfig.CMD_CHAR, ", {0}".format(botconfig.CMD_CHAR).join(cmd)) for user, cmd in cmds.items())) cmds_to_users = defaultdict(list)
for user in sorted(users_to_cmds, key=str.lower):
for cmd in users_to_cmds[user]:
cmds_to_users[cmd].append(user)
msg = "{0}: {1}".format("Allowed" if mode == "allow" else "Denied", "; ".join("\u0002{0}\u0002 ({1})".format(
cmd, ", ".join(users)) for cmd, users in sorted(cmds_to_users.items(), key=lambda t: t[0].lower())))
else:
msg = "{0}: {1}".format("Allowed" if mode == "allow" else "Denied", "; ".join("\u0002{0}\u0002 ({1})".format(
user, ", ".join(cmds)) for user, cmds in sorted(users_to_cmds.items(), key=lambda t: t[0].lower())))
if msg: if msg:
if data: if data:
@ -6513,6 +6539,8 @@ def allow_deny(cli, nick, chan, rest, mode):
# Don't show the cloak/account twice. # Don't show the cloak/account twice.
msg = " ".join((tokens[0], " ".join(tokens[2:]))) msg = " ".join((tokens[0], " ".join(tokens[2:])))
msg = var.break_long_message(msg.split("; "), "; ")
if chan == nick: if chan == nick:
pm(cli, nick, msg) pm(cli, nick, msg)
else: else: