(self, msg)
| 57 | self.send_msg_by_uid(u'[Robot]' + u'机器人已开启!', msg['to_user_id']) |
| 58 | |
| 59 | def handle_msg_all(self, msg): |
| 60 | if not self.robot_switch and msg['msg_type_id'] != 1: |
| 61 | return |
| 62 | if msg['msg_type_id'] == 1 and msg['content']['type'] == 0: # reply to self |
| 63 | self.auto_switch(msg) |
| 64 | elif msg['msg_type_id'] == 4 and msg['content']['type'] == 0: # text message from contact |
| 65 | self.send_msg_by_uid(self.tuling_auto_reply(msg['user']['id'], msg['content']['data']), msg['user']['id']) |
| 66 | elif msg['msg_type_id'] == 3: # group message |
| 67 | if msg['content']['data'].find('@') >= 0: # someone @ another |
| 68 | my_names = self.get_group_member_name(msg['user']['id'], self.user['UserName']) |
| 69 | if my_names is None: |
| 70 | my_names = {} |
| 71 | if 'NickName' in self.user and len(self.user['NickName']) > 0: |
| 72 | my_names['nickname2'] = self.user['NickName'] |
| 73 | if 'RemarkName' in self.user and len(self.user['RemarkName']) > 0: |
| 74 | my_names['remark_name2'] = self.user['RemarkName'] |
| 75 | is_at_me = False |
| 76 | text_msg = '' |
| 77 | for _ in my_names: |
| 78 | if msg['content']['data'].find('@'+my_names[_]) >= 0: |
| 79 | is_at_me = True |
| 80 | text_msg = msg['content']['data'].replace('@'+my_names[_], '').strip() |
| 81 | break |
| 82 | if is_at_me: # someone @ me |
| 83 | snames = self.get_group_member_name(msg['user']['id'], msg['content']['user']['id']) |
| 84 | if snames is None: |
| 85 | snames = self.get_account_name(msg['content']['user']['id']) |
| 86 | src_name = '' |
| 87 | if snames is not None: |
| 88 | if 'display_name' in snames and len(snames['display_name']) > 0: |
| 89 | src_name = snames['display_name'] |
| 90 | elif 'nickname' in snames and len(snames['nickname']) > 0: |
| 91 | src_name = snames['nickname'] |
| 92 | elif 'remark_name' in snames and len(snames['remark_name']) > 0: |
| 93 | src_name = snames['remark_name'] |
| 94 | else: |
| 95 | return |
| 96 | |
| 97 | if src_name != '': |
| 98 | reply = '@' + src_name + ' ' |
| 99 | if msg['content']['type'] == 0: # text message |
| 100 | reply += self.tuling_auto_reply(msg['content']['user']['id'], text_msg) |
| 101 | else: |
| 102 | reply += u"对不起,只认字,其他杂七杂八的我都不认识,,,Ծ‸Ծ,," |
| 103 | self.send_msg_by_uid(reply, msg['user']['id']) |
| 104 | |
| 105 | |
| 106 | def main(): |
nothing calls this directly
no test coverage detected