Add a safeguard to !fdie and !frestart when a game is running

This commit is contained in:
nyuszika7h 2016-04-19 16:16:59 +02:00
parent 4ecfead19e
commit 1f0a1e1303
2 changed files with 36 additions and 9 deletions

View File

@ -792,5 +792,6 @@
"maelstrom_dead": "You are dead and cannot join again.", "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_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_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\"."
} }

View File

@ -483,11 +483,24 @@ def sync_modes(cli):
def forced_exit(cli, nick, chan, rest): def forced_exit(cli, nick, chan, rest):
"""Forces the bot to close.""" """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: if var.PHASE in var.GAME_PHASES:
try: if var.PHASE == "join" or force:
stop_game(cli) try:
except Exception: stop_game(cli)
traceback.print_exc() 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: try:
reset_modes_timers(cli) reset_modes_timers(cli)
@ -531,11 +544,24 @@ def _restart_program(cli, mode=None):
def restart_program(cli, nick, chan, rest): def restart_program(cli, nick, chan, rest):
"""Restarts the bot.""" """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: if var.PHASE in var.GAME_PHASES:
try: if var.PHASE == "join" or force:
stop_game(cli) try:
except Exception: stop_game(cli)
traceback.print_exc() 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: try:
reset_modes_timers(cli) reset_modes_timers(cli)