Skip to content

Instantly share code, notes, and snippets.

@Zheaoli
Created January 18, 2018 11:58
Show Gist options
  • Save Zheaoli/bd659b874040855c22f10f52f0e59c71 to your computer and use it in GitHub Desktop.
Save Zheaoli/bd659b874040855c22f10f52f0e59c71 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
try:
import wxpy
except Exception as e:
import pip
pip.main(["install", "wxpy"])
import wxpy
bot = wxpy.Bot(console_qr=True)
my_friend = bot.friends().search('英子')[0]
groups = bot.groups()
group_map = {
"单核": "单核工作法 Monotasking",
}
msg_str = ","
temp_list = []
key_list = list(group_map.items())
for i in range(len(key_list)):
temp_list.append("\n {}. {} 关键词: {}".format(i + 1, key_list[i][1], key_list[i][0]))
msg_str = msg_str.join(temp_list)
@bot.register(msg_types=wxpy.FRIENDS)
def auto_create_accept_friends(msg):
new_friend = bot.accept_friend(msg.card)
if msg.text in group_map:
temp_group = groups.search(group_map.get(msg.text))
if len(temp_group) == 0:
new_friend.send("欢迎了来到图灵,你刚刚输入的关键字有误,请回复关键字入群,关键字如下:{}".format(msg_str))
return
group = temp_group[0]
group.update_group()
if new_friend in group.members:
new_friend.send("Hi 你已经在{}里了哦!试试其余群吧,试试其余群吧,关键字如下:{}".format(group_map.get(msg.text), msg_str))
return
group.add_members(new_friend, use_invitation=True)
else:
new_friend.send("欢迎了来到图灵,你刚刚输入的关键字有误,请回复关键字入群,关键字如下:{}".format(msg_str))
@bot.register(msg_types=wxpy.TEXT)
def add_group(msg):
if isinstance(msg.sender, wxpy.User):
people = msg.sender
# people.send("哇小哥哥/小姐姐,对不起啊,现在所有群已经满员了,请你耐心等一下,我们图灵会尽快解决的")
group_name = group_map.get(msg.text)
if group_name is None:
people.send("您好,您所输入的关键字有误")
return
temp_group = groups.search(group_name)
if len(temp_group) == 0:
people.send("您好,您所输入的关键字有误")
else:
temp_group[0].update_group()
if people in temp_group[0].members:
people.send("Hi 你已经在{}里了哦,试试其余群吧,关键字如下:{}".format(group_name, msg_str))
return
group = temp_group[0]
group.add_members(msg.sender, use_invitation=True)
bot.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment