From 7fb6b6eb80592d3c0bce67524deb48a89bf4d643 Mon Sep 17 00:00:00 2001 From: Jimmy Cao Date: Sun, 26 Feb 2012 18:07:36 -0600 Subject: [PATCH] cleanup of fgame --- modules/wolfgame.py | 34 +++++++++++++++++++++++----------- settings/wolfgame.py | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/wolfgame.py b/modules/wolfgame.py index 78dac6c..0dbc0c8 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -94,7 +94,6 @@ def connect_callback(cli): var.DEAD = [] var.ORIGINAL_SETTINGS = {} - var.SETTINGS_CHANGE_REQUESTER = None var.LAST_SAID_TIME = {} @@ -138,8 +137,6 @@ def reset_settings(): setattr(var, attr, var.ORIGINAL_SETTINGS[attr]) dict.clear(var.ORIGINAL_SETTINGS) - var.SETTINGS_CHANGE_REQUESTER = None - def reset(cli): chan = botconfig.CHANNEL @@ -2069,6 +2066,9 @@ def transition_night(cli): def cgamemode(cli, *args): chan = botconfig.CHANNEL + if var.ORIGINAL_SETTINGS: # needs reset + reset_settings() + for arg in args: modeargs = arg.split("=", 1) modeargs[0] = modeargs[0].strip() @@ -2359,7 +2359,10 @@ def get_help(cli, rnick, rest): nick, mode, user, cloak = parse_nick(rnick) fns = [] - cname = rest.strip().replace(botconfig.CMD_CHAR, "").lower() + rest = rest.strip().replace(botconfig.CMD_CHAR, "", 1).lower() + splitted = re.split(" +", rest, 1) + cname = splitted.pop(0) + rest = splitted[0] if splitted else "" found = False if cname: for c in (COMMANDS,PM_COMMANDS): @@ -2368,8 +2371,11 @@ def get_help(cli, rnick, rest): for fn in c[cname]: if fn.__doc__: if nick == botconfig.CHANNEL: - var.LOGGER.logMessage(botconfig.CMD_CHAR+cname+": "+fn.__doc__) - cli.msg(nick, botconfig.CMD_CHAR+cname+": "+fn.__doc__) + var.LOGGER.logMessage(botconfig.CMD_CHAR+cname+": "+fn.__doc__(rest)) + if callable(fn.__doc__): + cli.msg(nick, botconfig.CMD_CHAR+cname+": "+fn.__doc__(rest)) + else: + cli.msg(nick, botconfig.CMD_CHAR+cname+": "+fn.__doc__) return else: continue @@ -2594,16 +2600,22 @@ if botconfig.DEBUG_MODE: if nick not in pl: cli.notice(nick, "You're currently not playing.") return - if var.SETTINGS_CHANGE_REQUESTER: - cli.notice(nick, "There is already an existing "+ - "settings change request.") - return rest = rest.strip().lower() if rest: if cgamemode(cli, *re.split(" +",rest)): - var.SETTINGS_CHANGE_REQUESTER = nick cli.msg(chan, ("\u0002{0}\u0002 has changed the "+ "game settings successfully.").format(nick)) + + def fgame_help(args = ""): + args = args.strip() + if not args: + return "Available game mode setters: "+ ", ".join(var.GAME_MODES.keys()) + elif args in var.GAME_MODES.keys(): + return var.GAME_MODES[args].__doc__ + else: + return "Game mode setter {0} not found.".format(args) + + game.__doc__ = fgame_help # DO NOT MAKE THIS A PMCOMMAND ALSO diff --git a/settings/wolfgame.py b/settings/wolfgame.py index ead0160..9169192 100644 --- a/settings/wolfgame.py +++ b/settings/wolfgame.py @@ -135,7 +135,7 @@ class Normal(object): # TODO: implement game modes @game_mode("roles") class ChangedRolesMode(object): - """Example: !game roles=wolves:1,seers:0,angels:1""" + """Example: !fgame roles=wolves:1,seers:0,angels:1""" def __init__(self, arg): self.ROLES_GUIDE = ROLES_GUIDE.copy()