Пример #1
0
        port=botconfig.PORT,
        authname=botconfig.USERNAME,
        password=botconfig.PASS,
        nickname=botconfig.NICK,
        ident=botconfig.IDENT,
        real_name=botconfig.REALNAME,
        sasl_auth=botconfig.SASL_AUTHENTICATION,
        server_pass=botconfig.SERVER_PASS,
        use_ssl=botconfig.USE_SSL,
        cert_verify=var.SSL_VERIFY,
        cert_fp=var.SSL_CERTFP,
        client_certfile=var.SSL_CERTFILE,
        client_keyfile=var.SSL_KEYFILE,
        cipher_list=var.SSL_CIPHERS,
        tokenbucket=TokenBucket(var.IRC_TB_BURST,
                                var.IRC_TB_DELAY,
                                init=var.IRC_TB_INIT),
        connect_cb=handler.connect_callback,
        stream_handler=src.stream,
    )
    cli.mainLoop()


if __name__ == "__main__":
    try:
        main()
    except Exception:
        src.errlog(traceback.format_exc())

# vim: set sw=4 expandtab:
Пример #2
0
import src
from src import handler

def main():
    src.plog("Connecting to {0}:{1}{2}".format(botconfig.HOST, "+" if botconfig.USE_SSL else "", botconfig.PORT))
    cli = IRCClient(
                      {"privmsg": handler.on_privmsg,
                       "notice": lambda a, b, c, d: handler.on_privmsg(a, b, c, d, True),
                       "": handler.unhandled},
                     host=botconfig.HOST,
                     port=botconfig.PORT,
                     authname=botconfig.USERNAME,
                     password=botconfig.PASS,
                     nickname=botconfig.NICK,
                     ident=botconfig.IDENT,
                     real_name=botconfig.REALNAME,
                     sasl_auth=botconfig.SASL_AUTHENTICATION,
                     server_pass=botconfig.SERVER_PASS,
                     use_ssl=botconfig.USE_SSL,
                     connect_cb=handler.connect_callback,
                     stream_handler=src.stream,
    )
    cli.mainLoop()


if __name__ == "__main__":
    try:
        main()
    except Exception:
        src.errlog(traceback.format_exc())
Пример #3
0
    def __exit__(self, exc_type, exc_value, tb):
        if exc_type is exc_value is tb is None:
            _local.level -= 1
            return False

        if not issubclass(exc_type, Exception):
            _local.level -= 1
            return False

        if _local.level > 1:
            _local.level -= 1
            return False # the outermost caller should handle this

        variables = ["", None]

        if _local.handler is None:
            _local.handler = chain_exceptions(exc_value)

        if var.TRACEBACK_VERBOSITY > 0:
            word = "\nLocal variables from frame #{0} (in {1}):\n"
            variables.append(None)
            frames = []

            while tb is not None:
                ignore_locals = not tb.tb_frame.f_locals or tb.tb_frame.f_locals.get("_ignore_locals_")
                # also ignore locals for library code
                if "/lib/" in tb.tb_frame.f_code.co_filename.replace("\\", "/"):
                    ignore_locals = True
                if tb.tb_next is not None and ignore_locals:
                    frames.append(None)
                else:
                    frames.append(tb.tb_frame)
                tb = tb.tb_next

            if var.TRACEBACK_VERBOSITY < 2:
                word = "Local variables from innermost frame (in {1}):\n"
                frames = [frames[-1]]

            with _local.handler:
                for i, frame in enumerate(frames, start=1):
                    if frame is None:
                        continue
                    variables.append(word.format(i, frame.f_code.co_name))
                    for name, value in frame.f_locals.items():
                        try:
                            if isinstance(value, dict):
                                try:
                                    log_value = "{{{0}}}".format(", ".join("{0:for_tb}: {1:for_tb}".format(k, v) for k, v in value.items()))
                                except:
                                    try:
                                        log_value = "{{{0}}}".format(", ".join("{0!r}: {1:for_tb}".format(k, v) for k, v in value.items()))
                                    except:
                                        log_value = "{{{0}}}".format(", ".join("{0:for_tb}: {1!r}".format(k, v) for k, v in value.items()))
                            elif isinstance(value, list):
                                log_value = "[{0}]".format(", ".join(format(v, "for_tb") for v in value))
                            elif isinstance(value, set):
                                log_value = "{{{0}}}".format(", ".join(format(v, "for_tb") for v in value))
                            else:
                                log_value = format(value, "for_tb")
                        except:
                            log_value = repr(value)
                        variables.append("{0} = {1}".format(name, log_value))

            if len(variables) > 3:
                variables.append("\n")
                if var.TRACEBACK_VERBOSITY > 1:
                    variables[2] = "Local variables in all frames (most recent call last):"
                else:
                    variables[2] = ""
            else:
                variables[2] = "No local variables found in all frames."

        variables[1] = _local.handler.traceback
        errlog("\n".join(variables))

        # sanitize paths in tb: convert backslash to forward slash and remove prefixes from src and library paths
        variables[1] = variables[1].replace("\\", "/")
        variables[1] = re.sub(r'File "[^"]*/(src|gamemodes|oyoyo|roles|lib|wolfbot)', r'File "/\1', variables[1])

        # sanitize values within local frames
        if len(variables) > 3:
            for i in range(3, len(variables)):
                # strip filenames out of module printouts
                variables[i] = re.sub(r"<(module .*?) from .*?>", r"<\1>", variables[i])

        if channels.Main is not channels.Dev:
            channels.Main.send(messages["error_log"])
        message = [str(messages["error_log"])]

        link = _tracebacks.get("\n".join(variables))
        if link is None:
            api_url = "https://ww.chat/submit"
            data = None
            with _local.handler:
                req = urllib.request.Request(api_url, json.dumps({
                        "c": "\n".join(variables),  # contents
                    }).encode("utf-8", "replace"))

                req.add_header("Accept", "application/json")
                req.add_header("Content-Type", "application/json; charset=utf-8")
                resp = urllib.request.urlopen(req)
                data = json.loads(resp.read().decode("utf-8"))

            if data is None:  # couldn't fetch the link
                message.append(messages["error_pastebin"])
                errlog(_local.handler.traceback)
            else:
                link = _tracebacks["\n".join(variables)] = data["url"]
                message.append(link)

        else:
            message.append(link)

        if channels.Dev is not None:
            channels.Dev.send(" ".join(message), prefix=botconfig.DEV_PREFIX)

        _local.level -= 1
        if not _local.level: # outermost caller; we're done here
            _local.handler = None

        return True # a true return value tells the interpreter to swallow the exception
