Files
云端客 a3de5b65d6 [0.0.4迭代]活动期限/周本通知器 (#2604)
* feat(notice): 添加WebSocket独立通知功能并重构通知系统

- 实现WebSocket通知功能,支持私聊和群聊模式
- 添加通知类型配置选项,支持BGI通知、独立通知或两者同时使用
- 新增WebSocket相关配置项包括代理URL、连接地址和认证令牌
- 重构通知发送逻辑,支持多种通知类型的消息格式
- 添加@用户功能和多种消息类型支持
- 更新manifest.json添加网络请求权限配置
- 优化代码结构,使用异步初始化加载工具模块

* feat(ActivitySwitchNotice): 添加独立通知功能支持WebSocket推送

- 新增独立通知配置功能,支持通过WebSocket发送通知
- 新增ws.js模块实现WebSocket通知功能
- 新增noticeType配置选项用于选择通知模式
- 新增ws_proxy_url、ws_url、ws_token配置选项
- 新增action、send_id、at_list配置选项用于发送设置
- 更新README文档添加独立通知配置说明和使用要求
- 修复OCR识别函数名称从OcrRemainingTime改为OcrKey

* fix(ActivitySwitchNotice): 修复设置选项数组格式

- 修复了通知模式选项数组中缺少逗号的问题
- 确保JSON格式正确性以避免解析错误

* refactor(notice): 重构通知工具类并修复配置引用问题

- 将 noticeUtil.send 方法重命名为 sendText 以明确功能
- 修复配置对象引用问题,将 config 重命名为 configNotice 避免冲突
- 为 sendNotice 函数添加默认参数和调试日志
- 更新条件判断逻辑,使用 map.size 检查空值
- 修复 ws 模块中的配置对象引用,将 config 重命名为 configWs
- 重构 ws 模块初始化逻辑,确保配置正确加载
- 修复变量命名冲突,将 token 参数重命名为 wsToken
- 更新模块初始化顺序,调整 activity 工具的加载位置

* docs(ActivitySwitchNotice): 更新文档说明独立通知配置和WsProxy部署

- 更新独立通知功能说明,添加WsProxy依赖提示
- 简化settings.json文件路径引用
- 移除多余的配置示例分隔符
- 添加WsProxy部署指南和Docker镜像使用说明
- 整理文档结构,优化内容排版

* docs(ActivitySwitchNotice): 更新 README 文档完善功能说明和配置选项

- 添加了独立通知功能的详细配置说明
- 更新了设置表格格式和内容描述
- 增加了 WsProxy 部署指南和 Docker 配置示例
- 完善了核心模块和配置选项文档
- 修正了文档格式和链接引用问题

* docs(ActivitySwitchNotice): 更新 README 文档中的链接和函数名

- 修复 settings.json 链接格式
- 将 send 函数名更正为 sendText

* chore(ActivitySwitchNotice): 更新版本号

- 将版本号从 0.0.3 更新到 0.4
- 保持其他配置项不变

* docs(ActivitySwitchNotice): 更新版本历史文档

- 将版本 0.0.4 的发布状态更新为具体发布日期 2026-01-01
- 保持独立通知配置功能说明
- 保留 WebSocket 通知功能描述
- 维护版本历史记录的准确性
2026-01-01 20:20:44 +08:00

165 lines
4.7 KiB
JavaScript

const actionType = Object.freeze({
send_private_msg: 'send_private_msg',//私聊
send_group_msg: 'send_group_msg',//群聊
fromValue(value) {
return Object.keys(this).find(key => this[key] === value);
}
})
const textType = Object.freeze({
text: 'text',//文本
at: 'at',//@某人
image: 'image',//图片
face: 'face',//表情
json: 'json',//卡片消息
record: 'record',//语音
video: 'video',//视频
dice: 'dice',//骰子
rps: 'rps',//猜拳
file: 'file',//文件
node: 'node',//节点
// 添加反向映射(可选)
fromValue(value) {
return Object.keys(this).find(key => this[key] === value);
}
});
const actionMap = new Map([
["私聊", actionType.send_private_msg],
["群聊", actionType.send_group_msg]
]);
// const templateMap = new Map([
// [textType.text, {type: textType.text, data: {text: ""}}],
// [textType.at, {type: textType.at, data: {qq: ""}}],
// ]);
let configWs = {
action: actionMap.get(settings.action),
group_id: settings.send_id,
user_id: settings.send_id,
ws_proxy_url: settings.ws_proxy_url,
ws_url: settings.ws_url,
ws_token: settings.ws_token,
at_list: settings.at_list ? settings.at_list.split(",") : []
}
/**
*
*
* 初始化函数
* 该函数是一个异步函数,用于执行程序的初始化操作
* 目前函数体为空,可以根据实际需求添加初始化逻辑
*/
async function init() {
configWs = {
action: actionMap.get(settings.action),
group_id: settings.send_id,
user_id: settings.send_id,
ws_proxy_url: settings.ws_proxy_url,
ws_url: settings.ws_url,
ws_token: settings.ws_token,
at_list: settings.at_list ? settings.at_list.split(",") : []
}
log.debug(`configWs:{configWs}`, JSON.stringify(configWs))
log.info('ws init success')
}
/**
* 发送消息的异步函数
* @param {string} wsProxyUrl - WebSocket代理URL
* @param {string} wsUrl - WebSocket URL
* @param {string} wsToken - WebSocket令牌
* @param {string} action - 动作类型(群发或私聊)
* @param {number} group_id - 群号
* @param {number} user_id - 用户QQ号
* @param {Array} textList - 文本消息列表
* @param {Array} atList - @用户列表
* @returns {Promise<void>} 无返回值
*/
async function send(wsProxyUrl, wsUrl, wsToken, action, group_id, user_id, textList, atList) {
// 构建基础JSON对象
let json = {
action: action,//send_group_msg群发、send_private_msg私聊
// params: {
// group_id: group_id,//群号
// user_id: user_id,//QQ号
// message: []
// }
}
// 根据动作类型设置不同的参数
switch (action) {
case actionType.send_group_msg:
json.params = {
group_id: group_id,//群号
message: []
};
break;
case actionType.send_private_msg:
json.params = {
user_id: user_id,//QQ号
message: []
}
break;
default:
break;
}
// 添加文本消息到消息列表
for (let text of textList) {
json.params.message.push({
type: textType.text,
data: {
text: `${text}`
}
})
}
// 添加@消息到消息列表
for (let at of atList) {
//@qq
json.params.message.push({
type: textType.at,
data: {
qq: `${at}`
}
})
}
// 构建请求体
let body = {
url: wsUrl,
token: wsToken,
bodyJson: JSON.stringify(json)
}
// 调试日志输出请求体
log.debug(`body:{key}`, JSON.stringify(body))
// 信息日志记录HTTP请求开始
log.info('http request start')
// 发送HTTP请求
const httpResponse = await http.request("POST", wsProxyUrl, JSON.stringify(body), JSON.stringify({
"Content-Type": "application/json"
}));
// 检查响应状态码
if (httpResponse.status_code != 200) {
// 错误日志输出服务器响应
log.error(`服务器返回状态${httpResponse.headers} ${httpResponse.body}`);
return;
}
}
async function sendText(text) {
await init();
let action = configWs.action;
let group_id = configWs.group_id;
let user_id = configWs.user_id;
let wsUrl = configWs.ws_url
let wsProxyUrl = configWs.ws_proxy_url;
let ws_token = configWs.ws_token;
let textList = [text]
let atList = configWs.at_list
await send(wsProxyUrl, wsUrl, ws_token, action, group_id, user_id, textList, atList)
}
this.wsUtil = {
send,
sendText
}