Revert latest change and fix & refactor traceback pastebinning
This commit is contained in:
parent
0d99297aee
commit
da41736842
@ -14,22 +14,33 @@ log = logger("errors.log")
|
|||||||
alog = logger(None)
|
alog = logger(None)
|
||||||
|
|
||||||
|
|
||||||
def pastebin(s):
|
def notify_error(cli, chan, target_logger):
|
||||||
if not botconfig.PASTEBIN_TRACEBACK:
|
msg = "An error has occurred and has been logged."
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
tb = traceback.format_exc()
|
||||||
with socket.socket() as sock:
|
|
||||||
sock.connect(("termbin.com", 9999))
|
target_logger(tb)
|
||||||
sock.send(s.encode("utf-8", "replace") + b"\n")
|
|
||||||
return sock.recv(1024).decode("utf-8")
|
if botconfig.PASTEBIN_ERRORS:
|
||||||
except socket.error:
|
try:
|
||||||
log(traceback.format_exc())
|
with socket.socket() as sock:
|
||||||
|
sock.connect(("termbin.com", 9999))
|
||||||
|
sock.send(tb.encode("utf-8", "replace") + b"\n")
|
||||||
|
url = sock.recv(1024).decode("utf-8")
|
||||||
|
except socket.error:
|
||||||
|
target_logger(traceback.format_exc())
|
||||||
|
else:
|
||||||
|
msg += " "
|
||||||
|
msg += url
|
||||||
|
|
||||||
|
cli.msg(chan, msg)
|
||||||
|
|
||||||
|
|
||||||
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
||||||
|
|
||||||
|
currmod.notify_error = notify_error
|
||||||
|
|
||||||
if botconfig.IGNORE_HIDDEN_COMMANDS and (chan.startswith("@#") or chan.startswith("+#")):
|
if botconfig.IGNORE_HIDDEN_COMMANDS and (chan.startswith("@#") or chan.startswith("+#")):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -44,15 +55,11 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
for fn in currmod.COMMANDS[""]:
|
for fn in currmod.COMMANDS[""]:
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, msg)
|
fn(cli, rawnick, chan, msg)
|
||||||
except:
|
except Exception:
|
||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
log(traceback.format_exc())
|
notify_error(cli, chan, log)
|
||||||
url = pastebin(traceback.format_exc())
|
|
||||||
cli.msg(chan,
|
|
||||||
"An error has occurred and has been logged.{0}"
|
|
||||||
.format((" " + url) if url else ""))
|
|
||||||
|
|
||||||
|
|
||||||
for x in set(list(COMMANDS.keys()) + (list(currmod.COMMANDS.keys()) if currmod else list())):
|
for x in set(list(COMMANDS.keys()) + (list(currmod.COMMANDS.keys()) if currmod else list())):
|
||||||
@ -68,15 +75,11 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
for fn in COMMANDS.get(x, []) + (currmod.COMMANDS.get(x, []) if currmod else []):
|
for fn in COMMANDS.get(x, []) + (currmod.COMMANDS.get(x, []) if currmod else []):
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, h.lstrip())
|
fn(cli, rawnick, chan, h.lstrip())
|
||||||
except:
|
except Exception:
|
||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
log(traceback.format_exc())
|
notify_error(cli, chan, log)
|
||||||
url = pastebin(traceback.format_exc())
|
|
||||||
cli.msg(chan,
|
|
||||||
"An error has occurred and has been logged.{0}"
|
|
||||||
.format((" " + url) if url else ""))
|
|
||||||
|
|
||||||
|
|
||||||
def __unhandled__(cli, prefix, cmd, *args):
|
def __unhandled__(cli, prefix, cmd, *args):
|
||||||
@ -93,12 +96,7 @@ def __unhandled__(cli, prefix, cmd, *args):
|
|||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
log(traceback.format_exc())
|
notify_error(cli, chan, log)
|
||||||
url = pastebin(traceback.format_exc())
|
|
||||||
cli.msg(botconfig.CHANNEL,
|
|
||||||
"An error has occurred and has been logged.{0}"
|
|
||||||
.format((" " + url) if url else ""))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {}
|
COMMANDS = {}
|
||||||
|
@ -398,26 +398,37 @@ def sync_modes(cli):
|
|||||||
|
|
||||||
mass_mode(cli, voices, other)
|
mass_mode(cli, voices, other)
|
||||||
|
|
||||||
|
|
||||||
@cmd("fdie", "fbye", admin_only=True, pm=True)
|
@cmd("fdie", "fbye", admin_only=True, pm=True)
|
||||||
def forced_exit(cli, nick, chan, rest): # Admin Only
|
def forced_exit(cli, nick, chan, rest):
|
||||||
"""Forces the bot to close."""
|
"""Forces the bot to close."""
|
||||||
|
|
||||||
if var.PHASE in ("day", "night"):
|
if var.PHASE in ("day", "night"):
|
||||||
#ignore all errors that prevent the bot from stopping
|
|
||||||
try:
|
try:
|
||||||
stop_game(cli)
|
stop_game(cli)
|
||||||
except:
|
except Exception:
|
||||||
errlog(traceback.format_exc())
|
notify_error(cli, chan, errlog)
|
||||||
url = pastebin(traceback.format_exc())
|
|
||||||
cli.msg(chan, "An error has occurred and has been logged.{0}"
|
|
||||||
.format((" " + url) if url else ""))
|
|
||||||
reset_modes_timers(cli)
|
|
||||||
reset()
|
|
||||||
else:
|
|
||||||
reset_modes_timers(cli)
|
|
||||||
reset()
|
|
||||||
|
|
||||||
cli.quit("Forced quit from "+nick)
|
try:
|
||||||
|
reset_modes_timers(cli)
|
||||||
|
except Exception:
|
||||||
|
notify_error(cli, chan, errlog)
|
||||||
|
|
||||||
|
try:
|
||||||
|
assert(1 == 2)
|
||||||
|
except Exception:
|
||||||
|
notify_error(cli, chan, errlog)
|
||||||
|
|
||||||
|
try:
|
||||||
|
reset()
|
||||||
|
except Exception:
|
||||||
|
notify_error(cli, chan, errlog)
|
||||||
|
|
||||||
|
try:
|
||||||
|
cli.quit("Forced quit from {0}".format(nick))
|
||||||
|
except Exception:
|
||||||
|
notify_error(cli, chan, errlog)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
@cmd("frestart", admin_only=True, pm=True)
|
@cmd("frestart", admin_only=True, pm=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user