Add an option to pastebin tracebacks
This commit is contained in:
parent
d9a0fa3b6f
commit
b804d95e57
@ -32,3 +32,6 @@ USE_UTC = True # if True, will use the UTC time, else the local time
|
||||
# {tzname} and {tzoffset} can both be used; respectively the timezone name (like UTC) and offset in the form +0000
|
||||
# %Y is the year with century, %y is the year without, %m is the month, %d the day, %H hour, %M minute and %S seconds
|
||||
TIMESTAMP_FORMAT = "[%Y-%m-%d %H:%M:%S{tzoffset}]"
|
||||
|
||||
# If enabled, when there's an error, the bot will post it to termbin.com and post the link to the channel.
|
||||
PASTEBIN_ERRORS = True
|
||||
|
@ -8,10 +8,25 @@ from base64 import b64encode
|
||||
from oyoyo.parse import parse_nick
|
||||
import imp
|
||||
from tools import logger
|
||||
import socket
|
||||
|
||||
log = logger("errors.log")
|
||||
alog = logger(None)
|
||||
|
||||
|
||||
def pastebin(s):
|
||||
if not botconfig.PASTEBIN_ERRORS:
|
||||
return
|
||||
|
||||
try:
|
||||
with socket.socket() as sock:
|
||||
sock.connect(("termbin.com", 9999))
|
||||
sock.send(s.encode("utf-8", "replace") + b"\n")
|
||||
return sock.recv(1024).decode("utf-8")
|
||||
except socket.error:
|
||||
log(traceback.format_exc())
|
||||
|
||||
|
||||
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
||||
|
||||
@ -34,7 +49,11 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||
raise
|
||||
else:
|
||||
log(traceback.format_exc())
|
||||
cli.msg(chan, "An error has occurred and has been logged.")
|
||||
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())):
|
||||
if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
|
||||
@ -54,7 +73,11 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||
raise
|
||||
else:
|
||||
log(traceback.format_exc())
|
||||
cli.msg(chan, "An error has occurred and has been logged.")
|
||||
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):
|
||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
||||
@ -71,7 +94,11 @@ def __unhandled__(cli, prefix, cmd, *args):
|
||||
raise e
|
||||
else:
|
||||
log(traceback.format_exc())
|
||||
cli.msg(botconfig.CHANNEL, "An error has occurred and has been logged.")
|
||||
url = pastebin(traceback.format_exc())
|
||||
cli.msg(botconfig.CHANNEL,
|
||||
"An error has occurred and has been logged.{0}"
|
||||
.format((" " + url) if url else ""))
|
||||
|
||||
|
||||
|
||||
COMMANDS = {}
|
||||
|
@ -408,7 +408,9 @@ def forced_exit(cli, nick, chan, rest): # Admin Only
|
||||
stop_game(cli)
|
||||
except:
|
||||
errlog(traceback.format_exc())
|
||||
cli.msg(chan, "An error has occurred and has been logged.")
|
||||
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:
|
||||
@ -418,7 +420,6 @@ def forced_exit(cli, nick, chan, rest): # Admin Only
|
||||
cli.quit("Forced quit from "+nick)
|
||||
|
||||
|
||||
|
||||
@cmd("frestart", admin_only=True, pm=True)
|
||||
def restart_program(cli, nick, chan, rest):
|
||||
"""Restarts the bot."""
|
||||
@ -429,7 +430,9 @@ def restart_program(cli, nick, chan, rest):
|
||||
stop_game(cli)
|
||||
except:
|
||||
errlog(traceback.format_exc())
|
||||
cli.msg(chan, "An error has occurred and has been logged.")
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user