Browse Source

fixed several bugs and added nick change monitoring

master
jcao219 14 years ago
parent
commit
f4827b5943
  1. 7
      decorators.py
  2. 14
      oyoyo/client.py
  3. 4
      wolfbot.py
  4. 73
      wolfgame.py

7
decorators.py

@ -1,13 +1,14 @@ @@ -1,13 +1,14 @@
from oyoyo.parse import parse_nick
import botconfig
def generate(fdict):
def generate(fdict, **kwargs):
"""Generates a decorator generator. Always use this"""
def cmd(*s, raw_nick=False, admin_only=False):
def dec(f):
def innerf(*args):
largs = list(args)
if not raw_nick and largs[1]: largs[1] = parse_nick(largs[1])[0]
if not raw_nick and largs[1]:
largs[1] = parse_nick(largs[1])[0]
if admin_only:
if largs[1] and largs[1] in botconfig.ADMINS:
return f(*largs)
@ -21,4 +22,4 @@ def generate(fdict): @@ -21,4 +22,4 @@ def generate(fdict):
return dec
return cmd
return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs)

14
oyoyo/client.py

@ -145,20 +145,20 @@ class IRCClient(object): @@ -145,20 +145,20 @@ class IRCClient(object):
for el in data:
prefix, command, args = parse_raw_irc_command(el)
logging.debug("processCommand {0}({1})".format(command,
logging.debug("processCommand ({2}){0}({1})".format(command,
[arg.decode('utf_8')
for arg in args
if isinstance(arg, bytes)]))
if isinstance(arg, bytes)], prefix))
try:
largs = list(args)
if prefix:
largs.insert(0, prefix)
if prefix is not None:
prefix = prefix.decode("utf-8")
for i,arg in enumerate(largs):
if arg: largs[i] = arg.decode('utf_8')
if arg is not None: largs[i] = arg.decode('utf_8')
if command in self.command_handler:
self.command_handler[command](self, *largs)
self.command_handler[command](self, prefix,*largs)
elif "" in self.command_handler:
self.command_handler[""](self, command, *largs)
self.command_handler[""](self, prefix, command, *largs)
finally:
# error will of already been logged by the handler
pass

4
wolfbot.py

@ -18,12 +18,12 @@ def on_privmsg(cli, rawnick, chan, msg): @@ -18,12 +18,12 @@ def on_privmsg(cli, rawnick, chan, msg):
if not h or h[0] == " " or not x:
wolfgame.PM_COMMANDS[x](cli, rawnick, h.lstrip())
def __unhandled__(cli, cmd, *args):
def __unhandled__(cli, prefix, cmd, *args):
if cmd in wolfgame.HOOKS.keys():
largs = list(args)
for i,arg in enumerate(largs):
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
wolfgame.HOOKS[cmd](cli, *largs)
wolfgame.HOOKS[cmd](cli, prefix, *largs)
else:
logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8')
for arg in args

73
wolfgame.py

@ -16,7 +16,7 @@ HOOKS = {} @@ -16,7 +16,7 @@ HOOKS = {}
cmd = decorators.generate(COMMANDS)
pmcmd = decorators.generate(PM_COMMANDS)
hook = decorators.generate(HOOKS)
hook = decorators.generate(HOOKS, raw_nick=True)
# Game Logic Begins:
@ -229,18 +229,20 @@ def stats(cli, nick, chan, rest): @@ -229,18 +229,20 @@ def stats(cli, nick, chan, rest):
return
message = []
for role in var.ORIGINAL_ROLES.keys():
if not var.ORIGINAL_ROLES[role]:
f = False
for role in var.ROLES.keys():
if not var.ROLES[role]:
continue # Never had this role, don't list it.
count = len(var.ROLES[role])
if count > 1 or count == 0:
message.append("\u0002{0}\u0002 {1}".format(count, var.plural(role)))
else:
message.append("\u0002{0}\u0002 {1}".format(count, role))
if len(var.ROLES["wolf"]) > 1 or not var.ROLES["wolf"]:
if not f:
if count>1:
vb = "are"
else:
vb = "is"
if count > 1 or count == 0:
message.append("\u0002{0}\u0002 {1}".format(count if count else "no", var.plural(role)))
else:
message.append("\u0002{0}\u0002 {1}".format(count if count else "no", role))
cli.msg(chan, "{0}: There {3} {1}, and {2}.".format(nick,
", ".join(message[0:-1]),
message[-1],
@ -431,6 +433,10 @@ def del_player(cli, nick, forced_death = False): @@ -431,6 +433,10 @@ def del_player(cli, nick, forced_death = False):
del x[k]
elif x[k] == nick:
del x[k]
if nick in var.GUNNERS.keys():
del var.GUNNERS[nick]
if nick in var.CURSED:
var.CURSED.remove(nick)
if var.PHASE == "day" and not forced_death and ret: # didn't die from lynching
if nick in var.VOTES.keys():
del var.VOTES[nick] # Delete his votes
@ -442,9 +448,52 @@ def del_player(cli, nick, forced_death = False): @@ -442,9 +448,52 @@ def del_player(cli, nick, forced_death = False):
@hook("ping")
def on_ping(cli, server):
def on_ping(cli, prefix, server):
cli.send('PONG', server)
@hook("nick")
def on_nick(cli, prefix, nick):
prefix = parse_nick(prefix)[0]
if prefix in var.list_players():
r = var.ROLES[var.get_role(prefix)]
r.append(nick)
r.remove(prefix)
if var.PHASE in ("night", "day"):
if var.VICTIM == prefix:
var.VICTIM = nick
kvp = []
for dictvar in (var.HVISITED, var.OBSERVED):
for a,b in dictvar.items():
if a == prefix:
a = nick
if b == prefix:
b = nick
kvp.append((a,b))
dictvar.update(kvp)
if prefix in dictvar.keys():
del dictvar[prefix]
if prefix in var.SEEN:
var.SEEN.remove(prefix)
var.SEEN.append(nick)
if nick in var.GUNNERS.keys():
del var.GUNNERS[nick]
if nick in var.CURSED:
var.CURSED.remove(nick)
if var.PHASE == "day":
if prefix in var.WOUNDED:
var.WOUNDED.remove(prefix)
var.WOUNDED.append(nick)
if prefix in var.VOTES:
var.VOTES[nick] = var.VOTES.pop(prefix)
for v in var.VOTES.values():
if prefix in v:
v.remove(prefix)
v.append(nick)
else:
return
def leave(cli, what, nick):
if var.PHASE == "none" and what.startswith("!"):
@ -476,9 +525,9 @@ def leave(cli, what, nick): @@ -476,9 +525,9 @@ def leave(cli, what, nick):
cmd("!leave")(lambda cli, nick, *rest: leave(cli, "!leave", nick))
cmd("!quit")(lambda cli, nick, *rest: leave(cli, "!quit", nick))
hook("part")(lambda cli, nick, *rest: leave(cli, "part", nick))
hook("quit")(lambda cli, nick, *rest: leave(cli, "quit", nick))
hook("kick")(lambda cli, nick, *rest: leave(cli, "kick", nick))
hook("part")(lambda cli, prefix, nick, *rest: leave(cli, "part", nick))
hook("quit")(lambda cli, prefix, nick, *rest: leave(cli, "quit", nick))
hook("kick")(lambda cli, prefix, nick, *rest: leave(cli, "kick", nick))

Loading…
Cancel
Save