Skip to content

Commit

Permalink
Add @ key in groupchat
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Jun 5, 2016
1 parent 1f773d1 commit 31416a9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 45 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pip install itchat
```python
import itchat, time

itchat.auto_login()

@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])
Expand All @@ -51,8 +49,10 @@ def add_friend(msg):

@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
if msg['isAt']:
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])

itchat.auto_login()
itchat.run()
```

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ Here is the `code <https://github.com/littlecodersh/ItChat/tree/robot>`__.
import itchat, time
itchat.auto_login()
@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])
Expand All @@ -50,8 +48,10 @@ Here is the `code <https://github.com/littlecodersh/ItChat/tree/robot>`__.
@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
if msg['isAt']:
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
itchat.auto_login()
itchat.run()
**FAQ**
Expand Down
11 changes: 6 additions & 5 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

[![Gitter](https://badges.gitter.im/littlecodersh/ItChat.svg)](https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) ![python](https://img.shields.io/badge/python-2.7-ff69b4.svg) [中文版](https://github.com/littlecodersh/ItChat/blob/master/README.md)

itchat is an open source api for WeChat, a famous Chinese communicating app, you can easily use your personal wechat account through itchat in cmd.
itchat is an open source api for WeChat, a commonly-used Chinese social networking app, you can easily access your personal wechat account through itchat in cmd.

A wechat robot and a command line version of wechat are also structured, you can view them in [robot branch](https://github.com/littlecodersh/ItChat/tree/robot).
Wechat is structured with a wechat robot and a command line, you can view them in [robot branch](https://github.com/littlecodersh/ItChat/tree/robot).

Consisted of less than 30 lines of codes, a wechat robot can deal with all the oridinary messages.
A wechat robot can handle all the basic messages with only less than 30 lines of codes.

Now Wechat is an important part of personal sociality, hope that this repo can help you extend your personal wechat account and make your life easier.
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.

Python 2.7.11 version is also available [here](https://github.com/littlecodersh/ItChat/tree/py3-dev).

Expand Down Expand Up @@ -50,7 +50,8 @@ def add_friend(msg):

@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
if msg['isAt']:
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])

itchat.auto_login()
itchat.run()
Expand Down
92 changes: 72 additions & 20 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,89 @@
# itchat
# itchat

[![Gitter](https://badges.gitter.im/littlecodersh/ItChat.svg)](https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) ![python](https://img.shields.io/badge/python-2.7-ff69b4.svg) [English version](https://github.com/littlecodersh/ItChat/blob/master/README_EN.md)

itchat是一个开源的微信个人号接口,使用他你可以轻松的通过命令行使用个人微信号。

使用itchat,使用不到三十行的代码,你就可以自己编写一个能够处理所有信息的微信机器人。
微信机器人的实现及命令行版微信见[robot分支](https://github.com/littlecodersh/ItChat/tree/robot),Python 3.5.1 的版本可见这里:[here](https://github.com/littlecodersh/ItChat/tree/py3-dev)

使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。

如今微信已经成为了个人社交的很大一部分,希望这个项目能够帮助你扩展你的个人的微信号、方便自己的生活。

你可以在这里获取[源代码](https://github.com/littlecodersh/ItChat)

##Installation
## Documents

你可以在[这里](https://itchat.readthedocs.org/zh/latest/)获取api的使用帮助。

## Installation

可以通过本命令安装itchat:

```python
pip install itchat
```

## Simple uses

通过如下代码,微信已经可以就日常的各种信息进行获取与回复。

```python
import itchat, time

@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])

@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video'])
def download_files(msg):
fileDir = '%s%s'%(msg['Type'], int(time.time()))
msg['Text'](fileDir)
itchat.send('%s received'%msg['Type'], msg['FromUserName'])
itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName'])

@itchat.msg_register('Friends')
def add_friend(msg):
itchat.add_friend(**msg['Text'])
itchat.get_contract()
itchat.send_msg(msg['RecommendInfo']['UserName'], 'Nice to meet you!')

@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])

itchat.auto_login()
itchat.run()
```

## Have a try

这是一个基于这一项目的[开源小机器人](https://github.com/littlecodersh/ItChat/tree/robot),百闻不如一见,有兴趣可以尝试一下。

![QRCode](http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/400/)

## Screenshots

![file_autoreply](http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E5%BE%AE%E4%BF%A1%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E5%9B%BE%E7%89%87.png?imageView/2/w/300/) ![login_page](http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E7%99%BB%E5%BD%95%E7%95%8C%E9%9D%A2%E6%88%AA%E5%9B%BE.jpg?imageView/2/w/450/)

## FAQ

Q: 为什么中文的文件没有办法上传?

A: 这是由于`requests`的编码问题导致的。若需要支持中文文件传输,将[fields.py](https://github.com/littlecodersh/ItChat/blob/robot/plugin/config/fields.py)文件放入requests包的packages/urllib3下即可

可以通过本命令安装该项目:
## Author

`pip install itchat`
[LittleCoder](https://github.com/littlecodersh): 整体构架及完成Python2版本。

##Index
* [入门](https://itchat.readthedocs.org/zh/latest/1.Start/)
* [登陆](https://itchat.readthedocs.org/zh/latest/2.Login/)
* [注册消息方法](https://itchat.readthedocs.org/zh/latest/3.Handler/)
* [消息内容](https://itchat.readthedocs.org/zh/latest/4.Message%20content/)
* [回复](https://itchat.readthedocs.org/zh/latest/5.Reply/)
* [部署](https://itchat.readthedocs.org/zh/latest/6.Deploy/)
* [FAQ](https://itchat.readthedocs.org/zh/latest/7.FAQ/)
* [机器人](https://itchat.readthedocs.org/zh/latest/Robot/Home/)
* [教程](https://itchat.readthedocs.org/zh/latest/Tutorial/Tutorial1/)
[Chyroc](https://github.com/Chyroc): 完成Python3版本。

##Have a try
## See also

这是一个基于这一项目的小机器人,百闻不如一见,有兴趣可以尝试一下。
[liuwons/wxBot](https://github.com/liuwons/wxBot): 类似的基于Python的微信机器人

![QRCode](http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/200/)
[zixia/wechaty](https://github.com/zixia/wechaty): 基于Javascript(ES6)的微信个人账号机器人NodeJS框架/库

##Comments
## Comments

如果有什么问题或者建议都可以在这个[Issue](https://github.com/littlecodersh/ItChat/issues/1)和我讨论

Expand Down
18 changes: 8 additions & 10 deletions itchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ def send(msg, toUserName = None):
# decorations
__functionDict = {'GroupChat': {}, 'GeneralReply': None}
def configured_reply():
try:
msg = __client.storageClass.msgList.pop()
if '@@' in msg.get('FromUserName'):
replyFn = __functionDict['GroupChat'].get(msg['Type'], __functionDict['GeneralReply'])
send(replyFn(msg), msg.get('FromUserName'))
else:
replyFn = __functionDict.get(msg['Type'], __functionDict['GeneralReply'])
send(replyFn(msg), msg.get('FromUserName'))
except:
pass
if not __client.storageClass.msgList: return
msg = __client.storageClass.msgList.pop()
if '@@' in msg.get('FromUserName'):
replyFn = __functionDict['GroupChat'].get(msg['Type'], __functionDict['GeneralReply'])
if replyFn: send(replyFn(msg), msg.get('FromUserName'))
else:
replyFn = __functionDict.get(msg['Type'], __functionDict['GeneralReply'])
if replyFn: send(replyFn(msg), msg.get('FromUserName'))

def msg_register(_type = None, *args, **kwargs):
if hasattr(_type, '__call__'):
Expand Down
1 change: 1 addition & 0 deletions itchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def get_msg_from_raw(content):
additionalItems = {
'ActualUserName': ActualUserName,
'ActualNickName': ActualNickName,
'isAt': isAt,
'Content': Content, }
return dict(msg, **additionalItems)
def send_msg(self, msg = 'Test Message', toUserName = None):
Expand Down
6 changes: 3 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
import itchat

itchat.auto_login()

def simple_reply():
@itchat.msg_register
Expand All @@ -11,7 +10,6 @@ def simple_reply(msg):
itchat.run()

def complex_reply():

@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])
Expand All @@ -31,10 +29,12 @@ def add_friend(msg):

@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
if msg['isAt']:
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])

itchat.run()

if __name__ == '__main__':
itchat.auto_login()
# simple_reply()
complex_reply()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
setup(
name='itchat',

version='1.0.8',
version='1.0.9',

description='A complete wechat personal account api',
long_description=long_description,
Expand Down

0 comments on commit 31416a9

Please sign in to comment.