代码拉取完成,页面将自动刷新
import ai
import db
from wxauto import *
import time
wx = WeChat()
listen_list = []
# 读取好友列表
file_path = 'names.txt'
try:
with open(file_path, 'r', encoding='utf-8') as file:
names = file.readlines()
listen_list = [name.strip() for name in names]
except FileNotFoundError:
print(f"文件 {file_path} 未找到,请检查文件路径是否正确!")
except Exception as e:
print(f"读取文件时发生错误:{e}")
for i in listen_list:
print(f"开始监听好友 {i} 的消息...")
wx.AddListenChat(who=i, savepic=True)
ai.add_user(i)
wait = 1 # 设置间隔时间
# 创建数据库
db.create_db()
while True:
msgs = wx.GetListenMessage()
for chat in msgs:
who = chat.who # 获取聊天窗口名(人或群名)
one_msgs = msgs[chat] # 获取消息内容
for msg in one_msgs:
msgtype = msg.type # 获取消息类型
content = msg.content # 获取消息内容
print(f'【{who}】:{content}')
if msgtype == 'friend':
chat.SendMsg(ai.chat(who, content))
time.sleep(wait)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。