Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sundevilyang/54bdf83a92526e191907d199e783cf40 to your computer and use it in GitHub Desktop.
Save sundevilyang/54bdf83a92526e191907d199e783cf40 to your computer and use it in GitHub Desktop.
wechat_robot_auto_accept_and_invitate_to_group
#!/usr/bin/python3
import logging
import time
from wxpy import *
logging.basicConfig(level=logging.INFO)
# 减少网络层日志的干扰
for m in 'requests', 'urllib3':
logging.getLogger(m).setLevel(logging.WARNING)
bot = Bot(True)
@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
if '火种节' in msg.text.lower():
f = bot.accept_friend(msg.card)
f.send('哈哈,我自动接受了你的好友请求')
group = bot.groups().search(nick_name='Rails Girls预热群')
group = ensure_one(group)
if f in group:
f.send('您已加入 {} 分组'.format(g.name))
else:
#注意:如果该用户已经存在在这个分组,则会报异常
try:
group.add_members(f, use_invitation=True)
except ResponseError as e:
logging.warning('Failed to invite {}\n{}'.format(f, e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment