Exemplo n.º 1
0
 def __init__(self):
     super(Koudai, self).__init__()
     # 获取系统时间和配置文件时间
     self.sysTime13 = self.getSysTime13()
     self.cfgTime13 = self.getCfgTime13()
     # 请求一次口袋房间
     res = self.getMainpage()
     # 请求成功
     if res['status'] == 200:
         # 获取response
         self.response = res
         # 获取最新口袋消息时间
         self.kdmsgTime13 = self.getKdmsgTime13()
     elif res['status'] == 401:
         WARN('koudai48.py授权验证失败')
         if not setting.token_verify():
             WARN('token失效,尝试获取新token')
             setting.getNewToken()
     else:
         WARN('获取口袋房间信息出错', res['message'])
Exemplo n.º 2
0
def get_juju(bot):
    global msgTime_array
    global firstcheck_juju
    # 仅需修改播报的qq群昵称
    gl = bot.List('group', groupid)
    if gl is not None:
        ajax_url = 'https://pjuju.48.cn/imsystem/api/im/v1/member/room/message/mainpage'
        header = {
            'Host': 'pjuju.48.cn',
            'version': '5.0.1',
            'os': 'android',
            'Accept-Encoding': 'gzip',
            'IMEI': '866716037825810',
            'User-Agent': 'Mobile_Pocket',
            'Content-Length': '67',
            'Connection': 'Keep-Alive',
            'Content-Type': 'application/json;charset=utf-8',
            'token': setting.token()
        }
        form = {
            "lastTime": 0,
            "limit": 10,
            "chatType": 0,
            "roomId": setting.roomId()
        }
        response = requests.post(
            ajax_url,
            data=json.dumps(form),
            headers=header,
            verify=False,
            proxies=setting.proxy()
        ).json()
        INFO('聚聚房间request一次')
        if response['status'] == 200:
            datas = response['content']['data']
            # first check
            if firstcheck_juju == 0:
                for data in datas:
                    msgTime_array.append(data['msgTime'])
                firstcheck_juju = 1
            #
            # 控制list长度
            msgTime_array = msgTime_array[-10:]
            #
            # 初始化消息队列
            msg_array = []
            #
            for data in datas:
                msg = ''
                # 判断重复
                msgTime_array = sorted(msgTime_array)
                if data['msgTime'] in msgTime_array or data['msgTime'] < msgTime_array[0]:
                    continue
                else:
                    msgTime_array.append(data['msgTime'])
                #
                # 文字消息
                extInfo = json.loads(data['extInfo'])
                if data['msgType'] == 0:
                    if extInfo['messageObject'] == 'text':
                        msg = ('%s:%s\n%s' % (extInfo['senderName'], extInfo['text'], data['msgTimeStr']))
                    elif extInfo['messageObject'] == 'faipaiText':
                        # 20171221 16:38 黄子璇(roomid=9108720)发生err:翻牌信息未返回faipaiName
                        try:
                            msg = ('%s:%s\n%s:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], extInfo['faipaiName'], extInfo['faipaiContent'], data['msgTimeStr']))
                        except:
                            msg = ('%s:%s\n翻牌:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], extInfo['faipaiContent'], data['msgTimeStr']))
                        #
                    elif extInfo['messageObject'] == 'live':
                        msg = ('小偶像开视频直播啦 \n 直播标题:%s \n 直播封面:%s \n开始时间:%s \n 直播地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId']))
                    elif extInfo['messageObject'] == 'diantai':
                        msg = ('小偶像开电台啦 \n 电台标题:%s \n 电台封面:%s \n开始时间:%s \n 电台地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId']))
                    elif extInfo['messageObject'] == 'idolFlip':
                        # INFO('idol翻牌')
                        msg = ('%s:%s\n问题内容:%s\n%s' % (extInfo['senderName'], extInfo['idolFlipTitle'], extInfo['idolFlipContent'], data['msgTimeStr']))
                        pass
                    else:
                        msg = '有未知格式的文字消息'
                        WARN('有未知格式的文字消息')
                        WARN(data)
                # image
                elif data['msgType'] == 1:
                    bodys = json.loads(data['bodys'])
                    msg = ('【口袋48房间图片】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr']))
                # voice
                elif data['msgType'] == 2:
                    bodys = json.loads(data['bodys'])
                    msg = ('【口袋48房间语音】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr']))
                # video
                elif data['msgType'] == 3:
                    bodys = json.loads(data['bodys'])
                    msg = ('【口袋48房间视频】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr']))
                else:
                    msg = '有未知类型的消息'
                    WARN('有未知类型的消息')
                    WARN(data)
                msg_array.append(msg)
        # 获取失败,检查token
        elif response['status'] == 401 and response['message'] == '授权验证失败':
            WARN('koudai48.py授权验证失败')
            if not setting.token_verify():
                WARN('token失效,尝试获取新token')
                setting.getNewToken()
        else:
            WARN('获取口袋房间信息出错')
            WARN(response['message'])
        for group in gl:
            if msg_array:
                msg_array.reverse()
                for msgdata in msg_array:
                    bot.SendTo(group, msgdata)