def reply_text(self, msg): """ 仅返回答复文本 :param msg: Message 对象,或消息文本 :return: 答复文本 """ error_response = ( "主人还没给我设置这类话题的回复", ) if isinstance(msg, Message): user_id = get_context_user_id(msg) question = get_text_without_at_bot(msg) else: user_id = "abc" question = msg or "" params = { "question": question, "format": "json", "platform": "custom", "userId": user_id, } resp = self.session.post(self.url, data=params) text = resp.text for err in error_response: if err in text: return next_topic() return text
def reply_text(self, msg): """ 仅返回答复文本 :param msg: Message 对象,或消息文本 :return: 答复文本 """ error_response = ("主人还没给我设置这类话题的回复", ) if isinstance(msg, Message): user_id = get_context_user_id(msg) question = get_text_without_at_bot(msg) else: user_id = "abc" question = msg or "" params = { "question": question, "format": "json", "platform": "custom", "userId": user_id, } resp = self.session.post(self.url, data=params) text = resp.text for err in error_response: if err in text: return next_topic() return text
def do_reply(self, msg): que = [ u'报时', u'每日一句', u'猜谜', u'糗事', u'空气质量', u'藏头诗', u'梦见', u'一言', u'什么是', u'脑筋急转弯' ] if isinstance(msg, Message): user_id = get_context_user_id(msg) if msg.text.startswith(u'小鱼儿'): question = msg.text.replace(u'小鱼儿', '').strip() else: question = get_text_without_at_bot(msg) else: user_id = "abc" question = msg or "" url = 'http://api.douqq.com' params = {'key': self.key, 'msg': question} #params = {'key': self.key, 'msg': msg} #print question if question in que or u'求答案' in question or u'谜底' in question: try: resp = requests.get(url, params=params) ret = '@' + msg.member.name + ' ' + resp.text msg.reply(ret) #except requests.exceptions.RequestException: except: return self.DEFAULT_MSG return resp.text else: return self.DEFAULT_MSG
def operations(msg): if True or msg.is_at: text = get_text_without_at_bot(msg).strip() if '今日打卡' == text: send_report() elif '打卡改名为' in text: if msg.sender != bot.self: return "没有权限" origin, new = text.split('打卡改名为') session = Session() sharings = session.query(Sharing).filter( Sharing.name.like('%' + origin + '%')).all() for s in sharings: s.name = new session.commit()
def reply_text(self, msg, use_xiaoi): """ 仅返回答复文本 :param msg: Message 对象,或消息文本 :return: 答复文本 """ error_response = ("主人还没给我设置这类话题的回复", ) if isinstance(msg, Message): user_id = get_context_user_id(msg) self.user_id = user_id if msg.text.startswith(u'小鱼儿'): question = msg.text.replace(u'小鱼儿,', '').replace(u'小鱼儿', '').strip() else: question = get_text_without_at_bot(msg) else: user_id = "abc" question = msg or "" params = { "question": question, "format": "json", "platform": "custom", "userId": user_id, } if question == u'功能' or question == u'菜单' or question == u'你会什么': text = '聊天:任意语句\n查询天气:城市名+天气\n讲笑话:讲个笑话\n\ 计算器:678*3455\n查询火车票:北京到天津火车票\n查询星座:星座+运势;7月1日是什么星座\n心理测试:心理测试\n成语接龙:成语接龙\n\ 玩游戏:逃出房间;恐怖医院;一站到底\n手机号运势查询:手机号后四位+手机号运势' elif len(question) == 0: text = '在呢' elif question == u'你好' or question == u'您好': text = '你好,很高兴认识你。' elif question == u'备注' or question == u'备注模板': text = '%s-男-90-工作-本' % (msg.member.nick_name) elif question == u'彩蛋' or question == u'egg': text = self.egg elif question == u'群规' or question == u'群规是什么': text = self.group_role elif u'主人是谁' in question: text = '我的主人是Kevin。' elif u'送我一个男盆友' in question or u'送我一个男朋友' in question: text = '长得丑,想的美,说的就说你。' elif u'什么时候脱单' in question: text = '他来了缘聚,他走了缘散,你找他缘起,你不找他了缘灭。' elif u'双十一怎么过' in question: text = '买买买。。' elif u'和谁跨年' in question: text = '当然是我喜欢的人呀' elif u'你喜欢谁' in question: text = '我喜欢小姐姐啦,哈哈~~~' elif u'我爱你' in question and msg.member.nick_name == u'沐沐': text = '我也爱你哦,小姐姐,mua~' elif u'我喜欢你' in question and msg.member.nick_name == u'沐沐': text = '我也喜欢你哦,小姐姐,mua~' elif u'我想你了' in question and msg.member.nick_name == u'沐沐': text = '彼此彼此啦,嘿嘿,nua~' elif u'啥时脱单' in question: text = '缘分到了就脱单啦!' elif u'叫他出来' in question or u'你主人出来' in question: text = '你自己不会叫啊' elif u'谁最丑' in question or u'谁最难看' in question: text = '是你,是你,就是你喽~' elif u'最帅' in question: text = '还用问么,当然我主人啦,哈哈哈' elif u'最美' in question or u'最漂亮' in question: text = '是超级无敌可爱小姐姐哦,哈哈哈' elif u'我发红包' in question: text = '你先给我发一个吧' elif u'你发红包' in question: text = '赶紧发吧' elif u'群统计' in question or u'男女比例' in question: msg.sender.update_group(True) text = msg.sender.members.stats_text() elif u'发言频率' in question or u'聊天排行榜' in question: grouplog = analyze.GroupLog( hashlib.md5(msg.sender.name.encode('utf-8')).hexdigest()[-8:], self.log_dir) text = grouplog.log_context() elif question.startswith(u'表情包'): new_msg_total = question.split(u'表情包')[1] #msg.reply(new_msg) pic_num = new_msg_total[0:1] if pic_num == '1': new_msg = new_msg_total[1:] else: new_msg = new_msg_total express.Make_express().make_pic(new_msg, pic_num) #msg.reply_image('material/target.jpg') text = 'express_pic' elif question == u'小鱼儿休息' or question == u'小鱼儿休息一下吧': if msg.member.nick_name == 'Kevin': use_xiaoi = 0 text = '好的' else: text = u'我只听主人的哦。' elif question == u'小鱼儿干活' or question == u'小鱼儿起来干活': if msg.member.nick_name == 'Kevin': use_xiaoi = 1 text = '好的' else: text = u'我只听主人的哦。' else: text = '1' #for err in error_response: # if err in text: # return next_topic() return text, use_xiaoi
def reply_text(self, msg, at_member=True): """ 仅返回消息的答复文本 :param msg: Message 对象 :param at_member: 若消息来自群聊,回复时 @发消息的群成员 :return: 答复文本 :rtype: str """ def process_answer(): logger.debug('Tuling answer:\n' + pprint.pformat(answer)) ret = str() if at_member: if len(msg.chat ) > 2 and msg.member.name and not self.is_last_member(msg): ret += '@{} '.format(msg.member.name) code = -1 if answer: code = answer.get('code', -1) if code >= 100000: text = answer.get('text') if not text or (text == msg.text and len(text) > 3): text = next_topic() url = answer.get('url') items = answer.get('list', list()) ret += str(text) if url: ret += '\n{}'.format(url) for item in items: ret += '\n\n{}\n{}'.format( item.get('article') or item.get('name'), item.get('detailurl')) else: ret += next_topic() return ret def get_location(_chat): province = getattr(_chat, 'province', None) or '' city = getattr(_chat, 'city', None) or '' if province in ('北京', '上海', '天津', '重庆'): return '{}市{}区'.format(province, city) elif province and city: return '{}省{}市'.format(province, city) if not msg.bot: raise ValueError('bot not found: {}'.format(msg)) if not msg.text: return from wxpy.api.chats import Group if at_member and isinstance(msg.chat, Group) and msg.member: location = get_location(msg.member) else: # 使该选项失效,防止错误 @ 人 at_member = False location = get_location(msg.chat) user_id = get_context_user_id(msg) if location: location = location[:30] info = str(get_text_without_at_bot(msg))[-30:] payload = dict(key=self.api_key, info=info, userid=user_id, loc=location) logger.debug('Tuling payload:\n' + pprint.pformat(payload)) # noinspection PyBroadException try: r = self.session.post(self.url, json=payload) answer = r.json() except: answer = None finally: return process_answer()
def reply_text(self, msg, at_member=True): """ 仅返回消息的答复文本 :param msg: Message 对象 :param at_member: 若消息来自群聊,回复时 @发消息的群成员 :return: 答复文本 :rtype: str """ def process_answer(): logger.debug('Tuling answer:\n' + pprint.pformat(answer)) ret = str() if at_member: if len(msg.chat) > 2 and msg.member.name and not self.is_last_member(msg): ret += '@{} '.format(msg.member.name) code = -1 if answer: code = answer.get('code', -1) if code >= 100000: text = answer.get('text') if not text or (text == msg.text and len(text) > 3): text = next_topic() url = answer.get('url') items = answer.get('list', list()) ret += str(text) if url: ret += '\n{}'.format(url) for item in items: ret += '\n\n{}\n{}'.format( item.get('article') or item.get('name'), item.get('detailurl') ) else: ret += next_topic() return ret def get_location(_chat): province = getattr(_chat, 'province', None) or '' city = getattr(_chat, 'city', None) or '' if province in ('北京', '上海', '天津', '重庆'): return '{}市{}区'.format(province, city) elif province and city: return '{}省{}市'.format(province, city) if not msg.bot: raise ValueError('bot not found: {}'.format(msg)) if not msg.text: return from wxpy.api.chats import Group if at_member and isinstance(msg.chat, Group) and msg.member: location = get_location(msg.member) else: # 使该选项失效,防止错误 @ 人 at_member = False location = get_location(msg.chat) user_id = get_context_user_id(msg) if location: location = location[:30] info = str(get_text_without_at_bot(msg))[-30:] payload = dict( key=self.api_key, info=info, userid=user_id, loc=location ) logger.debug('Tuling payload:\n' + pprint.pformat(payload)) # noinspection PyBroadException try: r = self.session.post(self.url, json=payload) answer = r.json() except: answer = None finally: return process_answer()