文件已上传:https://www.pan38.com/share.php?code=XHUZM 提取码:8888
包含4个完整模块:主逻辑模块实现核心回复功能,工具模块封装常用函数,UI模块提供可视化控制界面,配置文件存储用户设置。使用时需要Auto.js 4.1.1以上版本,建议配合定时任务实现全天候自动回复。
工具函数集合
function isNewMessage(element) {
const id = element.id();
const timestamp = new Date().getTime();
return !global.lastMsgId ||
global.lastMsgId !== id ||
timestamp - global.__lastMsgTime > 60000;
}
function shouldReply(text) {
return config.keywords.some(keyword =>
text.includes(keyword)) &&
!config.whitelist.some(name =>
text.includes(name));
}
function isMessageArea(bounds) {
return bounds.top > height 0.3 &&
bounds.bottom < height 0.7;
}
function replyToMessage(bounds) {
click(bounds.centerX(), bounds.centerY());
sleep(500);
const randomIndex = Math.floor(Math.random() *
config.replyMessages.length);
setText(config.replyMessages[randomIndex]);
const sendBtn = text("发送").findOne(1000);
if (sendBtn) {
click(sendBtn.bounds().centerX(),
sendBtn.bounds().centerY());
global.__lastMsgTime = new Date().getTime();
}
}
function checkPermissions() {
const requiredPerms = [
"float_window",
"foreground_service",
"screen_capture"
];
return requiredPerms.every(perm =>
runtime.requestPermission(perm));
}
悬浮窗控制界面
function initUI() {
const window = floaty.window(
);
window.switcher.on("check", (checked) => {
isRunning = checked;
if (checked) {
toast("服务已启动");
mainService();
}
});
window.configBtn.click(() => {
showConfigDialog();
});
window.exitBtn.click(() => {
window.close();
exit();
});
}
function showConfigDialog() {
dialogs.build({
title: "配置自动回复",
items: [
{
input: config.replyMessages.join("\n"),
id: "messages",
hint: "每行一条回复内容"
},
{
input: config.keywords.join(","),
id: "keywords",
hint: "触发关键词,用逗号分隔"
}
],
positive: "保存",
negative: "取消"
}).on("positive", (dialog) => {
config.replyMessages =
dialog.getInput("messages").split("\n");
config.keywords =
dialog.getInput("keywords").split(",");
files.write("config.json",
JSON.stringify(config));
toast("配置已保存");
}).show();
}
{
"replyMessages": [
"您好,我现在不方便回复",
"稍后给您回复",
"自动回复:正在开会中"
],
"keywords": ["在吗", "你好", "hi"],
"whitelist": ["张三", "李四"],
"scanInterval": 3000,
"maxHistory": 50
}