Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Main script behind itchat robot
import itchat
# tuling plugin can be get here:
from tuling import get_response
def text_reply(msg):
if u'作者' in msg['Text'] or u'主人' in msg['Text']:
return u'你可以在这里了解他:'
elif u'源代码' in msg['Text'] or u'获取文件' in msg['Text']:
itchat.send('', msg['FromUserName'])
return u'这就是现在机器人后台的代码,是不是很简单呢?'
elif u'获取图片' in msg['Text']:
itchat.send('@img@applaud.gif', msg['FromUserName']) # there should be a picture
return get_response(msg['Text']) or u'收到:' + msg['Text']
@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video'])
def atta_reply(msg):
return ({ 'Picture': u'图片', 'Recording': u'录音',
'Attachment': u'附件', 'Video': u'视频', }.get(msg['Type']) +
u'已下载到本地') # download function is: msg['Text'](msg['FileName'])
@itchat.msg_register(['Map', 'Card', 'Note', 'Sharing'])
def mm_reply(msg):
if msg['Type'] == 'Map':
return u'收到位置分享'
elif msg['Type'] == 'Sharing':
return u'收到分享' + msg['Text']
elif msg['Type'] == 'Note':
return u'收到:' + msg['Text']
elif msg['Type'] == 'Card':
return u'收到好友信息:' + msg['Text']['Alias']
@itchat.msg_register('Text', isGroupChat = True)
def group_reply(msg):
if msg['isAt']:
return u'@%s\u2005%s' % (msg['ActualNickName'],
get_response(msg['Text']) or u'收到:' + msg['Text'])
def add_friend(msg):
+ u'源代码 :回复源代码\n' + u'图片获取:回复获取图片\n'
+ u'欢迎Star我的项目关注更新!', msg['RecommendInfo']['UserName'])
itchat.auto_login(True, enableCmdQR=True)

cybors commented Nov 5, 2016

怎样把项目放到sae gae bae上面啊?

lxj0276 commented Nov 12, 2016


leftus commented Dec 12, 2016

No module named 'tuling'

leftus commented Dec 12, 2016

我下的最新的啊 怎么没有

@leftus 在up主的EasierLife/Plugins/里面

Shunder commented Mar 12, 2017

好像应该应该是#coding=utf-8 ?


ipfgao commented Jul 1, 2017 edited


改成itchat.auto_login(True, enableCmdQR=2)后可以了

daicoolb commented Jul 8, 2017

如何将itchat的程序变成是一个service 跑在后台呢?

#!/usr/bin/env python
import itchat


def print_content(msg):
#def reply(msg):



python 小白 这个问题是用法问题吗?
File "", line 11
elif u'源代码' in msg['Text'] or u'获取文件' in msg['Text']:
SyntaxError: invalid syntax

kaaaaai commented Aug 7, 2017 edited

改成itchat.auto_login(True, enableCmdQR=2)后,二维码扫描显示“未找到17330349的相关信息”怎么破?而且第二次运行就二维码就无法被扫描

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment