Skip to content

Instantly share code, notes, and snippets.

@littlecodersh
Last active April 28, 2025 05:39
Show Gist options
  • Save littlecodersh/ec8ddab12364323c97d4e36459174f0d to your computer and use it in GitHub Desktop.
Save littlecodersh/ec8ddab12364323c97d4e36459174f0d to your computer and use it in GitHub Desktop.
Main script behind itchat robot
#coding=utf8
import itchat
# tuling plugin can be get here:
# https://github.com/littlecodersh/EasierLife/tree/master/Plugins/Tuling
from tuling import get_response
@itchat.msg_register('Text')
def text_reply(msg):
if u'作者' in msg['Text'] or u'主人' in msg['Text']:
return u'你可以在这里了解他:https://github.com/littlecodersh'
elif u'源代码' in msg['Text'] or u'获取文件' in msg['Text']:
itchat.send('@[email protected]', msg['FromUserName'])
return u'这就是现在机器人后台的代码,是不是很简单呢?'
elif u'获取图片' in msg['Text']:
itchat.send('@[email protected]', msg['FromUserName']) # there should be a picture
else:
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'])
@itchat.msg_register('Friends')
def add_friend(msg):
itchat.add_friend(**msg['Text'])
itchat.send_msg(u'项目主页:github.com/littlecodersh/ItChat\n'
+ u'源代码 :回复源代码\n' + u'图片获取:回复获取图片\n'
+ u'欢迎Star我的项目关注更新!', msg['RecommendInfo']['UserName'])
itchat.auto_login(True, enableCmdQR=True)
itchat.run()
@GodXuxilie
Copy link

Please scan the QR code to log in. Please press confirm on your phone. Traceback (most recent call last): File "E:\myinstall\code\test\link_AI.py", line 35, in itchat.auto_login(True, enableCmdQR=2) File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\site-packages\itchat\components\register.py", line 31, in auto_login self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback, File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\site-packages\itchat\components\login.py", line 53, in login status = self.check_login() File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\site-packages\itchat\components\login.py", line 137, in check_login if process_login_info(self, r.text): File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\site-packages\itchat\components\login.py", line 172, in process_login_info for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes: File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\xml\dom\minidom.py", line 1998, in parseString return expatbuilder.parseString(string) File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\xml\dom\expatbuilder.py", line 925, in parseString return builder.parseString(string) File "E:\myinstall\app\Anaconda3\envs\workpy39\lib\xml\dom\expatbuilder.py", line 223, in parseString parser.Parse(string, True) xml.parsers.expat.ExpatError: mismatched tag: line 64, column 4

这个问题怎么解决呀

@daicoolb
Copy link

daicoolb commented Jun 13, 2024 via email

@liubaiwu
Copy link

扫码登录成功后报错
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as xxx
Start auto replying.
Traceback (most recent call last):
File "E:\miniconda3\envs\transformers\lib\site-packages\itchat\components\login.py", line 255, in maintain_loop
msgList = produce_msg(self, msgList)
File "E:\miniconda3\envs\transformers\lib\site-packages\itchat\components\messages.py", line 64, in produce_msg
utils.msg_formatter(m, 'Content')
File "E:\miniconda3\envs\transformers\lib\site-packages\itchat\utils.py", line 69, in msg_formatter
d[k] = htmlParser.unescape(d[k])
AttributeError: 'HTMLParser' object has no attribute 'unescape'

@daicoolb
Copy link

daicoolb commented Jul 26, 2024 via email

@ZhongQiyu
Copy link

生成两次二维码之后报
xml.parsers.expat.ExpatError: mismatched tag
已经通过相关联的代码做过修复 同时登出微信界面 最新版pip install itchat-uos==1.5.0.dev0安装了就行

tuling 库里面根本没有 get_response 这个模块呀

Collecting tuling
Downloading tuling-1.2-py3-none-any.whl.metadata (529 bytes)
Downloading tuling-1.2-py3-none-any.whl (6.7 kB)
Installing collected packages: tuling
Successfully installed tuling-1.2
['builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'asyncio', 'event', 'eventPool', 'icodeUser', 'json', 'parse', 'time', 'urllib3']

@daicoolb
Copy link

daicoolb commented Oct 15, 2024 via email

@kdlhj
Copy link

kdlhj commented Apr 28, 2025

请你生成一张极其平凡无奇的iPhone自拍照,没有明确的主体或构图感,就是随手一拍的快照。照片略带运动模糊,阳光或室内打光不均匀导致的轻微曝光过度,整体呈现出一种刻意的平庸感,就像是从口袋里拿手机时不小心拍到的一张自拍,主角是杜兰特,旁边是克雷格

@daicoolb
Copy link

daicoolb commented Apr 28, 2025 via email

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