def run(self): while True: msgs = self.data.get() print msgs for msg in msgs: if msg['type'] == u'message': self.qq.sendMessage(msg['from'], ai.magic(msg['data']), "uin") elif msg['type'] == u'group_message': self.qq.sendGroupMessage(msg['from'], ai.magic(msg['data']), "uin")
def reply(data, message): # 不要自问自答 if 'author_name' in data and '小黄鸡' in data['author_name'].encode('utf-8'): return data['message'] = magic(message) current_bot_index = int(r.get('current_bot_index') or 0) bot = bots[current_bot_index] result = bot.addComment(data) # 如果连续8次遇到 code 1031,则认为被封了,换下一个账号 if result['code'] == 1031: reach_limit_time, MAX_LIMIT_TRY = r.incr('reach_limit_time'), 8 if int(reach_limit_time) == MAX_LIMIT_TRY: r.set('reach_limit_time', 0) current_bot_index = r.incr('current_bot_index') if int(current_bot_index) >= len(bots): r.set('current_bot_index', 0) raise Exception('SHIT!!!!!!ALL BOTS ARE DOWN!!!!!!!!!!') else: raise Exception('bot %s reach comment limit' % bot.email) else: print 'maybe comment limit', bot.email elif result['code'] == 0: r.set('reach_limit_time', 0) else: raise Exception('Error sending comment by bot %s' % bot.email)
def reply(data): bot = bots[0] # 现在只有一只小鸡了,且没了评论限制 data, message = getNotiData(bot, data) if not data: return # 不要自问自答 if 'author_name' in data and '小黄鸡' in data['author_name'].encode('utf-8'): return print 'handling comment', data, '\n' data['message'] = questionfilter(message) answer = magic(data, bot) data['message'] = answerfilter(answer) result = bot.addComment(data) code = result['code'] if code == 0: return if code == 10: print 'some words are blocked' else: raise Exception('Error sending comment by bot %s' % bot.email)
def reply(data): bot = bots[0] # 现在只有一只小鸡了,且没了评论限制 data, message = getNotiData(bot, data) if not data: return # 不要自问自答 if '小黄鸡' in data.get('author_name', u'').encode('utf-8'): return print 'handling comment', data, '\n' data['message'] = questionfilter(message) answer = magic(data, bot) data['message'] = answerfilter(answer) result = bot.addComment(data) code = result['code'] if code == 0: return if code == 10: print 'some words are blocked' else: raise Exception('Error sending comment by bot %s' % bot.email)
def reply(data, message): # 不要自问自答 if 'author_name' in data and '小黄鸡' in data['author_name'].encode('utf-8'): return data['message'] = magic(message) current_bot_index = int(r.get('current_bot_index') or 0) bot = bots[current_bot_index] result = bot.addComment(data) # 如果连续5次遇到 code 1031,则认为被封了,换下一个账号 if result['code'] == 1031: reach_limit_time, MAX_LIMIT_TRY = r.incr('reach_limit_time'), 5 if int(reach_limit_time) == MAX_LIMIT_TRY: r.set('reach_limit_time', 0) current_bot_index = r.incr('current_bot_index') if int(current_bot_index) >= len(bots): r.set('current_bot_index', 0) raise Exception('SHIT!!!!!!ALL BOTS ARE DOWN!!!!!!!!!!') else: raise Exception('bot %s reach comment limit' % bot.email) else: print 'maybe comment limit', bot.email elif result['code'] == 0: r.set('reach_limit_time', 0) else: raise Exception('Error sending comment by bot %s' % bot.email)
def reply(data, message): # 不要自问自答 if 'author_name' in data and '小黄鸡' in data['author_name'].encode('utf-8'): return data['message'] = answerfilter(magic(questionfilter(message))) bot = bots[0] # 现在只有一只小鸡了,且没了评论限制 result = bot.addComment(data) if result['code'] != 0: raise Exception('Error sending comment by bot %s' % bot.email)
def reply(data): bot = bots[0] # 现在只有一只小鸡了,且没了评论限制 data, message = getNotiData(bot, data) if not data: return # 不要自问自答 if 'author_name' in data and '小黄鸡' in data['author_name'].encode('utf-8'): return print 'handling comment', data, '\n' data['message'] = answerfilter(magic(questionfilter(message))) result = bot.addComment(data) if result['code'] != 0: raise Exception('Error sending comment by bot %s' % bot.email)
def process(data): data['CreateTime'] = int(data['CreateTime']) return magic(data)
cityFlag = False for city in cityidDict.keys(): if unicode2GB18030(city) in _reply: re_info = hanzi(getweather(city.encode('utf8'))) cityFlag = True break if not cityFlag: re_info = hanzi(getweather('武汉')) else: pass elif hanzi('笑话') in _reply or hanzi('讲笑话') in _reply or hanzi('讲个笑话') in _reply: re_info = hanzi(keyword_getResponse(1, '61')) elif hanzi('故事') in _reply or hanzi('讲故事') in _reply or hanzi('讲个故事') in _reply: re_info = hanzi(keyword_getResponse(2, '381')) else: # SimSimi获取 re_info = hanzi(magic(_reply.decode('GB18030'))) log.i(re_info) print re_info # 判断是否有敏感词 tf, sw = specialWords(sensitiveWordsList, re_info) if tf: log.i(hanzi('敏感词: ') + sw) print hanzi('敏感词: '), sw re_info = hanzi('昔人已乘黄鹤去,此地空余黄鹤楼。黄鹤一去不复返,白云千载空悠悠') else: pass # 回帖 bbssnd = BBSSND('Re:' + title, re_info + os.linesep + os.linesep.join(content)) bbssnd.bbssnd('http://byhh.net/cgi-bin/' + bbssnd_url, cookie)