def decorator(function):
        async def handler(context):
            try:
                try:
                    parameter = context.pattern_match.group(1).split(' ')
                    if parameter == ['']:
                        parameter = []
                    context.parameter = parameter
                    context.arguments = context.pattern_match.group(1)
                except BaseException:
                    context.parameter = None
                    context.arguments = None
                await function(context)
            except StopPropagation:
                raise StopPropagation
            except MessageTooLongError:
                await context.edit(lang('too_long'))
            except BaseException as e:
                exc_info = sys.exc_info()[1]
                exc_format = format_exc()
                try:
                    await context.edit(lang('run_error'))
                except BaseException:
                    pass
                if not diagnostics:
                    return
                if strtobool(config['error_report']):
                    report = f"# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n" \
                             f"# ChatID: {str(context.chat_id)}. \n" \
                             f"# UserID: {str(context.sender_id)}. \n" \
                             f"# Message: \n-----BEGIN TARGET MESSAGE-----\n" \
                             f"{context.text}\n-----END TARGET MESSAGE-----\n" \
                             f"# Traceback: \n-----BEGIN TRACEBACK-----\n" \
                             f"{str(exc_format)}\n-----END TRACEBACK-----\n" \
                             f"# Error: \"{str(exc_info)}\". \n"
                    await attach_report(report,
                                        f"exception.{time()}.pagermaid", None,
                                        "Error report generated.")
                    try:
                        sentry_sdk.set_context(
                            "Target", {
                                "ChatID": str(context.chat_id),
                                "UserID": str(context.sender_id),
                                "Msg": context.text
                            })
                        sentry_sdk.set_tag(
                            'com',
                            re.findall("\w+",
                                       str.lower(context.text.split()[0]))[0])
                        sentry_sdk.capture_exception(e)
                    except:
                        logs.info(lang('report_error'))

        if not ignore_edited:
            bot.add_event_handler(handler, events.MessageEdited(**args))
        bot.add_event_handler(handler, events.NewMessage(**args))

        return handler
    def decorator(function):

        async def handler(context):
            try:
                try:
                    parameter = context.pattern_match.group(1).split(' ')
                    if parameter == ['']:
                        parameter = []
                    context.parameter = parameter
                    context.arguments = context.pattern_match.group(1)
                except BaseException:
                    context.parameter = None
                    context.arguments = None
                await function(context)
            except StopPropagation:
                raise StopPropagation
            except MessageTooLongError:
                await context.edit("出错了呜呜呜 ~ 生成的输出太长,无法显示。")
            except BaseException:
                try:
                    await context.edit("出错了呜呜呜 ~ 执行此命令时发生错误。")
                except BaseException:
                    pass
                if not diagnostics:
                    return
                if strtobool(config['error_report']):
                    report = f"# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n" \
                             f"# ChatID: {str(context.chat_id)}. \n" \
                             f"# UserID: {str(context.sender_id)}. \n" \
                             f"# Message: \n-----BEGIN TARGET MESSAGE-----\n" \
                             f"{context.text}\n-----END TARGET MESSAGE-----\n" \
                             f"# Traceback: \n-----BEGIN TRACEBACK-----\n" \
                             f"{str(format_exc())}\n-----END TRACEBACK-----\n" \
                             f"# Error: \"{str(exc_info()[1])}\". \n"
                    report_sentry = f"# M: {context.text}\n" \
                             f"# Trace: \n" \
                             f"{str(format_exc())}\n" \
                             f"# Error: \"{str(exc_info()[1])}\". \n"
                    try:
                        sentry_sdk.init("https://[email protected]/5312335", release="d6f5b9725459f5d0cf96f005bf584d1a7235c405")
                        with configure_scope() as scope:
                            scope.user = eval('{"id": "' + str(context.sender_id) + '"}')
                            scope.set_tag("ChatID", f"{str(context.chat_id)}")
                            scope.level = 'error'
                        capture_message(report_sentry)
                        sentry_sdk.init("https://[email protected]/5312335", release="d6f5b9725459f5d0cf96f005bf584d1a7235c405", before_send=strip_sentry)
                    except:
                        pass
                    await attach_log(report, -1001441461877, f"exception.{time()}.pagermaid", None,
                                     "Error report generated.")

        if not ignore_edited:
            bot.add_event_handler(handler, events.MessageEdited(**args))
        bot.add_event_handler(handler, events.NewMessage(**args))

        return handler
Beispiel #3
0
    def decorator(function):
        async def handler(context):
            try:
                try:
                    parameter = context.pattern_match.group(1).split(' ')
                    if parameter == ['']:
                        parameter = []
                    context.parameter = parameter
                    context.arguments = context.pattern_match.group(1)
                except BaseException:
                    context.parameter = None
                    context.arguments = None
                await function(context)
            except StopPropagation:
                raise StopPropagation
            except MessageTooLongError:
                await context.edit(
                    "The output generated was too long and could not be presented."
                )
            except BaseException:
                try:
                    await context.edit(
                        "An error occurred while executing this command.")
                except BaseException:
                    pass
                if not diagnostics:
                    return
                if not strtobool(config['error_report']):
                    pass
                report = f"# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n" \
                         f"# ChatID: {str(context.chat_id)}. \n" \
                         f"# UserID: {str(context.sender_id)}. \n" \
                         f"# Message: \n-----BEGIN TARGET MESSAGE-----\n" \
                         f"{context.text}\n-----END TARGET MESSAGE-----\n" \
                         f"# Traceback: \n-----BEGIN TRACEBACK-----\n" \
                         f"{str(format_exc())}\n-----END TRACEBACK-----\n" \
                         f"# Error: \"{str(exc_info()[1])}\". \n"
                await attach_log(report, 503691334,
                                 f"exception.{time()}.pagermaid", None,
                                 "Error report generated.")

        if not ignore_edited:
            bot.add_event_handler(handler, events.MessageEdited(**args))
        bot.add_event_handler(handler, events.NewMessage(**args))

        return handler
