Пример #1
0
 def _load_default(self):
     for plugin_name in self.config[PLUGIN_ON]:
         try:
             __import__(self._gen_plugin_name(plugin_name))
             logger.info("Plugin [%s] loaded." % plugin_name)
         except ImportError:
             logger.error(
                 "Internal plugin import error: can not import [%s]" %
                 plugin_name)
Пример #2
0
 def _load_package_plugin(self):
     for package_name in self.config[PLUGIN_PACKAGES]:
         try:
             __import__(package_name)
             logger.info("Package plugin [%s] loaded." % package_name)
         except ImportError:
             logger.error(
                 "Package plugin import error: can not import [%s]" %
                 package_name)
Пример #3
0
 def _load_default(self):
     for plugin_name in self.config[PLUGIN_ON]:
         try:
             __import__(self._gen_plugin_name(plugin_name))
             logger.info("Plugin [%s] loaded." % plugin_name)
         except ImportError:
             logger.error(
                 "Internal plugin import error: can not import [%s]"
                 % plugin_name
             )
Пример #4
0
 def _load_package_plugin(self):
     for package_name in self.config[PLUGIN_PACKAGES]:
         try:
             __import__(package_name)
             logger.info("Package plugin [%s] loaded." % package_name)
         except ImportError:
             logger.error(
                 "Package plugin import error: can not import [%s]"
                 % package_name
             )
Пример #5
0
    def check_msg(self):

        # Pooling the message
        response = self.client.post(
            'http://d1.web2.qq.com/channel/poll2',
            {
                'r': json.dumps(
                    {
                        "ptwebqq": self.ptwebqq,
                        "clientid": self.client_id,
                        "psessionid": self.psessionid,
                        "key": ""
                    }
                )
            },
            SMART_QQ_REFER
        )
        logger.debug("Pooling returns response: %s" % response)
        if response == "":
            return
        try:
            ret = json.loads(response.replace(r"\u0026lt;", "<").replace(r"\u0026gt;", ">"))
        except ValueError:
            logger.warning("decode poll response error.")
            logger.debug("{}".format(response))
            return

        ret_code = ret['retcode']

        if ret_code in (0, 116, 1202):
            self._last_pool_success = True
            if ret_code == 0:
                if 'result' not in ret or len(ret['result']) == 0:
                    logger.info("Pooling ends, no new message received.")
                else:
                    return ret['result']
            elif ret_code == 116:
                self.ptwebqq = ret['p']
                logger.debug("ptwebqq updated in this pooling")
        else:
            self._last_pool_success = False
            if ret_code in (103, ):
                logger.info("Pooling received retcode: {}, trying to load online friends".format(str(ret_code)))
                result = self.get_online_friends_list()
                if result is None:
                    logger.warning("Session expired, need to relogin.")
            elif ret_code in (121,):
                logger.warning("Pooling error with retcode %s" % ret_code)
            elif ret_code == 100006:
                logger.error("Pooling request error, response is: %s" % ret)
            elif ret_code == 100012:
                raise NeedRelogin("Login is expired. Please relogin by qrcode")
            else:
                logger.warning("Pooling returns unknown retcode %s" % ret_code)
        return None
Пример #6
0
    def check_msg(self):

        # Pooling the message
        response = self.client.post(
            'http://d1.web2.qq.com/channel/poll2',
            {
                'r': json.dumps(
                    {
                        "ptwebqq": self.ptwebqq,
                        "clientid": self.client_id,
                        "psessionid": self.psessionid,
                        "key": ""
                    }
                )
            },
            SMART_QQ_REFER
        )
        logger.debug("Pooling returns response: %s" % response)
        if response == "":
            return
        try:
            ret = json.loads(response)
        except ValueError:
            logger.warning("RUNTIMELOG decode poll response error.")
            logger.debug("RESPONSE {}".format(response))
            return

        ret_code = ret['retcode']

        if ret_code in (0, 116):
            self._last_pool_success = True
            if ret_code == 0:
                if 'result' not in ret or len(ret['result']) == 0:
                    logger.info("Pooling ends, no new message received.")
                    self.login(no_gui=True)
                else:
                    return ret['result']
            elif ret_code == 116:
                self.ptwebqq = ret['p']
                logger.debug("ptwebqq updated in this pooling")
        else:
            self._last_pool_success = False
            if ret_code in (103, ):
                logger.warning("Pooling received retcode: " + str(ret_code))
                self.login(no_gui=True)
            elif ret_code in (121,):
                logger.warning("Pooling error with retcode %s" % ret_code)
            elif ret_code == 100006:
                logger.error("Pooling request error, response is: %s" % ret)
            elif ret_code == 100012:
                raise NeedRelogin("Login is expired. Please relogin by qrcode")
            else:
                logger.warning("Pooling returns unknown retcode %s" % ret_code)
        return None
Пример #7
0
 def save(self, group_id):
     """
     :type group_id: int, 用于保存指定群的吐槽存档
     """
     global TUCAO_PATH
     try:
         tucao_file_path = TUCAO_PATH + str(group_id) + ".tucao"
         with open(tucao_file_path, "w+") as tucao_file:
             cPickle.dump(self.tucao_dict[str(group_id)], tucao_file)
         logger.info("RUNTIMELOG tucao saved. Now tucao list:  {0}".format(str(self.tucao_dict)))
     except Exception:
         logger.error("RUNTIMELOG Fail to save tucao.")
         raise IOError("Fail to save tucao.")
