diff --git a/wolfbot.py b/wolfbot.py index 9b5d3a8..bdfc11c 100644 --- a/wolfbot.py +++ b/wolfbot.py @@ -24,6 +24,7 @@ from oyoyo.parse import parse_nick import logging import botconfig import wolfgame +import traceback def on_privmsg(cli, rawnick, chan, msg): if chan != botconfig.NICK: #not a PM @@ -32,7 +33,14 @@ def on_privmsg(cli, rawnick, chan, msg): h = msg[len(x)+1:] if not h or h[0] == " " or not x: for fn in wolfgame.COMMANDS[x]: - fn(cli, rawnick, chan, h.lstrip()) + try: + fn(cli, rawnick, chan, h.lstrip()) + except Exception as e: + if botconfig.DEBUG_MODE: + raise e + else: + traceback.print_exc() + cli.msg(chan, "An error has occurred.") else: for x in wolfgame.PM_COMMANDS.keys(): if msg.lower().startswith(botconfig.CMD_CHAR+x): @@ -43,7 +51,14 @@ def on_privmsg(cli, rawnick, chan, msg): continue if not h or h[0] == " " or not x: for fn in wolfgame.PM_COMMANDS[x]: - fn(cli, rawnick, h.lstrip()) + try: + fn(cli, rawnick, h.lstrip()) + except Exception as e: + if botconfig.DEBUG_MODE: + raise e + else: + traceback.print_exc() + cli.msg(chan, "An error has occurred.") def __unhandled__(cli, prefix, cmd, *args): if cmd in wolfgame.HOOKS.keys(): @@ -58,7 +73,10 @@ def __unhandled__(cli, prefix, cmd, *args): if isinstance(arg, bytes)])) def main(): - logging.basicConfig(level=logging.WARNING) + if not botconfig.DEBUG_MODE: + logging.basicConfig(level=logging.WARNING) + else: + logging.basicConfig(level=logging.INFO) cli = IRCClient( {"privmsg":on_privmsg, "":__unhandled__}, diff --git a/wolfgame.py b/wolfgame.py index b5b8b5b..4eedb2f 100644 --- a/wolfgame.py +++ b/wolfgame.py @@ -83,6 +83,12 @@ def connect_callback(cli): var.GAME_START_TIME = datetime.now() # for idle checker only var.GRAVEYARD_LOCK = threading.RLock() var.GAME_ID = 0 + + if botconfig.DEBUG_MODE: + NIGHT_TIME_LIMIT = 0 # 90 + DAY_TIME_LIMIT = 0 + KILL_IDLE_TIME = 0 #300 + WARN_IDLE_TIME = 0 #180 prepare_stuff() @@ -360,7 +366,7 @@ def fleave(cli, nick, chan, rest): def fstart(cli, nick, chan, rest): var.CAN_START_TIME = datetime.now() cli.msg(chan, "\u0002{0}\u0002 has forced the game to start.".format(nick)) - start(cli, chan, chan, rest) + start(cli, nick, nick, rest) @@ -1821,14 +1827,24 @@ def fwait(cli, nick, chan, rest): cli.notice(nick, "Werewolf is already in play.") return + rest = rest.strip() + if rest and rest.isdigit(): + if len(rest) < 4: + extra = int(rest) + else: + cli.msg(chan, "{0}: We don't have all day!".format(nick)) + return + else: + extra = var.EXTRA_WAIT + now = datetime.now() if now > var.CAN_START_TIME: - var.CAN_START_TIME = now + timedelta(seconds=var.EXTRA_WAIT) + var.CAN_START_TIME = now + timedelta(seconds=extra) else: - var.CAN_START_TIME += timedelta(seconds=var.EXTRA_WAIT) + var.CAN_START_TIME += timedelta(seconds=extra) var.WAITED += 1 cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+ - "{1} seconds.").format(nick, var.EXTRA_WAIT)) + "{1} seconds.").format(nick, extra)) @cmd("fstop",admin_only=True) @@ -1837,7 +1853,10 @@ def reset_game(cli, nick, chan, rest): cli.notice(nick, "No game is currently running.") return cli.msg(chan, "\u0002{0}\u0002 has forced the game to stop.".format(nick)) - stop_game(cli) + if var.PHASE != "join": + stop_game(cli) + else: + reset(cli) @pmcmd("rules") @@ -1864,7 +1883,7 @@ def help(cli, rnick, rest): found = True for fn in c[cname]: if fn.__doc__: - cli.msg(nick, fn.__doc__) + cli.msg(nick, botconfig.CMD_CHAR+cname+": "+fn.__doc__) return else: continue @@ -1982,6 +2001,7 @@ if botconfig.DEBUG_MODE: rst = re.split(" +",rest) if len(rst) < 2: cli.msg(chan, "The syntax is incorrect.") + return who = rst.pop(0).strip() rol = " ".join(rst).strip() ull = [u.lower() for u in var.USERS]