mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-25 04:59:52 +08:00
feat(ActivitySwitchNotice): 添加云端配置功能并改变wsproxy授权方式 (#3029)
- 新增云端配置功能 - 改变wsproxy授权方式为授权token或bettergi-scripts-tools授权拉取 - 在设置界面添加独立通知配置选项包括自定义通知和bgi-tools通知 - 添加bgi-tools获取授权wsproxy api地址输入框 - 添加bgi_tools授权token配置项 - 更新WebSocketProxyUrl默认路径 - 实现从bgi-tools获取ws信息的功能 - 添加getToken函数用于解析授权token - 实现pullAccessWsProxyConfig函数用于拉取ws代理配置 - 更新发送消息时携带uid和授权token信息
This commit is contained in:
@@ -511,6 +511,9 @@ ActivitySwitchNotice/
|
||||
|
||||
## 版本历史
|
||||
|
||||
### 0.1.2 (2026-03-23)
|
||||
- 新增云端配置功能
|
||||
- 改变wsproxy授权方式(授权token或bettergi-scripts-tools<版本需求0.0.7>授权拉取)
|
||||
### 0.1.1 (2026-03-16)
|
||||
- 周本提醒日 升为多选
|
||||
- 适配新秘境征讨UI
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "活动期限/周本通知器",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "",
|
||||
"settings_ui": "settings.json",
|
||||
"main": "main.js",
|
||||
|
||||
@@ -101,11 +101,45 @@
|
||||
{
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"name": "wsNoticeType",
|
||||
"type": "select",
|
||||
"label": "独立通知配置(设置):\n==============================\n",
|
||||
"options": [
|
||||
"自定义通知",
|
||||
"bgi-tools通知"
|
||||
],
|
||||
"default": "自定义通知"
|
||||
},
|
||||
{
|
||||
"name": "http_api_access_ws_proxy",
|
||||
"type": "input-text",
|
||||
"label": "bgi-tools获取授权wsproxy api地址",
|
||||
"default": "http://127.0.0.1:8081/bgi/ws-proxy/access"
|
||||
},
|
||||
{
|
||||
"name": "bgi_tools_token",
|
||||
"type": "input-text",
|
||||
"label": "bgi_tools授权token 语法:tokenName=tokenValue",
|
||||
"default": "Authorization= "
|
||||
},
|
||||
{
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"name": "ws_proxy_url",
|
||||
"type": "input-text",
|
||||
"label": "独立通知配置:\n==============================\nWebSocketProxyUrl(列:http://127.0.0.1:8081/ws-proxy/message/send)",
|
||||
"default": "http://127.0.0.1:8081/ws-proxy/message/send"
|
||||
"label": "WebSocketProxyUrl(列:http://127.0.0.1:8081/bgi/ws-proxy/message/send)",
|
||||
"default": "http://127.0.0.1:8081/bgi/ws-proxy/message/send"
|
||||
},
|
||||
{
|
||||
"name": "ws_url",
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {config} from "../../AutoPlan/config/config";
|
||||
import {ocrUID} from "./uid";
|
||||
|
||||
const actionType = Object.freeze({
|
||||
send_private_msg: 'send_private_msg',//私聊
|
||||
send_group_msg: 'send_group_msg',//群聊
|
||||
@@ -41,6 +44,10 @@ let configWs = {
|
||||
ws_token: settings.ws_token,
|
||||
at_list: settings.at_list ? settings.at_list.split(",") : []
|
||||
}
|
||||
let local = {
|
||||
token: null,
|
||||
uid: null,
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -50,19 +57,80 @@ let configWs = {
|
||||
* 目前函数体为空,可以根据实际需求添加初始化逻辑
|
||||
*/
|
||||
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(",") : []
|
||||
const uid = await ocrUID()
|
||||
local.token = await getToken()
|
||||
local.uid = uid
|
||||
if (settings.wsNoticeType === "自定义通知") {
|
||||
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(",") : []
|
||||
}
|
||||
} else {
|
||||
//从bgi-tools获取ws信息
|
||||
const configWsT = await pullAccessWsProxyConfig(local.uid, settings.http_api_access_ws_proxy)
|
||||
if (!configWsT) {
|
||||
// log.error("获取ws信息失败")
|
||||
throw new Error("获取ws授权信息失败")
|
||||
}
|
||||
configWs = configWsT
|
||||
configWs.at_list = configWsT.at_list ? configWsT.at_list.split(",") : []
|
||||
}
|
||||
log.debug(`configWs:{configWs}`, JSON.stringify(configWs))
|
||||
log.info('ws init success')
|
||||
}
|
||||
|
||||
async function getToken() {
|
||||
let token = {
|
||||
name: "",
|
||||
value: ""
|
||||
}
|
||||
const bgi_tools_token = settings.bgi_tools_token || "Authorization= "
|
||||
// const list = Array.from(bgi_tools_token.split("=")).map(item => item.trim());
|
||||
// config.bgi_tools.token.name = list[0]
|
||||
// config.bgi_tools.token.value = list[1]
|
||||
|
||||
const separatorIndex = bgi_tools_token.indexOf("=");
|
||||
if (separatorIndex !== -1) {
|
||||
token.name = bgi_tools_token.substring(0, separatorIndex).trim();
|
||||
token.value = bgi_tools_token.substring(separatorIndex + 1).trim();
|
||||
} else {
|
||||
token.name = bgi_tools_token.trim();
|
||||
token.value = "";
|
||||
}
|
||||
try {
|
||||
return token;
|
||||
} finally {
|
||||
local.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
export async function pullAccessWsProxyConfig(uid, http_api) {
|
||||
let token = local.token;
|
||||
let value = {
|
||||
"Content-Type": "application/json",
|
||||
[token.name]: token.value
|
||||
};
|
||||
http_api += "?uid=" + uid
|
||||
// 发送HTTP请求
|
||||
const httpResponse = await http.request("GET", http_api, JSON.stringify({}), JSON.stringify(value));
|
||||
// 检查响应状态码
|
||||
if (httpResponse.status_code != 200) {
|
||||
// 错误日志输出服务器响应
|
||||
log.error(`服务器返回状态${httpResponse.headers} ${httpResponse.body}`);
|
||||
} else {
|
||||
let result_json = JSON.parse(httpResponse.body);
|
||||
if (result_json?.code === 200) {
|
||||
return result_json?.data
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息的异步函数
|
||||
* @param {string} wsProxyUrl - WebSocket代理URL
|
||||
@@ -76,6 +144,7 @@ async function init() {
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async function send(wsProxyUrl, wsUrl, wsToken, action, group_id, user_id, textList, atList) {
|
||||
const uid = local.uid
|
||||
// 构建基础JSON对象
|
||||
let json = {
|
||||
action: action,//send_group_msg群发、send_private_msg私聊
|
||||
@@ -84,6 +153,7 @@ async function send(wsProxyUrl, wsUrl, wsToken, action, group_id, user_id, textL
|
||||
// user_id: user_id,//QQ号
|
||||
// message: []
|
||||
// }
|
||||
uid: uid
|
||||
}
|
||||
// 根据动作类型设置不同的参数
|
||||
switch (action) {
|
||||
@@ -122,7 +192,7 @@ async function send(wsProxyUrl, wsUrl, wsToken, action, group_id, user_id, textL
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let token = local.token;
|
||||
// 构建请求体
|
||||
let body = {
|
||||
url: wsUrl,
|
||||
@@ -133,10 +203,13 @@ async function send(wsProxyUrl, wsUrl, wsToken, action, group_id, user_id, textL
|
||||
log.debug(`body:{key}`, JSON.stringify(body))
|
||||
// 信息日志记录HTTP请求开始
|
||||
log.info('http request start')
|
||||
let value = {
|
||||
"Content-Type": "application/json",
|
||||
[token.name]: token.value
|
||||
};
|
||||
|
||||
// 发送HTTP请求
|
||||
const httpResponse = await http.request("POST", wsProxyUrl, JSON.stringify(body), JSON.stringify({
|
||||
"Content-Type": "application/json"
|
||||
}));
|
||||
const httpResponse = await http.request("POST", wsProxyUrl, JSON.stringify(body), JSON.stringify(value));
|
||||
// 检查响应状态码
|
||||
if (httpResponse.status_code != 200) {
|
||||
// 错误日志输出服务器响应
|
||||
|
||||
Reference in New Issue
Block a user