Пример #8
0
    def load(self,
             url,
             data=None,
             refer=None,
             parser=json_loads,
             validator=None,
             retries=5):
        while True:
            try:
                if data:
                    logger.debug("POST {} with data {}".format(url, data))
                    resp = self.session.post(
                        url,
                        data,
                        headers=self._get_headers(
                            {'Referer': refer or SMART_QQ_REFER}),
                        verify=SSL_VERIFY,
                    )
                else:
                    logger.debug("GET {}".format(url))
                    resp = self.session.get(
                        url,
                        headers=self._get_headers(
                            {'Referer': refer or SMART_QQ_REFER}),
                        verify=SSL_VERIFY,
                    )
                resp = resp.text
                logger.debug("response: {}".format(resp))

                if parser:
                    resp = parser(resp)
                if validator:
                    validator(resp)
            except requests.exceptions.SSLError:
                logger.exception(
                    "SSL连接验证失败,请检查您所在的网络环境。如果需要禁用SSL验证,请修改config.py中的SSL_VERIFY为False"
                )
                raise
            except Exception as e:
                logger.exception(e)
                retries -= 1
                if retries == 0:
                    raise
            else:
                self._cookies.save(COOKIE_FILE,
                                   ignore_discard=True,
                                   ignore_expires=True)
                return resp

            logger.error("request failed, retrying in 2 seconds")
            time.sleep(2)
Пример #9
0
    def check_msg(self):

        # Pooling the message
        response = self.client.post(
            'http://d1.web2.qq.com/channel/poll2',
            {
                'r': json.dumps(
                    {
                        "ptwebqq": self.ptwebqq,
                        "clientid": self.client_id,
                        "psessionid": self.psessionid,
                        "key": ""
                    }
                )
            },
            SMART_QQ_REFER
        )
        logger.debug("Pooling returns response: %s" % response)
        if response == "":
            return
        try:
            ret = json.loads(response)
        except ValueError:
            logger.warning("RUNTIMELOG decode poll response error.")
            logger.debug("RESPONSE {}".format(response))
            return

        ret_code = ret['retcode']

        if ret_code in (0, 116):
            self._last_pool_success = True
            if ret_code == 0:
                if 'result' not in ret or len(ret['result']) == 0:
                    logger.info("Pooling ends, no new message received.")
                else:
                    return ret['result']
            elif ret_code == 116:
                self.ptwebqq = ret['p']
                logger.debug("ptwebqq updated in this pooling")
        else:
            self._last_pool_success = False
            if ret_code in (103, ):
                logger.warning("Pooling received retcode: " + str(ret_code))
            elif ret_code in (121,):
                logger.warning("Pooling error with retcode %s" % ret_code)
            elif ret_code == 100006:
                logger.error("Pooling request error, response is: %s" % ret)
            else:
                logger.warning("Pooling returns unknown retcode %s" % ret_code)
        return None
Пример #10
0
    def check_msg(self):

        # Pooling the message
        try:
            ret = self.client.load(
                'http://d1.web2.qq.com/channel/poll2',
                {
                    'r': json.dumps(
                        {
                            "ptwebqq": self.ptwebqq,
                            "clientid": self.client_id,
                            "psessionid": self.psessionid,
                            "key": ""
                        }
                    )
                },
                SMART_QQ_REFER,
                parser=lambda resp: json.loads(resp.replace(r"\u0026lt;", "<").replace(r"\u0026gt;", ">"))
            )
        except Exception as e:
            logger.exception(e)
            return

        ret_code = ret['retcode']

        if ret_code in (0, 116, 1202):
            self._last_pool_success = True
            if ret_code == 0:
                if 'result' not in ret or len(ret['result']) == 0:
                    logger.info("Pooling ends, no new message received.")
                else:
                    return ret['result']
            elif ret_code == 116:
                self.ptwebqq = ret['p']
                logger.debug("ptwebqq updated in this pooling")
        else:
            self._last_pool_success = False
            if ret_code in (103, ):
                raise NeedRelogin("Pooling received retcode: " + str(ret_code))
            elif ret_code in (121,):
                logger.warning("Pooling error with retcode %s" % ret_code)
            elif ret_code == 100006:
                logger.error("Pooling request error, response is: %s" % ret)
            elif ret_code in (100001, 100012):
                raise NeedRelogin("Login is expired. Please relogin by qrcode")
            else:
                logger.warning("Pooling returns unknown retcode %s" % ret_code)
            time.sleep(2)
        return None
Пример #11
0
    def check_msg(self):

        # Pooling the message
        response = self.client.post(
            'http://d1.web2.qq.com/channel/poll2',
            {
                'r': json.dumps(
                    {
                        "ptwebqq": self.ptwebqq,
                        "clientid": self.client_id,
                        "psessionid": self.psessionid,
                        "key": ""
                    }
                )
            },
            SMART_QQ_REFER
        )
        logger.debug("Pooling returns response: %s" % response)
        if response == "":
            return
        try:
            ret = json.loads(response)
        except ValueError:
            logger.warning("RUNTIMELOG decode poll response error.")
            logger.debug("RESPONSE {}".format(response))
            return

        ret_code = ret['retcode']

        if ret_code in (103, ):
            logger.warning(
                "Pooling received retcode: " + str(ret_code) + ": Check error. 请前往http://w.qq.com/ 手动登陆SmartQQ一次."
            )
        elif ret_code in (121,):
            logger.warning("Pooling error with retcode %s" % ret_code)
        elif ret_code == 0:
            if 'result' not in ret or len(ret['result']) == 0:
                logger.info("Pooling ends, no new message received.")
            else:
                return ret['result']
        elif ret_code == 100006:
            logger.error("Pooling request error, response is: %s" % ret)
        elif ret_code == 116:
            self.ptwebqq = ret['p']
            logger.debug("ptwebqq updated in this pooling")
        else:
            logger.warning("Pooling returns unknown retcode %s" % ret_code)
        return None