Browse Source

fixed bugs introduced by the last commit

master
jcao219 14 years ago
parent
commit
76ad219e87
  1. 10
      decorators.py
  2. 9
      wolfbot.py
  3. 38
      wolfgame.py

10
decorators.py

@ -28,7 +28,15 @@ def generate(fdict, **kwargs):
return return
return f(*largs) return f(*largs)
for x in s: for x in s:
fdict[x] = innerf if x not in fdict.keys():
fdict[x] = []
else:
for fn in fdict[x]:
if (fn.owner_only != owner_only or
fn.admin_only != admin_only):
raise Exception("Command: "+x+" has non-matching protection levels!")
fdict[x].append(innerf)
innerf.owner_only = owner_only innerf.owner_only = owner_only
innerf.raw_nick = raw_nick innerf.raw_nick = raw_nick
innerf.admin_only = admin_only innerf.admin_only = admin_only

9
wolfbot.py

@ -10,7 +10,8 @@ def on_privmsg(cli, rawnick, chan, msg):
if not x or msg.lower().startswith(botconfig.CMD_CHAR+x): if not x or msg.lower().startswith(botconfig.CMD_CHAR+x):
h = msg[len(x)+1:] h = msg[len(x)+1:]
if not h or h[0] == " " or not x: if not h or h[0] == " " or not x:
wolfgame.COMMANDS[x](cli, rawnick, chan, h.lstrip()) for fn in wolfgame.COMMANDS[x]:
fn(cli, rawnick, chan, h.lstrip())
else: else:
for x in wolfgame.PM_COMMANDS.keys(): for x in wolfgame.PM_COMMANDS.keys():
if msg.lower().startswith(botconfig.CMD_CHAR+x): if msg.lower().startswith(botconfig.CMD_CHAR+x):
@ -20,14 +21,16 @@ def on_privmsg(cli, rawnick, chan, msg):
else: else:
continue continue
if not h or h[0] == " " or not x: if not h or h[0] == " " or not x:
wolfgame.PM_COMMANDS[x](cli, rawnick, h.lstrip()) for fn in wolfgame.PM_COMMANDS[x]:
fn(cli, rawnick, h.lstrip())
def __unhandled__(cli, prefix, cmd, *args): def __unhandled__(cli, prefix, cmd, *args):
if cmd in wolfgame.HOOKS.keys(): if cmd in wolfgame.HOOKS.keys():
largs = list(args) largs = list(args)
for i,arg in enumerate(largs): for i,arg in enumerate(largs):
if isinstance(arg, bytes): largs[i] = arg.decode('ascii') if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
wolfgame.HOOKS[cmd](cli, prefix, *largs) for fn in wolfgame.HOOKS[cmd]:
fn(cli, prefix, *largs)
else: else:
logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8') logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8')
for arg in args for arg in args

38
wolfgame.py

