From 8c0582477e8e65375c8b290b440cfd60a0450290 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Wed, 4 Nov 2015 13:16:35 -0500 Subject: [PATCH] Some tweaks to the error handler --- src/decorators.py | 9 ++++++++- src/gamemodes.py | 2 ++ src/wolfgame.py | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/decorators.py b/src/decorators.py index 15ca257..fee4623 100644 --- a/src/decorators.py +++ b/src/decorators.py @@ -20,11 +20,18 @@ HOOKS = defaultdict(list) # Error handler decorators class handle_error: - def __init__(self, func): + def __new__(cls, func): + if isinstance(func, cls): # already decorated + return func + + self = super().__new__(cls) + self.func = func self.instance = None self.owner = object + return self + def __get__(self, instance, owner): self.instance = instance self.owner = owner diff --git a/src/gamemodes.py b/src/gamemodes.py index b87f2d7..c31bf72 100644 --- a/src/gamemodes.py +++ b/src/gamemodes.py @@ -805,6 +805,8 @@ class SleepyMode(GameMode): def setup_nightmares(self, evt, cli, var): if random.random() < 1/5: + from src import decorators + self.do_nightmare = decorators.handle_error(self.do_nightmare) self.having_nightmare = True with var.WARNING_LOCK: t = threading.Timer(60, self.do_nightmare, (cli, var, random.choice(var.list_players()), var.NIGHT_COUNT)) diff --git a/src/wolfgame.py b/src/wolfgame.py index d9858b4..7dac911 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -2076,6 +2076,7 @@ def fday(cli, nick, chan, rest): transition_day(cli) # Specify force = "nick" to force nick to be lynched +@handle_error def chk_decision(cli, force = ""): with var.GRAVEYARD_LOCK: if var.PHASE != "day": @@ -3868,6 +3869,7 @@ def night_warn(cli, gameid): "The night is almost over and there are " + "still whispers heard in the village.\u0002")) +@handle_error def transition_day(cli, gameid=0): if gameid: if gameid != var.NIGHT_ID: @@ -6621,6 +6623,7 @@ def relay(cli, nick, chan, rest): mass_privmsg(cli, [x for x in badguys if x in var.PLAYERS], "\u0002{0}\u0002 says: {1}".format(nick, rest)) +@handle_error def transition_night(cli): if var.PHASE == "night": return