简单小练习_自动拉微信群
from wxpy import * import time bot = Bot() def listen(pwd): time.sleep(3) return [msg for msg in bot.messages if msg.text == pwd] def add_group(users,group): try: group.add_members(users,use_invitation=True) except ResponseError: return None def get_newfren(say): time.sleep(3) return [msg for msg in bot.messages if msg == say] group = bot.groups().search('test group 1')[0] while True: new_fren = get_newfren('make friend') if new_fren: print('find new one!') for msg in new_fren: new_user = msg.card bot.accept_friend(new_user) new_user.send('hi new friend') bot.messages.remove(msg) time.sleep(3) print('running') selected = listen('pull me in') if selected: print('find a new friend') for msg in selected: this_user = msg.sender add_group(this_user,group) bot.messages.remove(msg)