Skip to content

Commit 9e4a701

Browse files
committed
Fix actualusername fetch bugs
1 parent 06daef0 commit 9e4a701

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

itchat/components/messages.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,36 @@ def download_atta(attaDir=None):
190190

191191
def produce_group_chat(core, msg):
192192
r = re.match('(@[0-9a-z]*?):<br/>(.*)$', msg['Content'])
193-
if not r:
194-
utils.msg_formatter(msg, 'Content')
193+
if r:
194+
actualUserName, content = r.groups()
195+
chatroomUserName = msg['FromUserName']
196+
elif msg['FromUserName'] == core.storageClass.userName:
197+
actualUserName = core.storageClass.userName
198+
content = msg['Content']
199+
chatroomUserName = msg['ToUserName']
200+
else:
201+
logger.warning('New structure of groupchat detected, please report a bug.')
195202
return
196-
actualUserName, content = r.groups()
197-
chatroom = core.storageClass.search_chatrooms(userName=msg['FromUserName'])
203+
chatroom = core.storageClass.search_chatrooms(userName=chatroomUserName)
198204
member = utils.search_dict_list((chatroom or {}).get(
199205
'MemberList') or [], 'UserName', actualUserName)
200206
if member is None:
201207
chatroom = core.update_chatroom(msg['FromUserName'])
202208
member = utils.search_dict_list((chatroom or {}).get(
203209
'MemberList') or [], 'UserName', actualUserName)
204-
msg['ActualUserName'] = actualUserName
205-
msg['ActualNickName'] = member['DisplayName'] or member['NickName']
206-
msg['Content'] = content
207-
utils.msg_formatter(msg, 'Content')
208-
atFlag = '@' + (chatroom['self']['DisplayName']
209-
or core.storageClass.nickName)
210-
msg['isAt'] = (
211-
(atFlag + (u'\u2005' if u'\u2005' in msg['Content'] else ' '))
212-
in msg['Content']
213-
or
214-
msg['Content'].endswith(atFlag))
210+
if member is None:
211+
print(chatroom['MemberList'])
212+
logger.debug('chatroom member fetch failed with %s' % actualUserName)
213+
else:
214+
msg['ActualUserName'] = actualUserName
215+
msg['ActualNickName'] = member['DisplayName'] or member['NickName']
216+
msg['Content'] = content
217+
utils.msg_formatter(msg, 'Content')
218+
atFlag = '@' + (chatroom['self']['DisplayName']
219+
or core.storageClass.nickName)
220+
msg['isAt'] = (
221+
(atFlag + (u'\u2005' if u'\u2005' in msg['Content'] else ' '))
222+
in msg['Content'] or msg['Content'].endswith(atFlag))
215223

216224
def send_raw_msg(self, msgType, content, toUserName):
217225
url = '%s/webwxsendmsg' % self.loginInfo['url']

itchat/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os, platform
22

3-
VERSION = '1.2.20'
3+
VERSION = '1.2.21'
44
BASE_URL = 'https://login.weixin.qq.com'
55
OS = platform.system() #Windows, Linux, Darwin
66
DIR = os.getcwd()

0 commit comments

Comments
 (0)