Esempio n. 1
0
    def handle_verify_callback(self, status, msg=None):
        if not hasattr(self, "plug_loader"):
            self.plug_loader = PluginLoader(self)

        if hasattr(self, "verify_callback") and callable(self.verify_callback)\
           and not self.verify_callback_called:
            self.verify_callback(status, msg)
            self.verify_callback_called = True
Esempio n. 2
0
    def handle_verify_callback(self, status, msg=None):
        if not hasattr(self, "plug_loader"):
            self.plug_loader = PluginLoader(self)

        if hasattr(self, "verify_callback") and callable(self.verify_callback)\
           and not self.verify_callback_called:
            self.verify_callback(status, msg)
            self.verify_callback_called = True
Esempio n. 3
0
class Client(WebQQClient):
    verify_img_path = None
    message_requests = {}
    start_time = time.time()
    msg_num = 0

    def handle_verify_code(self, path, r, uin):
        self.verify_img_path = path

        if getattr(config, "UPLOAD_CHECKIMG", False):
            logger.info(u"正在上传验证码...")
            res = self.hub.upload_file("check.jpg", self.hub.checkimg_path)
            logger.info(u"验证码已上传, 地址为: {0}".format(res.read()))

        if getattr(config, "HTTP_CHECKIMG", False):
            if hasattr(self, "handler") and self.handler:
                self.handler.r = r
                self.handler.uin = uin

            logger.info("请打开 http://{0}:{1} 输入验证码".format(
                config.HTTP_LISTEN, config.HTTP_PORT))
            if getattr(config, "EMAIL_NOTICE", False):
                if send_notice_email():
                    logger.info("发送通知邮件成功")
                else:
                    logger.warning("发送通知邮件失败")
        else:
            logger.info(u"验证码本地路径为: {0}".format(self.hub.checkimg_path))
            check_code = None
            while not check_code:
                check_code = raw_input("输入验证码: ")
            self.enter_verify_code(check_code, r, uin)

    def enter_verify_code(self, code, r, uin, callback=None):
        super(Client, self).enter_verify_code(code, r, uin)
        self.verify_callback = callback
        self.verify_callback_called = False

    @register_request_handler(BeforeLoginRequest)
    def handle_verify_check(self, request, resp, data):
        if not data:
            self.handle_verify_callback(False, "没有数据返回验证失败, 尝试重新登录")
            return

        args = request.get_back_args(data)
        scode = int(args[0])
        if scode != 0:
            self.handle_verify_callback(False, args[4])

    def handle_verify_callback(self, status, msg=None):
        if not hasattr(self, "plug_loader"):
            self.plug_loader = PluginLoader(self)

        if hasattr(self, "verify_callback") and callable(self.verify_callback)\
           and not self.verify_callback_called:
            self.verify_callback(status, msg)
            self.verify_callback_called = True

    @register_request_handler(Login2Request)
    def handle_login_errorcode(self, request, resp, data):
        if not resp.body:
            return self.handle_verify_callback(False, u"没有数据返回, 尝试重新登录")

        if data.get("retcode") != 0:
            return self.handle_verify_callback(
                False, u"登录失败: {0}".format(data.get("retcode")))

    @register_request_handler(FriendInfoRequest)
    def handle_frind_info_erro(self, request, resp, data):
        if not resp.body:
            self.handle_verify_callback(False, u"获取好友列表失败")
            return

        if data.get("retcode") != 0:
            self.handle_verify_callback(
                False, u"好友列表获取失败: {0}".format(data.get("retcode")))
            return
        self.handle_verify_callback(True)

    @kick_message_handler
    def handle_kick(self, message):
        self.hub.relogin()

    @system_message_handler
    def handle_friend_add(self, mtype, from_uin, account, message):
        if mtype == "verify_required":
            if getattr(config, "AUTO_ACCEPT", True):
                self.hub.accept_verify(from_uin, account, str(account))

    @group_message_handler
    def handle_group_message(self, member_nick, content, group_code, send_uin,
                             source):
        callback = partial(self.send_group_with_nick, member_nick, group_code)
        self.handle_message(send_uin, content, callback)

    @sess_message_handler
    def handle_sess_message(self, qid, from_uin, content, source):
        callback = partial(self.hub.send_sess_msg, qid, from_uin)
        self.handle_message(from_uin, content, callback, 's')

    def handle_message(self, from_uin, content, callback, type="g"):
        content = content.strip()
        if self.plug_loader.dispatch(from_uin, content, type, callback):
            self.msg_num += 1

    def send_group_with_nick(self, nick, group_code, content):
        content = u"{0}: {1}".format(nick, content)
        self.hub.send_group_msg(group_code, content)

    @buddy_message_handler
    def handle_buddy_message(self, from_uin, content, source):
        callback = partial(self.hub.send_buddy_msg, from_uin)
        self.handle_message(from_uin, content, callback, 'b')

    @register_request_handler(PollMessageRequest)
    def handle_qq_errcode(self, request, resp, data):
        if data and data.get("retcode") in [100006]:
            logger.error(u"获取登出消息 {0!r}".format(data))
            self.hub.relogin()

        if data and data.get("retcode") in [103]:  # 103重新登陆不成功, 暂时退出
            logger.error(u"获取登出消息 {0!r}".format(data))
            exit()

    def send_msg_with_markname(self, markname, message, callback=None):
        request = self.hub.send_msg_with_markname(markname, message)
        if request is None:
            callback(False, u"不存在该好友")

        self.message_requests[request] = callback

    @register_request_handler(BuddyMsgRequest)
    def markname_message_callback(self, request, resp, data):
        callback = self.message_requests.get(request)
        if not callback:
            return

        if not data:
            callback(False, u"服务端没有数据返回")
            return

        if data.get("retcode") != 0:
            callback(False, u"发送失败, 错误代码:".format(data.get("retcode")))
            return

        callback(True)

    def run(self, handler=None):
        self.handler = handler
        super(Client, self).run()
