MCPcopy
hub / github.com/liuwons/wxBot / handle_msg

Method handle_msg

wxbot.py:376–427  ·  view source on GitHub ↗

The inner function that processes raw WeChat messages. msg_type_id: 0 -> Init 1 -> Self 2 -> FileHelper 3 -> Group 4 -> Contact 5 -> Public 6 -> Special 99 -> Unknown :param r: Th

(self, r)

Source from the content-addressed store, hash-verified

374 return msg_content
375
376 def handle_msg(self, r):
377 """
378 The inner function that processes raw WeChat messages.
379 msg_type_id:
380 0 -> Init
381 1 -> Self
382 2 -> FileHelper
383 3 -> Group
384 4 -> Contact
385 5 -> Public
386 6 -> Special
387 99 -> Unknown
388 :param r: The raw data of the messages.
389 :return: None
390 """
391 for msg in r['AddMsgList']:
392 msg_type_id = 99
393 user = {'id': msg['FromUserName'], 'name': 'unknown'}
394 if msg['MsgType'] == 51: # init message
395 msg_type_id = 0
396 user['name'] = 'system'
397 elif msg['FromUserName'] == self.user['UserName']: # Self
398 msg_type_id = 1
399 user['name'] = 'self'
400 elif msg['ToUserName'] == 'filehelper': # File Helper
401 msg_type_id = 2
402 user['name'] = 'file_helper'
403 elif msg['FromUserName'][:2] == '@@': # Group
404 msg_type_id = 3
405 user['name'] = self.get_prefer_name(self.get_account_name(user['id']))
406 elif self.is_contact(msg['FromUserName']): # Contact
407 msg_type_id = 4
408 user['name'] = self.get_prefer_name(self.get_account_name(user['id']))
409 elif self.is_public(msg['FromUserName']): # Public
410 msg_type_id = 5
411 user['name'] = self.get_prefer_name(self.get_account_name(user['id']))
412 elif self.is_special(msg['FromUserName']): # Special
413 msg_type_id = 6
414 user['name'] = self.get_prefer_name(self.get_account_name(user['id']))
415 else:
416 msg_type_id = 99
417 user['name'] = 'unknown'
418
419 if self.DEBUG and msg_type_id != 0:
420 print '[MSG] %s:' % user['name']
421 content = self.extract_msg_content(msg_type_id, msg)
422 message = {'msg_type_id': msg_type_id,
423 'msg_id': msg['MsgId'],
424 'content': content,
425 'to_user_id': msg['ToUserName'],
426 'user': user}
427 self.handle_msg_all(message)
428
429 def schedule(self):
430 """

Callers 1

proc_msgMethod · 0.95

Calls 7

get_prefer_nameMethod · 0.95
get_account_nameMethod · 0.95
is_contactMethod · 0.95
is_publicMethod · 0.95
is_specialMethod · 0.95
extract_msg_contentMethod · 0.95
handle_msg_allMethod · 0.95

Tested by

no test coverage detected