def error_callback(update: Update, context: CallbackContext): if not update: return if context.error in errors: return try: stringio = io.StringIO() pretty_errors.output_stderr = stringio output = pretty_errors.excepthook( type(context.error), context.error, context.error.__traceback__ ) pretty_errors.output_stderr = sys.stderr pretty_error = stringio.getvalue() stringio.close() except: pretty_error = "Failed to create pretty error." tb_list = traceback.format_exception( None, context.error, context.error.__traceback__ ) tb = "".join(tb_list) pretty_message = ( "{}\n" "-------------------------------------------------------------------------------\n" "An exception was raised while handling an update\n" "User: {}\n" "Chat: {} {}\n" "Callback data: {}\n" "Message: {}\n\n" "Full Traceback: {}" ).format( pretty_error, update.effective_user.id, update.effective_chat.title if update.effective_chat else "", update.effective_chat.id if update.effective_chat else "", update.callback_query.data if update.callback_query else "None", update.effective_message.text if update.effective_message else "No message", tb, ) key = requests.post( "https://nekobin.com/api/documents", json={"content": pretty_message} ).json() e = html.escape(f"{context.error}") if not key.get("result", {}).get("key"): with open("error.txt", "w+") as f: f.write(pretty_message) context.bot.send_document( OWNER_ID, open("error.txt", "rb"), caption=f"#{context.error.identifier}\n<b>An unknown error occured:</b>\n<code>{e}</code>", parse_mode="html", ) return key = key.get("result").get("key") url = f"https://nekobin.com/{key}.py" context.bot.send_message( OWNER_ID, text=f"#{context.error.identifier}\n<b>An unknown error occured:</b>\n<code>{e}</code>", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("Nekobin", url=url)]] ), parse_mode="html", )
def error_callback(update: Update, context: CallbackContext): if not update: return if context.error in errors: return try: stringio = io.StringIO() pretty_errors.output_stderr = stringio output = pretty_errors.excepthook(type(context.error), context.error, context.error.__traceback__) pretty_errors.output_stderr = sys.stderr pretty_error = stringio.getvalue() stringio.close() except: pretty_error = "Failed to create pretty error." tb_list = traceback.format_exception(None, context.error, context.error.__traceback__) tb = "".join(tb_list) pretty_message = ( "{}\n" "-------------------------------------------------------------------------------\n" "Se generó una error al manejar una update\n" "Usuario: {}\n" "Chat: {} {}\n" "Datos de devolución de llamada: {}\n" "Mensaje: {}\n\n" "Rastreo completo: {}").format( pretty_error, update.effective_user.id, update.effective_chat.title if update.effective_chat else "", update.effective_chat.id if update.effective_chat else "", update.callback_query.data if update.callback_query else "None", update.effective_message.text if update.effective_message else "No message", tb, ) key = requests.post("https://nekobin.com/api/documents", json={ "content": pretty_message }).json() e = html.escape(f"{context.error}") if not key.get("result", {}).get("key"): with open("error.txt", "w+") as f: f.write(pretty_message) if DEV_GROUP: try: context.bot.send_document( DEV_GROUP, open("error.txt", "rb"), caption= f"#{context.error.identifier}\n<b>Un error desconocido ocurrió:</b>\n<code>{e}</code>", parse_mode="html", ) except: context.bot.send_document( OWNER_ID, open("error.txt", "rb"), caption= f"#{context.error.identifier}\n<b>Un error desconocido ocurrió:</b>\n<code>{e}</code>", parse_mode="html", ) return key = key.get("result").get("key") url = f"https://nekobin.com/{key}.py" if DEV_GROUP: try: context.bot.send_message( DEV_GROUP, text= f"#{context.error.identifier}\n<b>Un error desconocido ocurrió:</b>\n<code>{e}</code>", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("Nekobin", url=url)]]), parse_mode="html", ) except: context.bot.send_message( OWNER_ID, text= f"#{context.error.identifier}\n<b>Un error desconocido ocurrió:</b>\n<code>{e}</code>", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("Nekobin", url=url)]]), parse_mode="html", )
def error_callback(update: Update, context: CallbackContext): if not update: return if context.error in errors: return try: stringio = io.StringIO() pretty_errors.output_stderr = stringio output = pretty_errors.excepthook( type(context.error), context.error, context.error.__traceback__, ) pretty_errors.output_stderr = sys.stderr pretty_error = stringio.getvalue() stringio.close() except: pretty_error = "Failed to create pretty error." tb_list = traceback.format_exception( None, context.error, context.error.__traceback__, ) tb = "".join(tb_list) pretty_message = ( "{}\n" "-------------------------------------------------------------------------------\n" "An exception was raised while handling an update\n" "User: {}\n" "Chat: {} {}\n" "Callback data: {}\n" "Message: {}\n\n" "Full Traceback: {}").format( pretty_error.replace(context.bot.token, "$TOKEN").replace( str(API_ID), "$API_ID").replace( API_HASH, "$API_HASH"), #.replace(SPAMWATCH_API, "$SPAMWATCH_API"), update.effective_user.id, update.effective_chat.title if update.effective_chat else "", update.effective_chat.id if update.effective_chat else "", update.callback_query.data if update.callback_query else "None", update.effective_message.text if update.effective_message else "No message", tb, ) data = str(pretty_message) uri = "https://spaceb.in/api/v1/documents" cont = {} cont['content'] = data cont['Extension'] = 'py' data = json.dumps(cont) headers = CaseInsensitiveDict() headers["Content-Type"] = "application/json" resp = requests.post(uri, headers=headers, data=data) result = resp.json()["payload"] key = result["id"] e = html.escape(f"{context.error}") e = e.replace(context.bot.token, "$TOKEN").replace(str(API_ID), "$API_ID").replace( API_HASH, "$API_HASH") #.replace(SPAMWATCH_API, "$SPAMWATCH_API") if not key: with open("error.txt", "w+") as f: f.write(pretty_message) context.bot.send_document( OWNER_ID, open("error.txt", "rb"), caption= f"#{context.error.identifier}\n<b>An unknown error occured:</b>\n<code>{e}</code>", parse_mode="html", ) return url = f"https://spaceb.in/{key}" context.bot.send_message( OWNER_ID, text= f"#{context.error.identifier}\n<b>An unknown error occured:</b>\n<code>{e}</code>", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("SpaceBin", url=url)]], ), parse_mode="html", )
def error_callback(update: Update, context: CallbackContext): if not update: return if context.error in errors: return tb_list = traceback.format_exception(None, context.error, context.error.__traceback__) try: stringio = io.StringIO() pretty_errors.output_stderr = stringio output = pretty_errors.excepthook( type(context.error), context.error, context.error.__traceback__, ) pretty_errors.output_stderr = sys.stderr pretty_error = stringio.getvalue() stringio.close() except: # pylint: disable=bare-except pretty_error = "Failed to create pretty error." tb_list = traceback.format_exception( None, context.error, context.error.__traceback__, ) tb = "".join(tb_list) pretty_message = ( "An exception was raised while handling an update\n" "User: {}\n" "Chat: {} {}\n" "Callback data: {}\n" "Message: {}\n\n" "Full Traceback: {}").format( pretty_error, update.effective_user.id, update.effective_chat.title if update.effective_chat else "", update.effective_chat.id if update.effective_chat else "", update.callback_query.data if update.callback_query else "None", update.effective_message.text if update.effective_message else "No message", tb, ) key = requests.post( "https://hastebin.com/documents", data=pretty_message.encode("UTF-8"), ).json() e = html.escape(f"{context.error}") if not key.get("result", {}).get("key"): with open("error.txt", "w+") as f: f.write(pretty_message) context.bot.send_document( ERROR_LOGS, open("error.txt", "rb"), caption= f"#{context.error.identifier}\n<b>Your sugar mommy got an error for you, you cute guy:</b>\n<code>{e}</code>", parse_mode="html", ) return key = key.get("result").get("key") url = f"https://hastebin.com/{key}" context.bot.send_message( ERROR_LOGS, text= f"#{context.error.identifier}\n<b>Your sugar mommy got an error for you, you cute guy:</b>\n<code>{e}</code>", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton("Hastebin", url=url)]]), parse_mode="html", )