takes care of performance bottlenecks in command processing
This commit is contained in:
parent
65b1123eeb
commit
d86eb56e00
@ -12,7 +12,7 @@ from oyoyo.parse import parse_nick
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import botconfig
|
import botconfig
|
||||||
|
|
||||||
def generate(fdict, **kwargs):
|
def generate(fdict, permissions=True, **kwargs):
|
||||||
"""Generates a decorator generator. Always use this"""
|
"""Generates a decorator generator. Always use this"""
|
||||||
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, id=-1):
|
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, id=-1):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
@ -25,6 +25,8 @@ def generate(fdict, **kwargs):
|
|||||||
if not raw_nick and largs[1]:
|
if not raw_nick and largs[1]:
|
||||||
largs[1] = parse_nick(largs[1])[0] # username
|
largs[1] = parse_nick(largs[1])[0] # username
|
||||||
#if largs[1].startswith("#"):
|
#if largs[1].startswith("#"):
|
||||||
|
if not permissions or "" in s:
|
||||||
|
return f(*largs)
|
||||||
if cloak:
|
if cloak:
|
||||||
for pattern in botconfig.DENY.keys():
|
for pattern in botconfig.DENY.keys():
|
||||||
if fnmatch.fnmatch(cloak, pattern):
|
if fnmatch.fnmatch(cloak, pattern):
|
||||||
@ -45,7 +47,7 @@ def generate(fdict, **kwargs):
|
|||||||
largs[0].notice(largs[1], "You are not the owner.")
|
largs[0].notice(largs[1], "You are not the owner.")
|
||||||
return
|
return
|
||||||
if admin_only:
|
if admin_only:
|
||||||
if cloak and [ptn for ptn in botconfig.OWNERS
|
if cloak and [ptn for ptn in botconfig.ADMINS+botconfig.OWNERS
|
||||||
if fnmatch.fnmatch(cloak, ptn)]:
|
if fnmatch.fnmatch(cloak, ptn)]:
|
||||||
return f(*largs)
|
return f(*largs)
|
||||||
elif cloak:
|
elif cloak:
|
||||||
|
@ -31,7 +31,7 @@ HOOKS = {}
|
|||||||
|
|
||||||
cmd = decorators.generate(COMMANDS)
|
cmd = decorators.generate(COMMANDS)
|
||||||
pmcmd = decorators.generate(PM_COMMANDS)
|
pmcmd = decorators.generate(PM_COMMANDS)
|
||||||
hook = decorators.generate(HOOKS, raw_nick=True)
|
hook = decorators.generate(HOOKS, raw_nick=True, permissions=False)
|
||||||
|
|
||||||
# Game Logic Begins:
|
# Game Logic Begins:
|
||||||
|
|
||||||
@ -422,8 +422,6 @@ def stats(cli, nick, chan, rest):
|
|||||||
l2 = [k for k in var.ORIGINAL_ROLES.keys()
|
l2 = [k for k in var.ORIGINAL_ROLES.keys()
|
||||||
if var.ORIGINAL_ROLES[k]]
|
if var.ORIGINAL_ROLES[k]]
|
||||||
rs = list(set(l1+l2))
|
rs = list(set(l1+l2))
|
||||||
if "village drunk" in rs:
|
|
||||||
rs.remove("village drunk") # drunk is not displayed
|
|
||||||
|
|
||||||
# Due to popular demand, picky ordering
|
# Due to popular demand, picky ordering
|
||||||
if "wolf" in rs:
|
if "wolf" in rs:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user