Esempio n. 4
0
class Client(WebQQClient):
    verify_img_path = None
    message_requests = {}
    start_time = time.time()
    msg_num = 0

    def handle_verify_code(self, path, r, uin):
        self.verify_img_path = path

        if getattr(config, "UPLOAD_CHECKIMG", False):
            logger.info(u"正在上传验证码...")
            res = self.hub.upload_file("check.jpg", self.hub.checkimg_path)
            logger.info(u"验证码已上传, 地址为: {0}".format(res.read()))

        if getattr(config, "HTTP_CHECKIMG", False):
            if hasattr(self, "handler") and self.handler:
                self.handler.r = r
                self.handler.uin = uin

            logger.info("请打开 http://{0}:{1} 输入验证码"
                        .format(config.HTTP_LISTEN, config.HTTP_PORT))
            if getattr(config, "EMAIL_NOTICE", False):
                if send_notice_email():
                    logger.info("发送通知邮件成功")
                else:
                    logger.warning("发送通知邮件失败")
        else:
            logger.info(u"验证码本地路径为: {0}".format(self.hub.checkimg_path))
            check_code = None
            while not check_code:
                check_code = raw_input("输入验证码: ")
            self.enter_verify_code(check_code, r, uin)

    def enter_verify_code(self, code, r, uin, callback=None):
        super(Client, self).enter_verify_code(code, r, uin)
        self.verify_callback = callback
        self.verify_callback_called = False

    @register_request_handler(BeforeLoginRequest)
    def handle_verify_check(self, request, resp, data):
        if not data:
            self.handle_verify_callback(False, "没有数据返回验证失败, 尝试重新登录")
            return

        args = request.get_back_args(data)
        scode = int(args[0])
        if scode != 0:
            self.handle_verify_callback(False, args[4])

    def handle_verify_callback(self, status, msg=None):
        if not hasattr(self, "plug_loader"):
            self.plug_loader = PluginLoader(self)

        if hasattr(self, "verify_callback") and callable(self.verify_callback)\
           and not self.verify_callback_called:
            self.verify_callback(status, msg)
            self.verify_callback_called = True

    @register_request_handler(Login2Request)
    def handle_login_errorcode(self, request, resp, data):
        if not resp.body:
            return self.handle_verify_callback(False, u"没有数据返回, 尝试重新登录")

        if data.get("retcode") != 0:
            return self.handle_verify_callback(False, u"登录失败: {0}"
                                               .format(data.get("retcode")))

    @register_request_handler(FriendInfoRequest)
    def handle_frind_info_erro(self, request, resp, data):
        if not resp.body:
            self.handle_verify_callback(False, u"获取好友列表失败")
            return

        if data.get("retcode") != 0:
            self.handle_verify_callback(False, u"好友列表获取失败: {0}"
                                        .format(data.get("retcode")))
            return
        self.handle_verify_callback(True)

    @kick_message_handler
    def handle_kick(self, message):
        self.hub.relogin()

    @system_message_handler
    def handle_friend_add(self, mtype, from_uin, account, message):
        if mtype == "verify_required":
            if getattr(config, "AUTO_ACCEPT", True):
                self.hub.accept_verify(from_uin, account, str(account))

    @group_message_handler
    def handle_group_message(self, member_nick, content, group_code,
                             send_uin, source):
        callback = partial(self.send_group_with_nick, member_nick, group_code)
        self.handle_message(send_uin, content, callback)

    @sess_message_handler
    def handle_sess_message(self, qid, from_uin, content, source):
        callback = partial(self.hub.send_sess_msg, qid, from_uin)
        self.handle_message(from_uin, content, callback, 's')

    @discu_message_handler
    def handle_discu_message(self, did, from_uin, content, source):
        nick = self.hub.get_friend_name(from_uin)
        callback = partial(self.send_discu_with_nick, nick, did)
        self.handle_message(from_uin, content, callback, 'g')

    def send_discu_with_nick(self, nick, did, content):
        content = u"{0}: {1}".format(nick, content)
        self.hub.send_discu_msg(did, content)

    def handle_message(self, from_uin, content, callback, type="g"):
        content = content.strip()
        if self.plug_loader.dispatch(from_uin, content, type, callback):
            self.msg_num += 1

    def send_group_with_nick(self, nick, group_code, content):
        content = u"{0}: {1}".format(nick, content)
        self.hub.send_group_msg(group_code, content)

    @buddy_message_handler
    def handle_buddy_message(self, from_uin, content, source):
        callback = partial(self.hub.send_buddy_msg, from_uin)
        self.handle_message(from_uin, content, callback, 'b')

    @register_request_handler(PollMessageRequest)
    def handle_qq_errcode(self, request, resp, data):
        if data and data.get("retcode") in [100006]:
            logger.error(u"获取登出消息 {0!r}".format(data))
            self.hub.relogin()

        if data and data.get("retcode") in [103]:  # 103重新登陆不成功, 暂时退出
            logger.error(u"获取登出消息 {0!r}".format(data))
            exit()

    def send_msg_with_markname(self, markname, message, callback=None):
        request = self.hub.send_msg_with_markname(markname, message)
        if request is None:
            callback(False, u"不存在该好友")

        self.message_requests[request] = callback

    @register_request_handler(BuddyMsgRequest)
    def markname_message_callback(self, request, resp, data):
        callback = self.message_requests.get(request)
        if not callback:
            return

        if not data:
            callback(False, u"服务端没有数据返回")
            return

        if data.get("retcode") != 0:
            callback(False, u"发送失败, 错误代码:".format(data.get("retcode")))
            return

        callback(True)

    def run(self, handler=None):
        self.handler = handler
        super(Client, self).run()
