Use ptpb.pw as pastebin with vanity IDs

This commit is contained in:
nyuszika7h 2016-08-10 23:38:54 +02:00
parent 35ad6c2766
commit 3f3b5bf1d7
2 changed files with 39 additions and 11 deletions

View File

@ -1,6 +1,6 @@
import traceback
import fnmatch import fnmatch
import socket import socket
import traceback
import types import types
from collections import defaultdict from collections import defaultdict
@ -54,15 +54,7 @@ class handle_error:
if not botconfig.PASTEBIN_ERRORS or botconfig.CHANNEL != botconfig.DEV_CHANNEL: if not botconfig.PASTEBIN_ERRORS or botconfig.CHANNEL != botconfig.DEV_CHANNEL:
cli.msg(botconfig.CHANNEL, msg) cli.msg(botconfig.CHANNEL, msg)
if botconfig.PASTEBIN_ERRORS and botconfig.DEV_CHANNEL: if botconfig.PASTEBIN_ERRORS and botconfig.DEV_CHANNEL:
try: pastebin_tb(cli, msg, traceback.format_exc())
with socket.socket() as sock:
sock.connect(("termbin.com", 9999))
sock.send(traceback.format_exc().encode("utf-8", "replace") + b"\n")
url = sock.recv(1024).decode("utf-8")
except socket.error:
pass
else:
cli.msg(botconfig.DEV_CHANNEL, " ".join((msg, url)))
class cmd: class cmd:
def __init__(self, *cmds, raw_nick=False, flag=None, owner_only=False, def __init__(self, *cmds, raw_nick=False, flag=None, owner_only=False,

View File

@ -1,6 +1,11 @@
import re
import fnmatch import fnmatch
import itertools import itertools
import json
import random
import re
import string
import traceback
import urllib
import botconfig import botconfig
import src.settings as var import src.settings as var
@ -428,6 +433,37 @@ def get_nick(cli, nick):
return None return None
return ul[ull.index(lnick)] return ul[ull.index(lnick)]
def pastebin_tb(cli, msg, exc):
try:
bot_id = re.sub(r"[^A-Za-z0-9-]", "-", botconfig.NICK)
bot_id = re.sub(r"--+", "-", bot_id)
bot_id = re.sub(r"^-+|-+$", "", bot_id)
rand_id = "".join(random.sample(string.ascii_letters + string.digits, 8))
api_url = "https://ptpb.pw/~{0}-error-{1}".format(bot_id, rand_id)
req = urllib.request.Request(api_url, urllib.parse.urlencode({
"c": traceback.format_exc(), # contents
"s": 86400 # expiry (seconds)
}).encode("utf-8", "replace"))
req.add_header("Accept", "application/json")
resp = urllib.request.urlopen(req)
data = json.loads(resp.read().decode("utf-8"))
url = data["url"]
except urllib.error.HTTPError as e:
if e.code == 409: # paste ID conflict
pastebin_tb(exc) # retry
else:
# Make sure we print the exception anyway
traceback.print_exc()
cli.msg(botconfig.DEV_CHANNEL, msg + " (Unable to pastebin traceback; please check the console.)")
except Exception:
traceback.print_exc()
cli.msg(botconfig.DEV_CHANNEL, msg + " (Unable to pastebin traceback; please check the console.)")
else:
cli.msg(botconfig.DEV_CHANNEL, " ".join((msg, url)))
class InvalidModeException(Exception): pass class InvalidModeException(Exception): pass