Skip to content

Commit aaa75e7

Browse files
authored
Merge pull request #2267 from 6vision/master
Optimize the welcome message for new members.
2 parents c184722 + 6d0cef3 commit aaa75e7

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

channel/wechat/wechat_message.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def __init__(self, itchat_msg, is_group=False):
1414
self.create_time = itchat_msg["CreateTime"]
1515
self.is_group = is_group
1616

17-
notes_join_group = ["加入群聊","加入了群聊","invited","joined"] # 可通过添加对应语言的加入群聊通知中的关键词适配更多
18-
notes_exit_group = ["移出了群聊","removed"] # 可通过添加对应语言的踢出群聊通知中的关键词适配更多
19-
notes_patpat = ["拍了拍我","tickled my","tickled me"] # 可通过添加对应语言的拍一拍通知中的关键词适配更多
17+
notes_join_group = ["加入群聊", "加入了群聊", "invited", "joined"] # 可通过添加对应语言的加入群聊通知中的关键词适配更多
18+
notes_bot_join_group = ["邀请你", "invited you", "You've joined", "你通过扫描"]
19+
notes_exit_group = ["移出了群聊", "removed"] # 可通过添加对应语言的踢出群聊通知中的关键词适配更多
20+
notes_patpat = ["拍了拍我", "tickled my", "tickled me"] # 可通过添加对应语言的拍一拍通知中的关键词适配更多
2021

2122
if itchat_msg["Type"] == TEXT:
2223
self.ctype = ContextType.TEXT
@@ -30,26 +31,30 @@ def __init__(self, itchat_msg, is_group=False):
3031
self.content = TmpDir().path() + itchat_msg["FileName"] # content直接存临时目录路径
3132
self._prepare_fn = lambda: itchat_msg.download(self.content)
3233
elif itchat_msg["Type"] == NOTE and itchat_msg["MsgType"] == 10000:
33-
if is_group and (any(note_join_group in itchat_msg["Content"] for note_join_group in notes_join_group)): # 若有任何在notes_join_group列表中的字符串出现在NOTE中
34+
if is_group:
35+
if any(note_bot_join_group in itchat_msg["Content"] for note_bot_join_group in notes_bot_join_group): # 邀请机器人加入群聊
36+
logger.warn("机器人加入群聊消息,不处理~")
37+
pass
38+
elif any(note_join_group in itchat_msg["Content"] for note_join_group in notes_join_group): # 若有任何在notes_join_group列表中的字符串出现在NOTE中
3439
# 这里只能得到nickname, actual_user_id还是机器人的id
35-
if "加入群聊" not in itchat_msg["Content"]:
36-
self.ctype = ContextType.JOIN_GROUP
37-
self.content = itchat_msg["Content"]
38-
if "invited" in itchat_msg["Content"]: # 匹配英文信息
39-
self.actual_user_nickname = re.findall(r'invited\s+(.+?)\s+to\s+the\s+group\s+chat', itchat_msg["Content"])[0]
40-
elif "joined" in itchat_msg["Content"]: # 匹配通过二维码加入的英文信息
41-
self.actual_user_nickname = re.findall(r'"(.*?)" joined the group chat via the QR Code shared by', itchat_msg["Content"])[0]
42-
elif "加入了群聊" in itchat_msg["Content"]:
43-
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[-1]
44-
elif "加入群聊" in itchat_msg["Content"]:
45-
self.ctype = ContextType.JOIN_GROUP
40+
if "加入群聊" not in itchat_msg["Content"]:
41+
self.ctype = ContextType.JOIN_GROUP
42+
self.content = itchat_msg["Content"]
43+
if "invited" in itchat_msg["Content"]: # 匹配英文信息
44+
self.actual_user_nickname = re.findall(r'invited\s+(.+?)\s+to\s+the\s+group\s+chat', itchat_msg["Content"])[0]
45+
elif "joined" in itchat_msg["Content"]: # 匹配通过二维码加入的英文信息
46+
self.actual_user_nickname = re.findall(r'"(.*?)" joined the group chat via the QR Code shared by', itchat_msg["Content"])[0]
47+
elif "加入了群聊" in itchat_msg["Content"]:
48+
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[-1]
49+
elif "加入群聊" in itchat_msg["Content"]:
50+
self.ctype = ContextType.JOIN_GROUP
51+
self.content = itchat_msg["Content"]
52+
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
53+
54+
elif any(note_exit_group in itchat_msg["Content"] for note_exit_group in notes_exit_group): # 若有任何在notes_exit_group列表中的字符串出现在NOTE中
55+
self.ctype = ContextType.EXIT_GROUP
4656
self.content = itchat_msg["Content"]
4757
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
48-
49-
elif is_group and (any(note_exit_group in itchat_msg["Content"] for note_exit_group in notes_exit_group)): # 若有任何在notes_exit_group列表中的字符串出现在NOTE中
50-
self.ctype = ContextType.EXIT_GROUP
51-
self.content = itchat_msg["Content"]
52-
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
5358

5459
elif "你已添加了" in itchat_msg["Content"]: #通过好友请求
5560
self.ctype = ContextType.ACCEPT_FRIEND

0 commit comments

Comments
 (0)