Allow admins and owners tracking via account.

This commit is contained in:
Vgr E.Barry 2014-12-06 15:43:34 -05:00
parent 5cc9715eb1
commit 3192052add
4 changed files with 56 additions and 13 deletions

View File

@ -20,3 +20,6 @@ ALLOWED_NORMAL_MODE_COMMANDS = [] # debug mode commands to be allowed in normal
OWNERS = ("unaffiliated/wolfbot_admin1",) # the comma is required at the end if there is one owner OWNERS = ("unaffiliated/wolfbot_admin1",) # the comma is required at the end if there is one owner
ADMINS = ("unaffiliated/wolfbot_admin2", "unaffiliated/wolfbot_admin3") # glob syntax supported (wildcards) ADMINS = ("unaffiliated/wolfbot_admin2", "unaffiliated/wolfbot_admin3") # glob syntax supported (wildcards)
OWNERS_ACCOUNTS = ("1owner_acc",)
ADMINS_ACCOUNTS = ("1admin_acc", "2admin_acc")

View File

@ -5500,7 +5500,7 @@ def get_help(cli, rnick, rest):
not fn[0].owner_only and name not in fn[0].aliases): not fn[0].owner_only and name not in fn[0].aliases):
fns.append("\u0002"+name+"\u0002") fns.append("\u0002"+name+"\u0002")
afns = [] afns = []
if is_admin(cloak) or cloak in botconfig.OWNERS: # todo - is_owner if is_admin(nick):
for name, fn in COMMANDS.items(): for name, fn in COMMANDS.items():
if fn[0].admin_only and name not in fn[0].aliases: if fn[0].admin_only and name not in fn[0].aliases:
afns.append("\u0002"+name+"\u0002") afns.append("\u0002"+name+"\u0002")
@ -5522,9 +5522,23 @@ def on_invite(cli, nick, something, chan):
cli.join(chan) cli.join(chan)
def is_admin(cloak): def is_admin(nick):
return bool([ptn for ptn in botconfig.OWNERS+botconfig.ADMINS if fnmatch.fnmatch(cloak.lower(), ptn.lower())]) if nick not in var.USERS.keys():
return False
if [ptn for ptn in botconfig.OWNERS+botconfig.ADMINS if fnmatch.fnmatch(var.USERS[nick]["cloak"].lower(), ptn.lower())]:
return True
if [ptn for ptn in botconfig.OWNERS_ACCOUNTS+botconfig.ADMINS_ACCOUNTS if fnmatch.fnmatch(var.USERS[nick]["account"].lower(), ptn.lower())]:
return True
return False
def is_owner(nick):
if nick not in var.USERS.keys():
return False
if [ptn for ptn in botconfig.OWNERS if fnmatch.fnmatch(var.USERS[nick]["cloak"].lower(), ptn.lower())]:
return True
if [ptn for ptn in botconfig.OWNERS_ACCOUNTS if fnmatch.fnmatch(var.USERS[nick]["account"].lower(), ptn.lower())]:
return True
return False
@cmd("admins", "ops") @cmd("admins", "ops")
def show_admins(cli, nick, chan, rest): def show_admins(cli, nick, chan, rest):
@ -5552,7 +5566,7 @@ def show_admins(cli, nick, chan, rest):
if not var.ADMIN_PINGING: if not var.ADMIN_PINGING:
return return
if is_admin(cloak) and "G" not in status and user != botconfig.NICK: if is_admin(user) and "G" not in status and user != botconfig.NICK:
admins.append(user) admins.append(user)
@hook("endofwho", hookid=4) @hook("endofwho", hookid=4)
@ -6097,7 +6111,7 @@ def _say(cli, raw_nick, rest, command, action=False):
(target, message) = rest (target, message) = rest
if not is_admin(host): if not is_admin(nick):
if nick not in var.USERS: if nick not in var.USERS:
pm(cli, nick, "You have to be in {0} to use this command.".format( pm(cli, nick, "You have to be in {0} to use this command.".format(
botconfig.CHANNEL)) botconfig.CHANNEL))
@ -6262,7 +6276,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
did = False did = False
if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only: if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only:
if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.USERS[nick]["cloak"])): not is_admin(nick)):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -6280,7 +6294,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
# chk_nightdone(cli) # chk_nightdone(cli)
elif COMMANDS.get(cmd) and not COMMANDS[cmd][0].owner_only: elif COMMANDS.get(cmd) and not COMMANDS[cmd][0].owner_only:
if (COMMANDS[cmd][0].admin_only and nick in var.USERS and if (COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.USERS[nick]["cloak"])): not is_admin(nick)):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -6319,7 +6333,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1) cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1)
if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only: if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only:
if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.USERS[nick]["cloak"])): not is_admin(nick)):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -6332,7 +6346,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
# chk_nightdone(cli) # chk_nightdone(cli)
elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only: elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only:
if (COMMANDS[cmd][0].admin_only and nick in var.USERS and if (COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.USERS[nick]["cloak"])): not is_admin(nick)):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return

