GaTextHook.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:WechatForwardBot 作者: grapeot 项目源码 文件源码
def process(self, msg, type):
        if type != TEXT:
            return
        groupName = msg['User']['NickName']
        toSend = None
        if any([ re.search(x, groupName) is not None for x in self.blacklist ]):
            return
        if re.search(self.forceTriggerText, msg['Content']):
            currentTime = time()
            gaNextTime = self.forceTriggerNextTimestamp.get(groupName, 0)
            if currentTime < gaNextTime:
                logging.info("Don't force Ga because time {0} < NextTime {1} for group {2}.".format(currentTime, gaNextTime, groupName))
                return;
            self.forceTriggerNextTimestamp[groupName] = currentTime + self.forceTriggerInterval
            toSend = self.forceTriggerGaText
            logging.info('{0} => {1}'.format(msg['Content'], toSend))
            itchat.send(toSend, msg['FromUserName'])
            return
        if re.search(self.triggerText, msg['Content']):
            # Check the ga time
            if groupName not in GaTextHook.gaNumDict:
                GaTextHook.gaNumDict[groupName] = 0
            GaTextHook.gaNumDict[groupName] += 1
            self.gaColl.update({'GroupName': groupName}, {'$set': { 'CurrentGaNum': GaTextHook.gaNumDict[groupName] } }, upsert=True)
            if GaTextHook.gaNumDict[groupName] > self.gaNumMax:
                logging.info("Don't Ga because GaNum {0} exceeds max {1} for group {2}.".format(GaTextHook.gaNumDict[groupName], self.gaNumMax, groupName))
                return
            toSend = '{0} x{1}'.format(self.gaText, GaTextHook.gaNumDict[groupName])
            logging.info('{0} => {1}'.format(msg['Content'], toSend))
            itchat.send(toSend, msg['FromUserName'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号