Esempio n. 5
0
        menu.options = S3OptionsMenu(controller).menu
        if not menu.options:
            # Fallback to an auto-generated list of resources
            # @ToDo
            pass
            #from eden.layouts import M
            #allmodels = models.__dict__
            #tables = []
            #for name in allmodels:
            #    if name == controller:
            #        for classname in allmodels[name].__all__:
            #            for tablename in models[controller][classname].names:
            #                tables.append(tablename)
            #menu.options = M(c=controller)(
            #    M(resourcename, f=resourcename)(
            #        M("New", m="create"),
            #        M("List All"),
            #    ),
            #)

    else:
        # Use custom menu
        menu.options = s3_menu_dict[controller]

    # Add breadcrumbs
    menu.breadcrumbs = S3OptionsMenu.breadcrumbs

# Set up plugins
from plugins import PluginLoader
PluginLoader.setup_all()
Esempio n. 6
0
        menu.options = S3OptionsMenu(controller).menu
        if not menu.options:
            # Fallback to an auto-generated list of resources
            # @ToDo
            pass
            #from eden.layouts import M
            #allmodels = models.__dict__
            #tables = []
            #for name in allmodels:
            #    if name == controller:
            #        for classname in allmodels[name].__all__:
            #            for tablename in models[controller][classname].names:
            #                tables.append(tablename)
            #menu.options = M(c=controller)(
            #    M(resourcename, f=resourcename)(
            #        M("New", m="create"),
            #        M("List All"),
            #    ),
            #)

    else:
        # Use custom menu
        menu.options = s3_menu_dict[controller]

    # Add breadcrumbs
    menu.breadcrumbs = S3OptionsMenu.breadcrumbs

# Set up plugins
from plugins import PluginLoader
PluginLoader.setup_all()