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'])
评论列表
文章目录