Browse Source

takes care of performance bottlenecks in command processing

master
jcao219 14 years ago
parent
commit
24eef701cb
  1. 6
      decorators.py
  2. 4
      wolfgame.py

6
decorators.py

@ -12,7 +12,7 @@ from oyoyo.parse import parse_nick @@ -12,7 +12,7 @@ from oyoyo.parse import parse_nick
import fnmatch
import botconfig
def generate(fdict, **kwargs):
def generate(fdict, permissions=True, **kwargs):
"""Generates a decorator generator. Always use this"""
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, id=-1):
def dec(f):
@ -25,6 +25,8 @@ def generate(fdict, **kwargs): @@ -25,6 +25,8 @@ def generate(fdict, **kwargs):
if not raw_nick and largs[1]:
largs[1] = parse_nick(largs[1])[0] # username
#if largs[1].startswith("#"):
if not permissions or "" in s:
return f(*largs)
if cloak:
for pattern in botconfig.DENY.keys():
if fnmatch.fnmatch(cloak, pattern):
@ -45,7 +47,7 @@ def generate(fdict, **kwargs): @@ -45,7 +47,7 @@ def generate(fdict, **kwargs):
largs[0].notice(largs[1], "You are not the owner.")
return
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)]:
return f(*largs)
elif cloak:

4
wolfgame.py

@ -31,7 +31,7 @@ HOOKS = {} @@ -31,7 +31,7 @@ HOOKS = {}
cmd = decorators.generate(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:
@ -422,8 +422,6 @@ def stats(cli, nick, chan, rest): @@ -422,8 +422,6 @@ def stats(cli, nick, chan, rest):
l2 = [k for k in var.ORIGINAL_ROLES.keys()
if var.ORIGINAL_ROLES[k]]
rs = list(set(l1+l2))
if "village drunk" in rs:
rs.remove("village drunk") # drunk is not displayed
# Due to popular demand, picky ordering
if "wolf" in rs:

Loading…
Cancel
Save