better error handling
This commit is contained in:
parent
e55335441c
commit
f4bf25df10
1
var.py
1
var.py
@ -14,6 +14,7 @@ DAY_TIME_LIMIT_CHANGE = 120 # After DAY_TIME_LIMIT_WARN has passed
|
|||||||
START_WITH_DAY = False
|
START_WITH_DAY = False
|
||||||
KILL_IDLE_TIME = 300
|
KILL_IDLE_TIME = 300
|
||||||
WARN_IDLE_TIME = 180
|
WARN_IDLE_TIME = 180
|
||||||
|
|
||||||
LOG_FILENAME = ""
|
LOG_FILENAME = ""
|
||||||
BARE_LOG_FILENAME = "barelog.txt"
|
BARE_LOG_FILENAME = "barelog.txt"
|
||||||
|
|
||||||
|
18
wolfbot.py
18
wolfbot.py
@ -30,7 +30,14 @@ def on_privmsg(cli, rawnick, chan, msg):
|
|||||||
if chan != botconfig.NICK: #not a PM
|
if chan != botconfig.NICK: #not a PM
|
||||||
if "" in wolfgame.COMMANDS.keys():
|
if "" in wolfgame.COMMANDS.keys():
|
||||||
for fn in wolfgame.COMMANDS[""]:
|
for fn in wolfgame.COMMANDS[""]:
|
||||||
fn(cli, rawnick, chan, msg)
|
try:
|
||||||
|
fn(cli, rawnick, chan, msg)
|
||||||
|
except Exception as e:
|
||||||
|
if botconfig.DEBUG_MODE:
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
cli.msg(chan, "An error has occurred and has been logged.")
|
||||||
# Now that is always called first.
|
# Now that is always called first.
|
||||||
for x in wolfgame.COMMANDS.keys():
|
for x in wolfgame.COMMANDS.keys():
|
||||||
if x and msg.lower().startswith(botconfig.CMD_CHAR+x):
|
if x and msg.lower().startswith(botconfig.CMD_CHAR+x):
|
||||||
@ -70,7 +77,14 @@ def __unhandled__(cli, prefix, cmd, *args):
|
|||||||
for i,arg in enumerate(largs):
|
for i,arg in enumerate(largs):
|
||||||
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
||||||
for fn in wolfgame.HOOKS[cmd]:
|
for fn in wolfgame.HOOKS[cmd]:
|
||||||
fn(cli, prefix, *largs)
|
try:
|
||||||
|
fn(cli, prefix, *largs)
|
||||||
|
except Exception as e:
|
||||||
|
if botconfig.DEBUG_MODE:
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
cli.msg(botconfig.CHANNEL, "An error has occured and has been logged.")
|
||||||
else:
|
else:
|
||||||
logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8')
|
logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8')
|
||||||
for arg in args
|
for arg in args
|
||||||
|
81
wolfgame.py
81
wolfgame.py
@ -991,8 +991,6 @@ def on_nick(cli, prefix, nick):
|
|||||||
if prefix in v:
|
if prefix in v:
|
||||||
v.remove(prefix)
|
v.remove(prefix)
|
||||||
v.append(nick)
|
v.append(nick)
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def leave(cli, what, nick, why=""):
|
def leave(cli, what, nick, why=""):
|
||||||
@ -1344,8 +1342,14 @@ def shoot(cli, nick, chan, rest):
|
|||||||
return
|
return
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
pll = [x.lower() for x in pl]
|
pll = [x.lower() for x in pl]
|
||||||
if victim not in pll:
|
for player in pll:
|
||||||
cli.notice(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
victim = pl[pll.index(victim)]
|
victim = pl[pll.index(victim)]
|
||||||
if victim == nick:
|
if victim == nick:
|
||||||
@ -1441,19 +1445,26 @@ def kill(cli, nick, rest):
|
|||||||
return
|
return
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
pll = [x.lower() for x in pl]
|
pll = [x.lower() for x in pl]
|
||||||
if victim not in pll:
|
|
||||||
|
for player in pll:
|
||||||
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
victim = pl[pll.index(victim)]
|
|
||||||
if victim == nick:
|
if victim == nick.lower():
|
||||||
cli.msg(nick, "Suicide is bad. Don't do it.")
|
cli.msg(nick, "Suicide is bad. Don't do it.")
|
||||||
return
|
return
|
||||||
if victim in var.ROLES["wolf"]+var.ROLES["werecrow"]:
|
if victim in var.ROLES["wolf"]+var.ROLES["werecrow"]:
|
||||||
cli.msg(nick, "You may only kill villagers, not other wolves")
|
cli.msg(nick, "You may only kill villagers, not other wolves.")
|
||||||
return
|
return
|
||||||
var.KILLS[nick] = victim
|
var.KILLS[nick] = pl[pll.index(victim)]
|
||||||
cli.msg(nick, "You have selected \u0002{0}\u0002 to be killed.".format(victim))
|
cli.msg(nick, "You have selected \u0002{0}\u0002 to be killed.".format(pl[pll.index(victim)]))
|
||||||
var.LOGGER.logBare(nick, "SELECT", victim)
|
var.LOGGER.logBare(nick, "SELECT", pl[pll.index(victim)])
|
||||||
var.ACTED_WOLVES.add(nick)
|
var.ACTED_WOLVES.add(nick)
|
||||||
chk_nightdone(cli)
|
chk_nightdone(cli)
|
||||||
|
|
||||||
@ -1483,7 +1494,13 @@ def guard(cli, nick, rest):
|
|||||||
return
|
return
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
pll = [x.lower() for x in pl]
|
pll = [x.lower() for x in pl]
|
||||||
if victim not in pll:
|
for player in pll:
|
||||||
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
if victim == nick.lower():
|
if victim == nick.lower():
|
||||||
@ -1517,8 +1534,14 @@ def observe(cli, nick, rest):
|
|||||||
return
|
return
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
pll = [x.lower() for x in pl]
|
pll = [x.lower() for x in pl]
|
||||||
if victim not in pll:
|
for player in pll:
|
||||||
cli.msg(nick, "\u0002{0}\u0002 is currently not playing.".format(victim))
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
victim = pl[pll.index(victim)]
|
victim = pl[pll.index(victim)]
|
||||||
if victim == nick.lower():
|
if victim == nick.lower():
|
||||||
@ -1561,8 +1584,14 @@ def investigate(cli, nick, rest):
|
|||||||
return
|
return
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
pll = [x.lower() for x in pl]
|
pll = [x.lower() for x in pl]
|
||||||
if victim not in pll:
|
for player in pll:
|
||||||
cli.msg(nick, "\u0002{0}\u0002 is currently not playing.".format(victim))
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
victim = pl[pll.index(victim)]
|
victim = pl[pll.index(victim)]
|
||||||
|
|
||||||
@ -1601,15 +1630,21 @@ def hvisit(cli, nick, rest):
|
|||||||
if not victim:
|
if not victim:
|
||||||
cli.msg(nick, "Not enough parameters")
|
cli.msg(nick, "Not enough parameters")
|
||||||
return
|
return
|
||||||
pl = [x.lower() for x in var.list_players()]
|
pll = [x.lower() for x in var.list_players()]
|
||||||
if victim not in pl:
|
for player in pll:
|
||||||
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
if nick.lower() == victim: # Staying home
|
if nick.lower() == victim: # Staying home
|
||||||
var.HVISITED[nick] = None
|
var.HVISITED[nick] = None
|
||||||
cli.msg(nick, "You have chosen to stay home for the night.")
|
cli.msg(nick, "You have chosen to stay home for the night.")
|
||||||
else:
|
else:
|
||||||
var.HVISITED[nick] = var.list_players()[pl.index(victim)]
|
var.HVISITED[nick] = var.list_players()[pll.index(victim)]
|
||||||
cli.msg(nick, ("You are spending the night with \u0002{0}\u0002. "+
|
cli.msg(nick, ("You are spending the night with \u0002{0}\u0002. "+
|
||||||
"Have a good time!").format(var.HVISITED[nick]))
|
"Have a good time!").format(var.HVISITED[nick]))
|
||||||
cli.msg(var.HVISITED[nick], ("You are spending the night with \u0002{0}"+
|
cli.msg(var.HVISITED[nick], ("You are spending the night with \u0002{0}"+
|
||||||
@ -1647,7 +1682,13 @@ def see(cli, nick, rest):
|
|||||||
if not victim:
|
if not victim:
|
||||||
cli.msg(nick, "Not enough parameters")
|
cli.msg(nick, "Not enough parameters")
|
||||||
return
|
return
|
||||||
if victim not in pll:
|
for player in pll:
|
||||||
|
if victim == player:
|
||||||
|
break
|
||||||
|
if player.startswith(victim):
|
||||||
|
victim = player
|
||||||
|
break
|
||||||
|
else:
|
||||||
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
cli.msg(nick,"\u0002{0}\u0002 is currently not playing.".format(victim))
|
||||||
return
|
return
|
||||||
victim = pl[pll.index(victim)]
|
victim = pl[pll.index(victim)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user