View File

@ -198,9 +198,12 @@ LYNCH_MESSAGES_NO_REVEAL = ("The villagers, after much debate, finally decide on
import botconfig import botconfig
RULES = (botconfig.CHANNEL + " channel rules: http://wolf.xnrand.com/rules") RULES = (botconfig.CHANNEL + " channel rules: http://wolf.xnrand.com/rules")
botconfig.DENY = {} #these are set in here ... for now botconfig.DENY = {} # These are set in here ... for now
botconfig.ALLOW = {} botconfig.ALLOW = {}
botconfig.DENY_ACCOUNTS = {}
botconfig.ALLOW_ACCOUNTS = {}
# Other settings: # Other settings:
OPT_IN_PING = False # instead of !away/!back, users can opt-in to be pinged OPT_IN_PING = False # instead of !away/!back, users can opt-in to be pinged

View File

@ -11,6 +11,7 @@
from oyoyo.parse import parse_nick from oyoyo.parse import parse_nick
import fnmatch import fnmatch
import botconfig import botconfig
import settings.wolfgame as var
def generate(fdict, permissions=True, **kwargs): def generate(fdict, permissions=True, **kwargs):
"""Generates a decorator generator. Always use this""" """Generates a decorator generator. Always use this"""
@ -26,7 +27,10 @@ def generate(fdict, permissions=True, **kwargs):
else: else:
nick = "" nick = ""
cloak = "" cloak = ""
if nick in var.USERS.keys():
acc = var.USERS[nick]["account"]
else:
acc = None
if not raw_nick and len(largs) > 1 and largs[1]: if not raw_nick and len(largs) > 1 and largs[1]:
largs[1] = nick largs[1] = nick
#if largs[1].startswith("#"): #if largs[1].startswith("#"):
@ -44,18 +48,37 @@ def generate(fdict, permissions=True, **kwargs):
for cmdname in s: for cmdname in s:
if cmdname in botconfig.ALLOW[pattern]: if cmdname in botconfig.ALLOW[pattern]:
return f(*largs) # no questions return f(*largs) # no questions
if acc:
for pattern in botconfig.DENY_ACCOUNTS.keys():
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
for cmdname in s:
if cmdname in botconfig.DENY_ACCOUNTS[pattern]:
largs[0].notice(nick, "You do not have permission to use that command.")
return
for pattern in botconfig.ALLOW_ACCOUNTS.keys():
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
for cmdname in s:
if cmdname in botconfig.ALLOW_ACCOUNTS[pattern]:
return f(*largs)
if owner_only: if owner_only:
if cloak and [ptn for ptn in botconfig.OWNERS if cloak and [ptn for ptn in botconfig.OWNERS
if fnmatch.fnmatch(cloak.lower(), ptn.lower())]: if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
return f(*largs) return f(*largs)
elif cloak: elif acc and [ptn for ptn in botconfig.OWNERS_ACCOUNTS
if fnmatch.fnmatch(acc.lower(), ptn.lower())]:
return f(*largs)
else:
largs[0].notice(nick, "You are not the owner.") largs[0].notice(nick, "You are not the owner.")
return return
if admin_only: if admin_only:
if cloak and [ptn for ptn in botconfig.ADMINS+botconfig.OWNERS if cloak and [ptn for ptn in botconfig.ADMINS+botconfig.OWNERS
if fnmatch.fnmatch(cloak.lower(), ptn.lower())]: if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
return f(*largs) return f(*largs)
elif cloak: elif acc and [ptn for ptn in (botconfig.ADMINS_ACCOUNTS+
botconfig.OWNERS_ACCOUNTS) if fnmatch.fnmatch(
acc.lower(), ptn.lower())]:
return f(*largs)
else:
largs[0].notice(nick, "You are not an admin.") largs[0].notice(nick, "You are not an admin.")
return return
return f(*largs) return f(*largs)