Browse Source

faftergame, flastgame also improved

master
jcao219 14 years ago
parent
commit
556cc86d4a
  1. 15
      decorators.py
  2. 88
      wolfgame.py

15
decorators.py

@ -19,11 +19,16 @@ def generate(fdict, permissions=True, **kwargs): @@ -19,11 +19,16 @@ def generate(fdict, permissions=True, **kwargs):
def innerf(*args):
largs = list(args)
if len(largs) > 1 and largs[1]:
cloak = parse_nick(largs[1])[3]
nick, _, _, cloak = parse_nick(largs[1])
if cloak is None:
cloak = ""
else:
nick = ""
cloak = ""
if not raw_nick and len(largs) > 1 and largs[1]:
largs[1] = parse_nick(largs[1])[0] # username
largs[1] = nick
#if largs[1].startswith("#"):
if not permissions or "" in s:
return f(*largs)
@ -32,7 +37,7 @@ def generate(fdict, permissions=True, **kwargs): @@ -32,7 +37,7 @@ def generate(fdict, permissions=True, **kwargs):
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
for cmdname in s:
if cmdname in botconfig.DENY[pattern]:
largs[0].notice(largs[1], "You do not have permission to use that command.")
largs[0].notice(nick, "You do not have permission to use that command.")
return
for pattern in botconfig.ALLOW.keys():
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
@ -44,14 +49,14 @@ def generate(fdict, permissions=True, **kwargs): @@ -44,14 +49,14 @@ def generate(fdict, permissions=True, **kwargs):
if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
return f(*largs)
elif cloak:
largs[0].notice(largs[1], "You are not the owner.")
largs[0].notice(nick, "You are not the owner.")
return
if admin_only:
if cloak and [ptn for ptn in botconfig.ADMINS+botconfig.OWNERS
if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
return f(*largs)
elif cloak:
largs[0].notice(largs[1], "You are not an admin.")
largs[0].notice(nick, "You are not an admin.")
return
return f(*largs)
alias = False

88
wolfgame.py

@ -214,6 +214,21 @@ def restart_program(cli, nick, *rest): @@ -214,6 +214,21 @@ def restart_program(cli, nick, *rest):
os.execl(python, python, *sys.argv)
@cmd("frehash", admin_only=True)
def frehash(cli, nick, chan, rest):
if var.PHASE in ("day", "night"):
stop_game(cli)
else:
reset(cli)
imp.reload(botconfig)
imp.reload(var)
imp.reload(decorators.botconfig)
cli.msg(chan, "Operation successful.")
@cmd("ping")
def pinger(cli, nick, chan, rest):
@ -679,12 +694,12 @@ def stop_game(cli, winner = ""): @@ -679,12 +694,12 @@ def stop_game(cli, winner = ""):
reset(cli)
# This must be after reset(cli)
if var.ADMIN_TO_PING:
if var.AFTER_FLASTGAME:
var.AFTER_FLASTGAME()
else:
cli.msg(chan, "PING! " + var.ADMIN_TO_PING)
var.ADMIN_TO_PING = None
if var.AFTER_FLASTGAME:
var.AFTER_FLASTGAME()
var.AFTER_FLASTGAME = None
if var.ADMIN_TO_PING: # It was an flastgame
cli.msg(chan, "PING! " + var.ADMIN_TO_PING)
var.ADMIN_TO_PING = None
return True
@ -2227,6 +2242,50 @@ def coin(cli, nick, chan, rest): @@ -2227,6 +2242,50 @@ def coin(cli, nick, chan, rest):
def aftergame(cli, rawnick, rest):
"""Schedule a command to be run after the game by someone."""
chan = botconfig.CHANNEL
nick = parse_nick(rawnick)[0]
rst = re.split(" +", rest)
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1).strip()
if cmd in PM_COMMANDS.keys():
def do_action():
for fn in PM_COMMANDS[cmd]:
fn(cli, rawnick, " ".join(rst))
elif cmd in COMMANDS.keys():
def do_action():
for fn in COMMANDS[cmd]:
fn(cli, rawnick, botconfig.CHANNEL, " ".join(rst))
else:
cli.notice(nick, "That command was not found.")
return
if var.PHASE == "none":
do_action()
return
cli.msg(chan, ("The command \02{0}\02 has been scheduled to run "+
"after this game by \02{1}\02.").format(cmd, nick))
var.AFTER_FLASTGAME = do_action
@cmd("faftergame", admin_only=True, raw_nick=True)
def _faftergame(cli, nick, chan, rest):
if not rest.strip():
cli.notice(parse_nick(nick)[0], "Incorrect syntax for this command.")
return
aftergame(cli, nick, rest)
@pmcmd("faftergame", admin_only=True, raw_nick=True)
def faftergame(cli, nick, rest):
_faftergame(cli, nick, botconfig.CHANNEL, rest)
@pmcmd("flastgame", admin_only=True, raw_nick=True)
def flastgame(cli, nick, rest):
"""This command may be used in the channel or in a PM, and it disables starting or joining a game. !flastgame <optional-command-after-game-ends>"""
@ -2243,21 +2302,10 @@ def flastgame(cli, nick, rest): @@ -2243,21 +2302,10 @@ def flastgame(cli, nick, rest):
cli.msg(chan, "Starting a new game has now been disabled by \02{0}\02.".format(nick))
var.ADMIN_TO_PING = nick
rst = re.split(" +", rest)
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1).strip()
if cmd in PM_COMMANDS.keys():
def do_action():
for fn in PM_COMMANDS[cmd]:
fn(cli, rawnick, " ".join(rst))
elif cmd.lower() in COMMANDS.keys():
def do_action():
for fn in COMMANDS[cmd]:
fn(cli, rawnick, botconfig.CHANNEL, " ".join(rst))
else:
cli.msg(chan, "That command was not found.")
return
if rest.strip():
aftergame(cli, rawnick, rest)
var.AFTER_FLASTGAME = do_action
@cmd("flastgame", admin_only=True, raw_nick=True)

Loading…
Cancel
Save