refactor: 重构 Onebot 配置格式,增强可读性

This commit is contained in:
SherkeyXD
2024-05-14 20:17:53 +08:00
parent 7b5c332726
commit e91ed34b40
9 changed files with 259 additions and 230 deletions

View File

@@ -16,7 +16,7 @@ class OB11HTTPServer extends HttpServerBase {
}
protected listen(port: number, host: string) {
if (ob11Config.enableHttp) {
if (ob11Config.http.enable) {
super.listen(port, host);
}
}

View File

@@ -78,19 +78,19 @@ export function postOB11Event(msg: PostEventType, reportSelf = false, postWs = t
return;
}
}
if (config.enableHttpPost) {
if (config.http.enablePost) {
const msgStr = JSON.stringify(msg);
const hmac = crypto.createHmac('sha1', ob11Config.httpSecret);
const hmac = crypto.createHmac('sha1', ob11Config.http.secret);
hmac.update(msgStr);
const sig = hmac.digest('hex');
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'x-self-id': selfInfo.uin
};
if (config.httpSecret) {
if (config.http.secret) {
headers['x-signature'] = 'sha1=' + sig;
}
for (const host of config.httpPostUrls) {
for (const host of config.http.postUrls) {
fetch(host, {
method: 'POST',
headers,

View File

@@ -116,7 +116,7 @@ export class ReverseWebsocket {
class OB11ReverseWebsockets {
start() {
for (const url of ob11Config.wsReverseUrls) {
for (const url of ob11Config.reverseWs.urls) {
log('开始连接反向ws', url);
new Promise(() => {
try {