def msg_yy(msg): """ 微信web版无法邀请好友入群 if msg.text == u'北京': msg.reply('北京交流群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_beijing = self.bot.groups().search(u'北京交流群')[0] group_beijing.add_members(new_friend, use_invitation=True) elif msg.text == u'小群': msg.reply('北京小群') group_tianjin = self.bot.groups().search(u'人工智能体验群')[0] new_friend = self.bot.friends().search(msg.sender.name)[0] self.friend.send(new_friend) group_tianjin.add_members(new_friend, use_invitation=True) """ if msg.sender.name == 'Kevin': try: send_kevin =12 if send_kevin == 1: msg.reply('Hello') except Exception as e: logger.error(e) else: if msg.text == u'你好': try: msg.reply(u'你好') except Exception as e: logger.error(e)
def msg_yy(msg): #ret_text, self.use_xiaoi = self.xiaoyuer.do_reply(msg,self.use_xiaoi) #微信web版无法邀请好友入群 if u'我通过了你的朋友验证请求' in msg.text or u"现在我们可以开始聊天了" in msg.text: msg.reply('欢迎加入北京芊芊结1群,加入更多群请回复:加群') msg.reply_image("material/zaoan.png") new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结1群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'入群' or msg.text == "加群": msg.reply('回复相应数字即可发送群邀请\n1. 北京芊芊结1群\n\ 2. 北京芊芊结C群\n3. 缘来是你北京交友群\n4. 机器人小鱼儿聊天群') elif msg.text == u'3': msg.reply('缘来是你北京交友群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_beijing = self.bot.groups().search(u'北京交友群')[0] group_beijing.add_members(new_friend, use_invitation=True) elif msg.text == u'1': msg.reply('北京芊芊结1群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结1群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'4': msg.reply('机器人小鱼儿聊天群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'机器人小鱼儿聊天群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'2': msg.reply('北京芊芊结C群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结C群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'5': msg.reply('北京芊芊结单身5群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结单身5群')[0] group_add.add_members(new_friend, use_invitation=True) if msg.sender.name == 'Kevin': try: send_kevin = 12 if send_kevin == 1: msg.reply('Hello') except Exception as e: logger.error(e) else: #msg.reply(u'这话我没法接') if msg.text == u'你好': try: msg.reply(u'你好') except Exception as e: logger.error(e)
def send_message(self): #self.group_note_list = [u'测试专用群'] #print self.group_note_list for group_n in self.group_note_list: try: my_group = self.bot.groups().search(group_n)[0] except IndexError,e: logger.error('%s not exists, please check it!' %group_n) continue #group_name = hashlib.md5(my_group.name.encode('utf-8')).hexdigest()[-8:] group_members = analyze.GroupMembers(self.path, my_group) group_members.analyze_mem()
def use_sche(self): #if self.send_me == 1: #self.send_message() #schedule.every().day.at("17:17").do(self.send_message) #schedule.every(10).minutes.do(self.send_message) schedule.every().day.at("7:30").do(self.send_group_msg,u'早上好') while True: #self.myself.send('log out') if not self.bot.alive: logger.error('not login') self.main() break schedule.run_pending() time.sleep(10)
def print_mp_msg(msg): #self.friend.send(msg) #self.friend.send_raw_msg( raw_content=msg.raw) #msg.forward(self.friend) """ if msg.type == SHARING and msg.sender.name == '爱净意': for article in msg.articles: if '第壹简报' in article.title: self.friend.send(article.title) self.friend.send(article.url) #article_url = 'https://mp.weixin.qq.com/s/5E_SGRmaDA9O1nZgjGG0mw' jb = jianbao.Get_Jianbao(article.url) jb_content = jb.out_jianbao() logger.info(jb_content) self.friend.send(jb_content) if msg.type == SHARING and msg.sender.name == '硕士博士俱乐部': for article in msg.articles: if '妹子篇' in article.title: self.friend.send(article.title) self.friend.send(article.url) if msg.type == SHARING and msg.sender.name == '硕博联谊': for article in msg.articles: if '妹子' in article.title and '现居北京' in article.title: self.friend.send(article.title) self.friend.send(article.url) """ #if msg.type == SHARING and msg.sender.name == '简报微刊': if msg.type == SHARING and msg.sender.name == '第壹简报': for article in msg.articles: #if '简报微刊' in article.title: if '第壹简报' in article.title: #self.friend.send(article.title) #self.friend.send(article.url) jb = jianbao.Get_Jianbao(article.url) jb_content = jb.out_jianbao() self.jb_content = jb_content #self.friend.send(jb_content) for group_n in self.group_jianbao_list: try: my_group = self.bot.groups().search(group_n)[0] my_group.send(jb_content) except IndexError, e: logger.error( '%s not exists, please check it!' % val)
def use_sche(self): #if self.send_me == 1: #self.send_message() #schedule.every().day.at("17:17").do(self.send_message) #schedule.every(10).minutes.do(self.send_message) schedule.every().day.at("08:00").do(self.send_friend_msg, self.send_morning) #schedule.every().day.at("22:30").do(self.send_friend_msg,self.send_night) #schedule.every().day.at("10:20").do(self.send_friend_msg,u"@all 休息一下吧,该喝水了!") #schedule.every().day.at("11:30").do(self.send_friend_msg,u"@all 该吃午饭了!") #schedule.every().day.at("13:00").do(self.send_friend_msg,u"@all 午休时间到!") #schedule.every().day.at("16:00").do(self.send_friend_msg,u"@all 休息一下吧,该喝水了!") while True: #self.myself.send('log out') if not self.bot.alive: logger.error('not login') self.main() break schedule.run_pending() time.sleep(10)
def msg_yy(msg): #create log file day = time.strftime("%Y-%m-%d") file_name = '%s.txt' % (day) file_ab_path = os.path.join(self.friends_path, file_name) create_time = msg.create_time.strftime('%Y-%m-%d %H:%M:%S') #pic_file = os.path.join(self.path,group_name,day) #if not os.path.exists(pic_file): #os.mkdir(pic_file) #ret_text, self.use_xiaoi = self.xiaoyuer.do_reply(msg,self.use_xiaoi) #微信web版无法邀请好友入群 if msg.type == PICTURE: word_text = "PICTURE:%s" % (msg.file_name) ct = msg.create_time.strftime('%Y-%m-%d-%H-%M-%S') msg.get_file('%s/%s-%s-%s' % (self.friends_pic_path, ct, random.randint( 1, 10), msg.file_name)) #if msg.file_name.endswith(".png"): # new_friend = self.bot.friends().search(msg.sender.name)[0] # group_add = self.bot.groups().search(self.invite_group2)[0] # group_add.add_members(new_friend, use_invitation=True) #group_beijing = self.bot.groups().search(self.invite_group3)[0] #group_beijing.add_members(new_friend, use_invitation=True) elif msg.type == TEXT: word_text = msg.text ''' print self.friends_accept #if self.friends_accept and (u'我通过了你的朋友验证请求' in msg.text or u"现在我们可以开始聊天了" in msg.text): if self.friends_accept and u'我通过了你的朋友验证请求' in msg.text: msg.reply('嗨,您好!欢迎你加入芊芊结北京单身群,为了保证群内良好的交流与互动,请进群后务必根据群要求修改群名片,并完成相应步骤,你才能更好脱单哦!!') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(self.invite_group1)[0] group_add.add_members(new_friend, use_invitation=True) msg.reply_raw_msg( raw_type=42, raw_content='<msg username="******" nickname="豆豆要发芽"/>') msg.reply(u'另外如若想进入其他北京地区单身群,需要做点小任务哦!将以下图片转发到朋友圈,并配上以下文字。完成后将截图发送给我即可。文字内容如下:') msg.reply(u"”这个平台不错哦,群主也很靠谱,大家可以扫描加入,体验一下“") msg.reply_image("material/welcome.jpg") elif msg.text == u'入群' or msg.text == "加群": msg.reply('回复相应数字即可发送群邀请\n1. 北京芊芊结1群\n\ 2. 北京芊芊 结C群\n3. 缘来是你北京交友群\n4. 机器人小鱼儿聊天群') elif msg.text == u'3': msg.reply('缘来是你北京交友群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_beijing = self.bot.groups().search(u'北京交友群')[0] group_beijing.add_members(new_friend, use_invitation=True) elif msg.text == u'1': msg.reply('北京芊芊结1群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结1群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'4': msg.reply('机器人小鱼儿聊天群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'机器人小鱼儿聊天群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'2': msg.reply('北京芊芊结C群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结C群')[0] group_add.add_members(new_friend, use_invitation=True) elif msg.text == u'5': msg.reply('北京芊芊结单身5群') new_friend = self.bot.friends().search(msg.sender.name)[0] group_add = self.bot.groups().search(u'北京芊芊结单身5群')[0] group_add.add_members(new_friend, use_invitation=True) ''' #if msg.sender.name == 'Kevin': # try: # send_kevin =12 # if send_kevin == 1: # msg.reply('Hello') #except Exception as e: # logger.error(e) #msg.reply(u'这话我没法接') if msg.text == u'你好': try: msg.reply(u'你好') except Exception as e: logger.error(e) word = "%s %s:%s\n" % (create_time, msg.sender.name, word_text) with open(file_ab_path, "a+") as f: f.write(word.encode('utf-8')) word = None