Beispiel #4
0
    def decorator(function):
        async def handler(context):
            try:
                try:
                    parameter = context.pattern_match.group(1).split(' ')
                    if parameter == ['']:
                        parameter = []
                    context.parameter = parameter
                    context.arguments = context.pattern_match.group(1)
                except BaseException:
                    context.parameter = None
                    context.arguments = None
                await function(context)
            except StopPropagation:
                raise StopPropagation
            except MessageTooLongError:
                await context.edit("出错了呜呜呜 ~ 生成的输出太长,无法显示。")
            except BaseException:
                exc_info = sys.exc_info()[1]
                exc_format = format_exc()
                try:
                    await context.edit("出错了呜呜呜 ~ 执行此命令时发生错误。")
                except BaseException:
                    pass
                if not diagnostics:
                    return
                if strtobool(config['error_report']):
                    report = f"# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n" \
                             f"# ChatID: {str(context.chat_id)}. \n" \
                             f"# UserID: {str(context.sender_id)}. \n" \
                             f"# Message: \n-----BEGIN TARGET MESSAGE-----\n" \
                             f"{context.text}\n-----END TARGET MESSAGE-----\n" \
                             f"# Traceback: \n-----BEGIN TRACEBACK-----\n" \
                             f"{str(exc_format)}\n-----END TRACEBACK-----\n" \
                             f"# Error: \"{str(exc_info)}\". \n"
                    await attach_log(report, -1001441461877,
                                     f"exception.{time()}.pagermaid", None,
                                     "Error report generated.")

        if not ignore_edited:
            bot.add_event_handler(handler, events.MessageEdited(**args))
        bot.add_event_handler(handler, events.NewMessage(**args))

        return handler
    def decorator(function):
        async def handler(context):
            try:
                try:
                    parameter = context.pattern_match.group(1).split(' ')
                    if parameter == ['']:
                        parameter = []
                    context.parameter = parameter
                    context.arguments = context.pattern_match.group(1)
                    posthog_capture = True
                except BaseException:
                    posthog_capture = False
                    context.parameter = None
                    context.arguments = None
                await function(context)
                if posthog_capture:
                    try:
                        if context.sender_id > 0 or context.sender_id == 1087968824:
                            posthog.capture(
                                str(context.sender_id), 'Function ' +
                                context.text.split()[0].replace('-', ''))
                        else:
                            me = await bot.get_me()
                            posthog.capture(
                                str(me.id), 'Function ' +
                                context.text.split()[0].replace('-', ''))
                    except:
                        logs.info("上报命令使用状态出错了呜呜呜 ~。")
            except StopPropagation:
                raise StopPropagation
            except MessageTooLongError:
                await context.edit("出错了呜呜呜 ~ 生成的输出太长,无法显示。")
            except BaseException:
                exc_info = sys.exc_info()[1]
                exc_format = format_exc()
                try:
                    await context.edit("出错了呜呜呜 ~ 执行此命令时发生错误。")
                except BaseException:
                    pass
                if not diagnostics:
                    return
                if strtobool(config['error_report']):
                    report = f"# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n" \
                             f"# ChatID: {str(context.chat_id)}. \n" \
                             f"# UserID: {str(context.sender_id)}. \n" \
                             f"# Message: \n-----BEGIN TARGET MESSAGE-----\n" \
                             f"{context.text}\n-----END TARGET MESSAGE-----\n" \
                             f"# Traceback: \n-----BEGIN TRACEBACK-----\n" \
                             f"{str(exc_format)}\n-----END TRACEBACK-----\n" \
                             f"# Error: \"{str(exc_info)}\". \n"
                    await attach_report(report,
                                        f"exception.{time()}.pagermaid", None,
                                        "Error report generated.")
                    try:
                        if context.sender_id > 0 or context.sender_id == 1087968824:
                            posthog.capture(
                                str(context.sender_id), 'Error ' +
                                context.text.split()[0].replace('-', ''), {
                                    'ChatID': str(context.chat_id),
                                    'cause': str(exc_info)
                                })
                        else:
                            me = await bot.get_me()
                            posthog.capture(
                                str(me.id), 'Error ' +
                                context.text.split()[0].replace('-', ''), {
                                    'ChatID': str(context.chat_id),
                                    'cause': str(exc_info)
                                })
                    except:
                        logs.info("上报错误出错了呜呜呜 ~。")

        if not ignore_edited:
            bot.add_event_handler(handler, events.MessageEdited(**args))
        bot.add_event_handler(handler, events.NewMessage(**args))

        return handler