コード例 #1
0
ファイル: main.py プロジェクト: HFO4/SmartQQBot
def main_loop(no_gui=False, new_user=False, debug=False):
    patch()
    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    logger.info("Initializing...")
    plugin_manager.load_plugin()
    if new_user:
        clean_cookie()
    bot.login(no_gui)
    observer = MessageObserver(bot)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg) for msg in msg_list]
                )
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logger.warning("Message pooling timeout, retrying...")
        except Exception:
            logger.exception("Exception occurs when checking msg.")
コード例 #2
0
def main_loop(no_gui=False, new_user=False, debug=False):
    patch()
    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    logger.info("Initializing...")
    plugin_manager.load_plugin()
    if new_user:
        clean_cookie()
    bot.login(no_gui)
    observer = MessageObserver(bot)
    for name, func in bot_inited_registry.iteritems():
        try:
            func(bot)
        except Exception:
            logging.exception(
                "Error occurs while loading plugin [%s]." % name
            )
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg) for msg in msg_list]
                )
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logger.warning("Message pooling timeout, retrying...")
        except Exception:
            logger.exception("Exception occurs when checking msg.")
コード例 #3
0
def run():
    patch()
    init_logging(logging.DEBUG)
    plugin_manager.load_plugin()
    bot.login()
    observer = MessageObserver(bot)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list([mk_msg(msg) for msg in msg_list])
        except socket.timeout as e:
            logging.warning("Message pooling timeout, retrying...")
        except Exception:
            logging.exception("Exception occurs when checking msg.")
コード例 #4
0
 def monitorLoop():  #监听消息用的循环,用以实现被动回复消息
     while True:
         try:
             msg_list = bot.check_msg()
             if msg_list is not None:
                 print('msg_list = {}'.format(msg_list))
                 observer.handle_msg_list(
                     [mk_msg(msg, bot) for msg in msg_list])
         except ServerResponseEmpty:
             continue
         except (socket.timeout, IOError):
             logger.warning("Message pooling timeout, retrying...")
         except NeedRelogin:
             exit(0)
         except Exception:
             logger.exception("Exception occurs when checking msg.")
コード例 #5
0
ファイル: main.py プロジェクト: coswell/SmartQQBot
def run():
    patch()
    init_logging(logging.DEBUG)
    plugin_manager.load_plugin()
    bot.login()
    observer = MessageObserver(bot)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg) for msg in msg_list]
                )
        except socket.timeout as e:
            logging.warning("Message pooling timeout, retrying...")
        except Exception:
            logging.exception("Exception occurs when checking msg.")
コード例 #6
0
def run():
    patch()
    init_logging(logging.INFO)
    plugin_manager.load_plugin()
    bot.login()
    observer = MessageObserver(bot)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list([mk_msg(msg) for msg in msg_list])
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logging.warning("Message pooling timeout, retrying...")
        except Exception:
            logging.exception("Exception occurs when checking msg.")
コード例 #7
0
ファイル: main.py プロジェクト: drinksober/ChatBot
def run():
    patch()
    init_logging(logging.INFO)
    plugin_manager.load_plugin()
    bot.login()
    observer = MessageObserver(bot)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg) for msg in msg_list]
                )
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logging.warning("Message pooling timeout, retrying...")
        except Exception:
            logging.exception("Exception occurs when checking msg.")
コード例 #8
0
ファイル: main.py プロジェクト: he0119/SmartQQBot
def main_loop(no_gui=False,
              new_user=False,
              debug=False,
              http=False,
              password=False):
    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    if http:
        run_http_daemon()
    logger.info("Initializing...")
    plugin_manager.load_plugin()
    if new_user:
        clean_cookie()
    bot.login(no_gui, password)
    observer = MessageObserver(bot)

    for name, func in bot_inited_registry.items():
        try:
            t = threading.Thread(target=func, args=(bot, ))
            t.daemon = True
            t.start()
        except Exception:
            logging.exception("Error occurs while loading plugin [%s]." % name)
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg, bot) for msg in msg_list])
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logger.debug("Message pooling timeout, retrying...")
        except NeedRelogin:
            exit(0)
        except Exception:
            logger.exception("Exception occurs when checking msg.")
コード例 #9
0
ファイル: main.py プロジェクト: chenrz925/bookish-broccoli
def main_loop(no_gui=False, new_user=False, debug=False, http=False):
    patch()
    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    if http:
        run_http_daemon()
    logger.info("Initializing...")
    plugin_manager.load_plugin()
    if new_user:
        clean_cookie()
    bot.login(no_gui)
    observer = MessageObserver(bot)
    for name, func in iteritems(bot_inited_registry):
        try:
            func(bot)
        except Exception:
            logging.exception(
                "Error occurs while loading plugin [%s]." % name
            )
    while True:
        try:
            msg_list = bot.check_msg()
            if msg_list is not None:
                observer.handle_msg_list(
                    [mk_msg(msg, bot) for msg in msg_list]
                )
        except ServerResponseEmpty:
            continue
        except (socket.timeout, IOError):
            logger.warning("Message pooling timeout, retrying...")
        except NeedRelogin:
            exit(0)
        except Exception:
            logger.exception("Exception occurs when checking msg.")