Пример #4
0
    def __exit__(self, exc_type, exc_value, tb):
        if exc_type is exc_value is tb is None:
            _local.level -= 1
            return False

        if not issubclass(exc_type, Exception):
            _local.level -= 1
            return False

        if _local.level > 1:
            _local.level -= 1
            return False # the outermost caller should handle this

        variables = ["", None]

        if _local.handler is None:
            _local.handler = chain_exceptions(exc_value)

        if var.TRACEBACK_VERBOSITY > 0:
            word = "\nLocal variables from frame #{0} (in {1}):\n"
            variables.append(None)
            frames = []

            while tb is not None:
                if tb.tb_next is not None and tb.tb_frame.f_locals.get("_ignore_locals_") or not tb.tb_frame.f_locals:
                    frames.append(None)
                else:
                    frames.append(tb.tb_frame)
                tb = tb.tb_next

            if var.TRACEBACK_VERBOSITY < 2:
                word = "Local variables from innermost frame (in {1}):\n"
                frames = [frames[-1]]

            with _local.handler:
                for i, frame in enumerate(frames, start=1):
                    if frame is None:
                        continue
                    variables.append(word.format(i, frame.f_code.co_name))
                    for name, value in frame.f_locals.items():
                        variables.append("{0} = {1!r}".format(name, value))

            if len(variables) > 3:
                variables.append("\n")
                if var.TRACEBACK_VERBOSITY > 1:
                    variables[2] = "Local variables in all frames (most recent call last):"
                else:
                    variables[2] = ""
            else:
                variables[2] = "No local variables found in all frames."

        variables[1] = _local.handler.traceback

        if not botconfig.PASTEBIN_ERRORS or channels.Main is not channels.Dev:
            channels.Main.send(messages["error_log"])
        if botconfig.PASTEBIN_ERRORS and channels.Dev is not None:
            message = [messages["error_log"]]

            link_uuid = _tracebacks.get("\n".join(variables))
            if link_uuid is None:
                bot_id = re.sub(r"[^A-Za-z0-9-]", "-", users.Bot.nick)
                bot_id = re.sub(r"--+", "-", bot_id).strip("-")

                rand_id = "".join(random.sample(string.ascii_letters + string.digits, 8))

                api_url = "https://ptpb.pw/~{0}-error-{1}".format(bot_id, rand_id)

                data = None
                with _local.handler:
                    req = urllib.request.Request(api_url, urllib.parse.urlencode({
                            "c": "\n".join(variables),  # contents
                        }).encode("utf-8", "replace"))

                    req.add_header("Accept", "application/json")
                    resp = urllib.request.urlopen(req)
                    data = json.loads(resp.read().decode("utf-8"))

                if data is None: # couldn't fetch the link
                    message.append(messages["error_pastebin"])
                    variables[1] = _local.handler.traceback # an error happened; update the stored traceback
                else:
                    link, uuid = _tracebacks["\n".join(variables)] = (data["url"] + "/pytb", data.get("uuid"))
                    message.append(link)
                    if uuid is None: # if there's no uuid, the paste already exists and we don't have it
                        message.append("(Already reported by another instance)")
                    else:
                        message.append("(uuid: {0})".format(uuid))

            else:
                link, uuid = link_uuid
                message.append(link)
                if uuid is None:
                    message.append("(Previously reported)")
                else:
                    message.append("(uuid: {0}-...)".format(uuid[:8]))

            channels.Dev.send(" ".join(message), prefix=botconfig.DEV_PREFIX)

        errlog("\n".join(variables))

        _local.level -= 1
        if not _local.level: # outermost caller; we're done here
            _local.frame_locals = None
            _local.handler = None

        return True # a true return value tells the interpreter to swallow the exception
