Some tweaks to the error handler
This commit is contained in:
parent
b28d4bf6e3
commit
8c0582477e
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user