Exemple #1
0
def getWeibo(delay):
    bot = CQHttp(api_root='http://127.0.0.1:5700/')
    while True:
        global weibo_id_array
        global firstcheck_weibo
        wbcontent = ''
        idcount = -1
        if (firstcheck_weibo == 1):
            weibo_id_array = copy.copy(getidarray())
            firstcheck_weibo = False
        checkwbid = copy.copy(get_5_idarray())
        if (firstcheck_weibo == 0):
            for cardid in checkwbid:
                idcount += 1
                if int(cardid) == 0:
                    continue
                if cardid not in weibo_id_array:
                    weibo_id_array.append(cardid)
                    retweet = checkretweet(idcount)
                    wbpic = checkpic(idcount)
                    wbscheme = getscheme(idcount)
                    if (retweet):
                        wbcontent = "源源刚刚[转发]了一条微博:" + '\n' + '\n' + getretweetweibo(idcount) + '\n'
                        wbcontent = wbcontent + '\n' + "传送门:" + wbscheme
                    else:
                        wbcontent = "源源刚刚发了一条新微博:" + '\n' + '\n' + getweibo(idcount) + '\n'
                        if (wbpic):
                            wbcontent = wbcontent + getpic(idcount)
                        wbcontent = wbcontent + '\n' + "传送门:" + wbscheme
                    bot.send_group_msg_async(group_id=groupid(), message=wbcontent, auto_escape=False)
        time.sleep(int(delay))
Exemple #2
0
def getModian(delay):
    bot = CQHttp(api_root='http://127.0.0.1:5700/')
    while True:
        stampTime = int(time.time())
        msgDict = newOrder(stampTime, int(delay))
        if msgDict:
            for msg in msgDict['msg']:
                msg += msgDict['end']
                bot.send_group_msg_async(group_id=groupid(), message=msg, auto_escape=False)
                time.sleep(0.1)
        time.sleep(int(delay))
Exemple #3
0
class ListenKdMdWb(QThread):
    def __init__(self, kd, md, wb):
        super(QThread, self).__init__()
        self.switch_kd = kd
        self.switch_md = md
        self.switch_wb = wb
        self.sched = BlockingScheduler()
        self.weibo_id_array = []
        self.firstcheck_weibo = True
        self.pref3 = Preferences()
        self.api_root_url = 'http://127.0.0.1:%s/' % self.pref3.getapi_root_port(
        )
        self.bot = CQHttp(api_root=self.api_root_url)
        self.version_dict = self.bot.get_version_info()
        self.version = self.version_dict['coolq_edition']

    def run(self):
        if self.switch_md:
            self.interval_md = int(self.pref3.getmdinterval())
            self.sched.add_job(self.getmodian,
                               'interval',
                               seconds=self.interval_md,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        if self.switch_wb:
            self.interval_wb = int(self.pref3.getwbinterval())
            self.sched.add_job(self.getweibo,
                               'interval',
                               seconds=self.interval_wb,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        if self.switch_kd:
            self.interval_kd = int(self.pref3.getkdinterval())
            self.sched.add_job(self.getkoudai,
                               'interval',
                               seconds=self.interval_kd,
                               misfire_grace_time=10,
                               coalesce=True,
                               max_instances=2)
        self.sched.start()

    def getmodian(self):
        try:
            INFO('check modian')
            stampTime = int(time.time())
            msgDict_array = newOrder(stampTime, int(self.interval_md))
            for msgDict in msgDict_array[0:-1]:
                if msgDict:
                    for msg in msgDict['msg']:
                        msg += msgDict['end']
                        print(msg)
                        for grpid in self.pref3.getqqidarray():
                            self.bot.send_group_msg_async(group_id=grpid,
                                                          message=msg,
                                                          auto_escape=False)
                            time.sleep(0.1)
        except Exception as e:
            WARN('error when getModian', e, "modian dict:", msgDict_array[-1])
        finally:
            INFO('modian check completed')

    def getweibo(self):
        try:
            weibo = Weibo()
            INFO('check weibo')
            # 初次启动记录前十条微博id
            if self.firstcheck_weibo is True:
                INFO('first check weibo')
                self.weibo_id_array = weibo.IdArray
                self.firstcheck_weibo = False
            if self.firstcheck_weibo is False:
                # 取最新的前三条微博
                for idcount in range(0, 3):
                    # 广告位微博id为0,忽略
                    if int(weibo.IdArray[idcount]) == 0:
                        continue
                    # 微博id不在记录的id列表里,判断为新微博
                    if weibo.IdArray[idcount] not in self.weibo_id_array:
                        msg = []
                        # 将id计入id列表
                        self.weibo_id_array.append(weibo.IdArray[idcount])
                        # 检查新微博是否是转发
                        if weibo.checkRetweet(idcount):
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '小偶像刚刚转发了一条微博:\n'
                                }
                            })
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text':
                                    '%s\n' % weibo.getRetweetWeibo(idcount)
                                }
                            })
                        # 原创微博
                        else:
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '小偶像刚刚发了一条新微博:\n'
                                }
                            })
                            msg.append({
                                'type': 'text',
                                'data': {
                                    'text': '%s\n' % weibo.getWeibo(idcount)
                                }
                            })
                            # 检查原创微博是否带图
                            if weibo.checkPic(idcount):
                                # 只取第一张图,pro可以直接发图,air则无
                                msg.append({
                                    'type': 'image',
                                    'data': {
                                        'file': '%s' % weibo.getPic(idcount)[0]
                                    }
                                })
                                # 播报图的总数
                                if len(weibo.getPic(idcount)) > 1:
                                    msg.append({
                                        'type': 'text',
                                        'data': {
                                            'text':
                                            '\n(一共有%d张图喔)\n' %
                                            len(weibo.getPic(idcount))
                                        }
                                    })
                        msg.append({
                            'type': 'text',
                            'data': {
                                'text': '传送门:%s' % weibo.getScheme(idcount)
                            }
                        })
                        for grpid in self.pref3.getqqidarray():
                            self.bot.send_group_msg_async(group_id=grpid,
                                                          message=msg,
                                                          auto_escape=False)
                            time.sleep(0.5)
                        print(msg)
        except Exception as e:
            WARN('error when getWeibo', e)
        finally:
            INFO('weibo check completed')

    def getkoudai(self):
        try:
            INFO('check koudai room')
            koudai = Koudai()
            # 检查是否有新消息
            if koudai.checkNew():
                INFO('have new room msg')
                # 判断酷Q版本
                if self.version == 'air':
                    msgArray = koudai.msgAir()
                elif self.version == 'pro':
                    msgArray = koudai.msgPro()
                # 消息序列反向排序
                msgArray.reverse()
                for msg in msgArray:
                    print(msg)
                    for grpid in self.pref3.getqqidarray():
                        self.bot.send_group_msg_async(group_id=grpid,
                                                      message=msg,
                                                      auto_escape=False)
                        time.sleep(0.5)
        except Exception as e:
            WARN('error when getRoomMsg', e)
            raise e
        finally:
            INFO('koudai check completed')