diff --git a/README.md b/README.md index f5ae45f6..6cc418de 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,8 @@ A: 有些账号是天生无法给自己的账号发送信息的,建议使用`f [yaphone/itchat4j][yaphone-itchat4j]: 用Java扩展个人微信号的能力 +[kanjielu/jeeves][kanjielu-jeeves]: 使用springboot开发的微信机器人 + ## 问题和建议 如果有什么问题或者建议都可以在这个[Issue][issue#1]和我讨论 @@ -306,4 +308,5 @@ A: 有些账号是天生无法给自己的账号发送信息的,建议使用`f [Mojo-Weixin]: https://github.com/sjdy521/Mojo-Weixin [HanSon-vbot]: https://github.com/hanson/vbot [yaphone-itchat4j]: https://github.com/yaphone/itchat4j +[kanjielu-jeeves]: https://github.com/kanjielu/jeeves [issue#1]: https://github.com/littlecodersh/ItChat/issues/1 diff --git a/README_EN.md b/README_EN.md index 208585c7..8c8d6660 100644 --- a/README_EN.md +++ b/README_EN.md @@ -10,7 +10,7 @@ A wechat robot can handle all the basic messages with only less than 30 lines of And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools. -Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and enbetter user's experience with wechat. +Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and better user's experience with wechat. ## Installation @@ -168,7 +168,7 @@ itchat.search_friends(wechatAccount='littlecodersh') itchat.search_friends(name='LittleCoder机器人', wechatAccount='littlecodersh') ``` -There are detailed information about searching and getting of massive platforms and chatrooms in document. +There is detailed information about searching and getting of massive platforms and chatrooms in document. ### Download and send attachments diff --git a/docs/api.md b/docs/api.md index e861c00e..15187032 100644 --- a/docs/api.md +++ b/docs/api.md @@ -102,7 +102,7 @@ def start_receiving(self, finishCallback=None): def get_msg(self): ''' fetch messages for fetching - - method blocks for sometime util + - method blocks for sometime until - new messages are to be received - or anytime they like - synckey is updated with returned synccheckkey diff --git a/itchat/components/contact.py b/itchat/components/contact.py index 70609ed3..3ae3c02a 100644 --- a/itchat/components/contact.py +++ b/itchat/components/contact.py @@ -1,12 +1,10 @@ -import os, time, re, io +import time, re, io import json, copy -import traceback, logging - -import requests +import logging from .. import config, utils from ..returnvalues import ReturnValue -from ..storage import contact_change, templates +from ..storage import contact_change from ..utils import update_info_dict logger = logging.getLogger('itchat') @@ -148,8 +146,9 @@ def update_local_chatrooms(core, l): del oldChatroom['MemberList'][i] # - update OwnerUin if oldChatroom.get('ChatRoomOwner') and oldChatroom.get('MemberList'): - oldChatroom['OwnerUin'] = utils.search_dict_list(oldChatroom['MemberList'], - 'UserName', oldChatroom['ChatRoomOwner']).get('Uin', 0) + owner = utils.search_dict_list(oldChatroom['MemberList'], + 'UserName', oldChatroom['ChatRoomOwner']) + oldChatroom['OwnerUin'] = (owner or {}).get('Uin', 0) # - update IsAdmin if 'OwnerUin' in oldChatroom and oldChatroom['OwnerUin'] != 0: oldChatroom['IsAdmin'] = \ diff --git a/itchat/components/hotreload.py b/itchat/components/hotreload.py index 11604109..ae93f9be 100644 --- a/itchat/components/hotreload.py +++ b/itchat/components/hotreload.py @@ -1,5 +1,5 @@ import pickle, os -import logging, traceback +import logging import requests diff --git a/itchat/components/login.py b/itchat/components/login.py index b542027e..86550bd4 100644 --- a/itchat/components/login.py +++ b/itchat/components/login.py @@ -1,7 +1,7 @@ -import os, sys, time, re, io +import os, time, re, io import threading import json, xml.dom.minidom -import copy, pickle, random +import random import traceback, logging try: from httplib import BadStatusLine @@ -206,19 +206,19 @@ def web_init(self): self.storageClass.userName = dic['User']['UserName'] self.storageClass.nickName = dic['User']['NickName'] # deal with contact list returned when init - contactList = dic.get('ContactList', []) - chatroomList, otherList = [], [] - for m in contactList: - if m['Sex'] != 0: - otherList.append(m) - elif '@@' in m['UserName']: + contactList = dic.get('ContactList', []) + chatroomList, otherList = [], [] + for m in contactList: + if m['Sex'] != 0: + otherList.append(m) + elif '@@' in m['UserName']: m['MemberList'] = [] # don't let dirty info pollute the list - chatroomList.append(m) - elif '@' in m['UserName']: - # mp will be dealt in update_local_friends as well - otherList.append(m) + chatroomList.append(m) + elif '@' in m['UserName']: + # mp will be dealt in update_local_friends as well + otherList.append(m) if chatroomList: - update_local_chatrooms(self, chatroomList) + update_local_chatrooms(self, chatroomList) if otherList: update_local_friends(self, otherList) return dic diff --git a/itchat/components/messages.py b/itchat/components/messages.py index 5f500420..78748254 100644 --- a/itchat/components/messages.py +++ b/itchat/components/messages.py @@ -1,7 +1,7 @@ import os, time, re, io import json import mimetypes, hashlib -import traceback, logging +import logging from collections import OrderedDict import requests @@ -47,7 +47,7 @@ def download_fn(downloadDir=None): def produce_msg(core, msgList): ''' for messages types * 40 msg, 43 videochat, 50 VOIPMSG, 52 voipnotifymsg - * 53 webwxvoipnotifymsg, 9999 sysnotice + * 53 webwxvoipnotifymsg, 9999 sysnotice ''' rl = [] srl = [40, 43, 50, 52, 53, 9999] @@ -89,7 +89,7 @@ def produce_msg(core, msgList): 'Type': 'Text', 'Text': m['Content'],} elif m['MsgType'] == 3 or m['MsgType'] == 47: # picture - download_fn = get_download_fn(core, + download_fn = get_download_fn(core, '%s/webwxgetmsgimg' % core.loginInfo['url'], m['NewMsgId']) msg = { 'Type' : 'Picture', @@ -141,7 +141,11 @@ def download_video(videoDir=None): 'FileName' : '%s.mp4' % time.strftime('%y%m%d-%H%M%S', time.localtime()), 'Text': download_video, } elif m['MsgType'] == 49: # sharing - if m['AppMsgType'] == 6: + if m['AppMsgType'] == 0: # chat history + msg = { + 'Type': 'Note', + 'Text': m['Content'], } + elif m['AppMsgType'] == 6: rawMsg = m cookiesList = {name:data for name,data in core.s.cookies.items()} def download_atta(attaDir=None): @@ -169,7 +173,7 @@ def download_atta(attaDir=None): 'Type': 'Attachment', 'Text': download_atta, } elif m['AppMsgType'] == 8: - download_fn = get_download_fn(core, + download_fn = get_download_fn(core, '%s/webwxgetmsgimg' % core.loginInfo['url'], m['NewMsgId']) msg = { 'Type' : 'Picture', @@ -239,7 +243,7 @@ def produce_group_chat(core, msg): member = utils.search_dict_list((chatroom or {}).get( 'MemberList') or [], 'UserName', actualUserName) if member is None: - chatroom = core.update_chatroom(msg['FromUserName']) + chatroom = core.update_chatroom(chatroomUserName) member = utils.search_dict_list((chatroom or {}).get( 'MemberList') or [], 'UserName', actualUserName) if member is None: @@ -267,7 +271,7 @@ def send_raw_msg(self, msgType, content, toUserName): 'ToUserName': (toUserName if toUserName else self.storageClass.userName), 'LocalID': int(time.time() * 1e4), 'ClientMsgId': int(time.time() * 1e4), - }, + }, 'Scene': 0, } headers = { 'ContentType': 'application/json; charset=UTF-8', 'User-Agent' : config.USER_AGENT } r = self.s.post(url, headers=headers, @@ -515,8 +519,8 @@ def revoke(self, msgId, toUserName, localId=None): "ClientMsgId": localId or str(time.time() * 1e3), "SvrMsgId": msgId, "ToUserName": toUserName} - headers = { - 'ContentType': 'application/json; charset=UTF-8', + headers = { + 'ContentType': 'application/json; charset=UTF-8', 'User-Agent' : config.USER_AGENT } r = self.s.post(url, headers=headers, data=json.dumps(data, ensure_ascii=False).encode('utf8')) diff --git a/itchat/core.py b/itchat/core.py index 2b39d933..52d6ae4f 100644 --- a/itchat/core.py +++ b/itchat/core.py @@ -1,8 +1,6 @@ -import logging - import requests -from . import config, storage, utils, log +from . import storage from .components import load_components class Core(object): @@ -127,7 +125,7 @@ def start_receiving(self, exitCallback=None, getReceivingFnOnly=False): def get_msg(self): ''' fetch messages for fetching - - method blocks for sometime util + - method blocks for sometime until - new messages are to be received - or anytime they like - synckey is updated with returned synccheckkey diff --git a/itchat/returnvalues.py b/itchat/returnvalues.py index b9600bd6..f28c11d0 100644 --- a/itchat/returnvalues.py +++ b/itchat/returnvalues.py @@ -1,6 +1,4 @@ #coding=utf8 -import sys - TRANSLATE = 'Chinese' class ReturnValue(dict):