made debug mode better, now there are no time limits in debug mode, and !fwait now accepts a parameter, and !fstop doesn't crash the bot if used in the joining phase
This commit is contained in:
parent
dc51b7fb51
commit
0b889d5933
24
wolfbot.py
24
wolfbot.py
@ -24,6 +24,7 @@ from oyoyo.parse import parse_nick
|
|||||||
import logging
|
import logging
|
||||||
import botconfig
|
import botconfig
|
||||||
import wolfgame
|
import wolfgame
|
||||||
|
import traceback
|
||||||
|
|
||||||
def on_privmsg(cli, rawnick, chan, msg):
|
def on_privmsg(cli, rawnick, chan, msg):
|
||||||
if chan != botconfig.NICK: #not a PM
|
if chan != botconfig.NICK: #not a PM
|
||||||
@ -32,7 +33,14 @@ def on_privmsg(cli, rawnick, chan, msg):
|
|||||||
h = msg[len(x)+1:]
|
h = msg[len(x)+1:]
|
||||||
if not h or h[0] == " " or not x:
|
if not h or h[0] == " " or not x:
|
||||||
for fn in wolfgame.COMMANDS[x]:
|
for fn in wolfgame.COMMANDS[x]:
|
||||||
fn(cli, rawnick, chan, h.lstrip())
|
try:
|
||||||
|
fn(cli, rawnick, chan, h.lstrip())
|
||||||
|
except Exception as e:
|
||||||
|
if botconfig.DEBUG_MODE:
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
traceback.print_exc()
|
||||||
|
cli.msg(chan, "An error has occurred.")
|
||||||
else:
|
else:
|
||||||
for x in wolfgame.PM_COMMANDS.keys():
|
for x in wolfgame.PM_COMMANDS.keys():
|
||||||
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
||||||
@ -43,7 +51,14 @@ def on_privmsg(cli, rawnick, chan, msg):
|
|||||||
continue
|
continue
|
||||||
if not h or h[0] == " " or not x:
|
if not h or h[0] == " " or not x:
|
||||||
for fn in wolfgame.PM_COMMANDS[x]:
|
for fn in wolfgame.PM_COMMANDS[x]:
|
||||||
fn(cli, rawnick, h.lstrip())
|
try:
|
||||||
|
fn(cli, rawnick, h.lstrip())
|
||||||
|
except Exception as e:
|
||||||
|
if botconfig.DEBUG_MODE:
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
traceback.print_exc()
|
||||||
|
cli.msg(chan, "An error has occurred.")
|
||||||
|
|
||||||
def __unhandled__(cli, prefix, cmd, *args):
|
def __unhandled__(cli, prefix, cmd, *args):
|
||||||
if cmd in wolfgame.HOOKS.keys():
|
if cmd in wolfgame.HOOKS.keys():
|
||||||
@ -58,7 +73,10 @@ def __unhandled__(cli, prefix, cmd, *args):
|
|||||||
if isinstance(arg, bytes)]))
|
if isinstance(arg, bytes)]))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.WARNING)
|
if not botconfig.DEBUG_MODE:
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
else:
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
cli = IRCClient(
|
cli = IRCClient(
|
||||||
{"privmsg":on_privmsg,
|
{"privmsg":on_privmsg,
|
||||||
"":__unhandled__},
|
"":__unhandled__},
|
||||||
|
32
wolfgame.py
32
wolfgame.py
@ -84,6 +84,12 @@ def connect_callback(cli):
|
|||||||
var.GRAVEYARD_LOCK = threading.RLock()
|
var.GRAVEYARD_LOCK = threading.RLock()
|
||||||
var.GAME_ID = 0
|
var.GAME_ID = 0
|
||||||
|
|
||||||
|
if botconfig.DEBUG_MODE:
|
||||||
|
NIGHT_TIME_LIMIT = 0 # 90
|
||||||
|
DAY_TIME_LIMIT = 0
|
||||||
|
KILL_IDLE_TIME = 0 #300
|
||||||
|
WARN_IDLE_TIME = 0 #180
|
||||||
|
|
||||||
prepare_stuff()
|
prepare_stuff()
|
||||||
|
|
||||||
|
|
||||||
@ -360,7 +366,7 @@ def fleave(cli, nick, chan, rest):
|
|||||||
def fstart(cli, nick, chan, rest):
|
def fstart(cli, nick, chan, rest):
|
||||||
var.CAN_START_TIME = datetime.now()
|
var.CAN_START_TIME = datetime.now()
|
||||||
cli.msg(chan, "\u0002{0}\u0002 has forced the game to start.".format(nick))
|
cli.msg(chan, "\u0002{0}\u0002 has forced the game to start.".format(nick))
|
||||||
start(cli, chan, chan, rest)
|
start(cli, nick, nick, rest)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1821,14 +1827,24 @@ def fwait(cli, nick, chan, rest):
|
|||||||
cli.notice(nick, "Werewolf is already in play.")
|
cli.notice(nick, "Werewolf is already in play.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
rest = rest.strip()
|
||||||
|
if rest and rest.isdigit():
|
||||||
|
if len(rest) < 4:
|
||||||
|
extra = int(rest)
|
||||||
|
else:
|
||||||
|
cli.msg(chan, "{0}: We don't have all day!".format(nick))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
extra = var.EXTRA_WAIT
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if now > var.CAN_START_TIME:
|
if now > var.CAN_START_TIME:
|
||||||
var.CAN_START_TIME = now + timedelta(seconds=var.EXTRA_WAIT)
|
var.CAN_START_TIME = now + timedelta(seconds=extra)
|
||||||
else:
|
else:
|
||||||
var.CAN_START_TIME += timedelta(seconds=var.EXTRA_WAIT)
|
var.CAN_START_TIME += timedelta(seconds=extra)
|
||||||
var.WAITED += 1
|
var.WAITED += 1
|
||||||
cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+
|
cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+
|
||||||
"{1} seconds.").format(nick, var.EXTRA_WAIT))
|
"{1} seconds.").format(nick, extra))
|
||||||
|
|
||||||
|
|
||||||
@cmd("fstop",admin_only=True)
|
@cmd("fstop",admin_only=True)
|
||||||
@ -1837,7 +1853,10 @@ def reset_game(cli, nick, chan, rest):
|
|||||||
cli.notice(nick, "No game is currently running.")
|
cli.notice(nick, "No game is currently running.")
|
||||||
return
|
return
|
||||||
cli.msg(chan, "\u0002{0}\u0002 has forced the game to stop.".format(nick))
|
cli.msg(chan, "\u0002{0}\u0002 has forced the game to stop.".format(nick))
|
||||||
stop_game(cli)
|
if var.PHASE != "join":
|
||||||
|
stop_game(cli)
|
||||||
|
else:
|
||||||
|
reset(cli)
|
||||||
|
|
||||||
|
|
||||||
@pmcmd("rules")
|
@pmcmd("rules")
|
||||||
@ -1864,7 +1883,7 @@ def help(cli, rnick, rest):
|
|||||||
found = True
|
found = True
|
||||||
for fn in c[cname]:
|
for fn in c[cname]:
|
||||||
if fn.__doc__:
|
if fn.__doc__:
|
||||||
cli.msg(nick, fn.__doc__)
|
cli.msg(nick, botconfig.CMD_CHAR+cname+": "+fn.__doc__)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
@ -1982,6 +2001,7 @@ if botconfig.DEBUG_MODE:
|
|||||||
rst = re.split(" +",rest)
|
rst = re.split(" +",rest)
|
||||||
if len(rst) < 2:
|
if len(rst) < 2:
|
||||||
cli.msg(chan, "The syntax is incorrect.")
|
cli.msg(chan, "The syntax is incorrect.")
|
||||||
|
return
|
||||||
who = rst.pop(0).strip()
|
who = rst.pop(0).strip()
|
||||||
rol = " ".join(rst).strip()
|
rol = " ".join(rst).strip()
|
||||||
ull = [u.lower() for u in var.USERS]
|
ull = [u.lower() for u in var.USERS]
|
||||||
|
Loading…
Reference in New Issue
Block a user