@ -307,11 +307,15 @@ def fleave(cli, nick, chan, rest):
elif a.lower() not in pll: elif a.lower() not in pll:
cli.msg(chan, nick+": That could not be done.") cli.msg(chan, nick+": That could not be done.")
@cmd("fstart", admin_only=True) @cmd("fstart", admin_only=True)
def fstart(cli, nick, chan, rest): def fstart(cli, nick, chan, rest):
var.CAN_START_TIME = datetime.now() var.CAN_START_TIME = datetime.now()
start(cli, nick, chan, rest) start(cli, nick, chan, rest)
@cmd("chankick", admin_only=True) @cmd("chankick", admin_only=True)
def chankick(cli, nick, chan, rest): def chankick(cli, nick, chan, rest):
rest = rest.split(" ", 1) rest = rest.split(" ", 1)
@ -320,12 +324,16 @@ def chankick(cli, nick, chan, rest):
else: else:
cli.kick(chan, nick, "No.") cli.kick(chan, nick, "No.")
@hook("kick") @hook("kick")
def on_kicked(cli, nick, chan, victim, reason): def on_kicked(cli, nick, chan, victim, reason):
if victim == botconfig.NICK: if victim == botconfig.NICK:
cli.join(botconfig.CHANNEL) cli.join(botconfig.CHANNEL)
cli.kick(chan, nick, "No.") cli.msg("ChanServ", "op "+botconfig.CHANNEL)
# cli.kick(chan, nick, "No.")
@cmd("stats") @cmd("stats")
def stats(cli, nick, chan, rest): def stats(cli, nick, chan, rest):
@ -669,6 +677,8 @@ def on_join(cli, raw_nick, chan):
nick = parse_nick(raw_nick)[0] nick = parse_nick(raw_nick)[0]
if nick not in var.USERS and nick != botconfig.NICK: if nick not in var.USERS and nick != botconfig.NICK:
var.USERS.append(nick) var.USERS.append(nick)
#if nick in var.list_players():
# cli.mode(chan, "+v", nick, nick+"!*@*") needed?
@cmd("goat") @cmd("goat")
def goat(cli, nick, chan, rest): def goat(cli, nick, chan, rest):
@ -749,7 +759,7 @@ def on_nick(cli, prefix, nick):
def leave(cli, what, nick, why=""): def leave(cli, what, nick, why=""):
if why == botconfig.CHANGING_HOST_QUIT_MESSAGE: if why and why == botconfig.CHANGING_HOST_QUIT_MESSAGE:
return return
if var.PHASE == "none" and what.startswith(botconfig.CMD_CHAR): if var.PHASE == "none" and what.startswith(botconfig.CMD_CHAR):
cli.notice(nick, "No game is currently running.") cli.notice(nick, "No game is currently running.")
@ -1315,17 +1325,19 @@ def forcepm(cli, nick, chan, rest):
cli.msg(chan, "That won't work.") cli.msg(chan, "That won't work.")
return return
if not is_fake_nick(who): if not is_fake_nick(who):
if who not in var.USERS: if who not in var.USERS:
cli.msg(chan, "This can only be done on fake nicks.") cli.msg(chan, "This can only be done on fake nicks.")
return return
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1) cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1)
if cmd in PM_COMMANDS.keys() and not PM_COMMANDS[cmd].owner_only: if cmd in PM_COMMANDS.keys() and not PM_COMMANDS[cmd][0].owner_only:
PM_COMMANDS[cmd](cli, who, " ".join(rst)) for fn in PM_COMMANDS[cmd]:
fn(cli, who, " ".join(rst))
cli.msg(chan, "Operation successful.") cli.msg(chan, "Operation successful.")
#if var.PHASE == "night": <- Causes problems with night starting twice. #if var.PHASE == "night": <- Causes problems with night starting twice.
# chk_nightdone(cli) # chk_nightdone(cli)
elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd].owner_only: elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only:
COMMANDS[cmd](cli, who, chan, " ".join(rst)) for fn in COMMANDS[cmd]:
fn(cli, who, chan, " ".join(rst))
cli.msg(chan, "Operation successful.") cli.msg(chan, "Operation successful.")
else: else:
cli.msg(chan, "That command was not found.") cli.msg(chan, "That command was not found.")
@ -1496,6 +1508,8 @@ def transition_night(cli):
"check for PMs from me for instructions. "+ "check for PMs from me for instructions. "+
"If you did not receive one, simply sit back, "+ "If you did not receive one, simply sit back, "+
"relax, and wait patiently for morning.")) "relax, and wait patiently for morning."))
cli.msg(chan, "DEBUG: "+str(var.ROLES))
if not var.ROLES["wolf"]: # Probably something interesting going on. if not var.ROLES["wolf"]: # Probably something interesting going on.
chk_nightdone(cli) chk_nightdone(cli)
chk_traitor(cli) chk_traitor(cli)
@ -1762,12 +1776,12 @@ def help(cli, rnick, chan, rest):
nick, mode, user, cloak = parse_nick(rnick) nick, mode, user, cloak = parse_nick(rnick)
fns = [] fns = []
for name, fn in COMMANDS.items(): for name, fn in COMMANDS.items():
if name and not fn.admin_only and not fn.owner_only: if name and not fn[0].admin_only and not fn[0].owner_only:
fns.append("\u0002"+name+"\u0002") fns.append("\u0002"+name+"\u0002")
afns = [] afns = []
if cloak in botconfig.ADMINS: if cloak in botconfig.ADMINS:
for name, fn in COMMANDS.items(): for name, fn in COMMANDS.items():
if fn.admin_only: if fn[0].admin_only:
afns.append("\u0002"+name+"\u0002") afns.append("\u0002"+name+"\u0002")
cli.notice(nick, "Commands: "+", ".join(fns)) cli.notice(nick, "Commands: "+", ".join(fns))
if afns: if afns:

Loading…
Cancel
Save