Пример #5
0
    def __exit__(self, exc_type, exc_value, tb):
        if exc_type is exc_value is tb is None:
            _local.level -= 1
            return False

        if not issubclass(exc_type, Exception):
            _local.level -= 1
            return False

        if _local.level > 1:
            _local.level -= 1
            return False # the outermost caller should handle this

        variables = ["", None]

        if _local.handler is None:
            _local.handler = chain_exceptions(exc_value)

        if var.TRACEBACK_VERBOSITY > 0:
            word = "\nLocal variables from frame #{0} (in {1}):\n"
            variables.append(None)
            frames = []

            while tb is not None:
                if tb.tb_next is not None and tb.tb_frame.f_locals.get("_ignore_locals_") or not tb.tb_frame.f_locals:
                    frames.append(None)
                else:
                    frames.append(tb.tb_frame)
                tb = tb.tb_next

            if var.TRACEBACK_VERBOSITY < 2:
                word = "Local variables from innermost frame (in {1}):\n"
                frames = [frames[-1]]

            with _local.handler:
                for i, frame in enumerate(frames, start=1):
                    if frame is None:
                        continue
                    variables.append(word.format(i, frame.f_code.co_name))
                    for name, value in frame.f_locals.items():
                        variables.append("{0} = {1!r}".format(name, value))

            if len(variables) > 3:
                variables.append("\n")
                if var.TRACEBACK_VERBOSITY > 1:
                    variables[2] = "Local variables in all frames (most recent call last):"
                else:
                    variables[2] = ""
            else:
                variables[2] = "No local variables found in all frames."

        variables[1] = _local.handler.traceback
        bot_root = os.path.dirname(__file__).split("src")[0]
        if bot_root and bot_root != "/":
            variables[1] = variables[1].replace(bot_root, "/")

        if channels.Main is not channels.Dev:
            channels.Main.send(messages["error_log"])
        message = [messages["error_log"]]

        link = _tracebacks.get("\n".join(variables))
        if link is None:
            api_url = "https://ww.chat/submit"
            data = None
            with _local.handler:
                req = urllib.request.Request(api_url, json.dumps({
                        "c": "\n".join(variables),  # contents
                    }).encode("utf-8", "replace"))

                req.add_header("Accept", "application/json")
                req.add_header("Content-Type", "application/json; charset=utf-8")
                resp = urllib.request.urlopen(req)
                data = json.loads(resp.read().decode("utf-8"))

            if data is None: # couldn't fetch the link
                message.append(messages["error_pastebin"])
                variables[1] = _local.handler.traceback # an error happened; update the stored traceback
            else:
                link = _tracebacks["\n".join(variables)] = data["url"]
                message.append(link)

        else:
            message.append(link)

        if channels.Dev is not None:
            channels.Dev.send(" ".join(message), prefix=botconfig.DEV_PREFIX)

        errlog("\n".join(variables))

        _local.level -= 1
        if not _local.level: # outermost caller; we're done here
            _local.handler = None

        return True # a true return value tells the interpreter to swallow the exception