diff --git a/messages/en.json b/messages/en.json index 7aac8b3..d902302 100644 --- a/messages/en.json +++ b/messages/en.json @@ -792,5 +792,6 @@ "maelstrom_dead": "You are dead and cannot join again.", "villagergame_lose": "Game over! The villagers realize too late that there are actually no wolves, and never manage to rebuild to what they had before this fiasco. Nobody wins. (Hint: next time if you suspect there are no wolves, have everyone {0}vote {1}.)", "villagergame_win": "Game over! The villagers come to their senses and realize there are actually no wolves, and live in harmony forevermore. Everybody wins.", - "villagergame_nope": "Game over! The villagers decided incorrectly that there are actually no wolves, allowing the wolves to slaughter the remainder of them in their sleep with impunity." + "villagergame_nope": "Game over! The villagers decided incorrectly that there are actually no wolves, allowing the wolves to slaughter the remainder of them in their sleep with impunity.", + "stop_bot_ingame_safeguard": "Warning: A game is currently running. If you want to {what} the bot anyway, use \"{prefix}{cmd} -force\"." } diff --git a/src/wolfgame.py b/src/wolfgame.py index a4ef31b..67c8014 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -483,11 +483,24 @@ def sync_modes(cli): def forced_exit(cli, nick, chan, rest): """Forces the bot to close.""" + args = rest.split() + + if args and args[0] == "-force": + force = True + rest = " ".join(args[1:]) + else: + force = False + if var.PHASE in var.GAME_PHASES: - try: - stop_game(cli) - except Exception: - traceback.print_exc() + if var.PHASE == "join" or force: + try: + stop_game(cli) + except Exception: + traceback.print_exc() + else: + reply(cli, nick, chan, messages["stop_bot_ingame_safeguard"].format( + what="stop", cmd="fdie", prefix=botconfig.CMD_CHAR), private=True) + return try: reset_modes_timers(cli) @@ -531,11 +544,24 @@ def _restart_program(cli, mode=None): def restart_program(cli, nick, chan, rest): """Restarts the bot.""" + args = rest.split() + + if args and args[0] == "-force": + force = True + rest = " ".join(args[1:]) + else: + force = False + if var.PHASE in var.GAME_PHASES: - try: - stop_game(cli) - except Exception: - traceback.print_exc() + if var.PHASE == "join" or force: + try: + stop_game(cli) + except Exception: + traceback.print_exc() + else: + reply(cli, nick, chan, messages["stop_bot_ingame_safeguard"].format( + what="restart", cmd="frestart", prefix=botconfig.CMD_CHAR), private=True) + return try: reset_modes_timers(cli)