From 9067a1fc9212e030c6e1fbe2636e713fa3188c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 28 May 2024 23:24:54 +0800 Subject: [PATCH] refactor: info record local --- src/common/utils/helper.ts | 3 ++- .../action/group/GetGroupMemberList.ts | 2 +- src/onebot11/config.ts | 8 +++---- src/onebot11/main.ts | 2 +- src/webui/ui/NapCat.ts | 21 ++++++++++++++++--- src/webui/ui/components/WebUiApiOB11Config.ts | 3 ++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/common/utils/helper.ts b/src/common/utils/helper.ts index 8c44094b..3d7cb267 100644 --- a/src/common/utils/helper.ts +++ b/src/common/utils/helper.ts @@ -145,7 +145,8 @@ export function migrateConfig(oldConfig: any) { musicSignUrl: oldConfig.musicSignUrl, reportSelfMessage: oldConfig.reportSelfMessage, token: oldConfig.token, - GroupLocalTimeRecord: [] + GroupLocalTimeRecord: false, + GroupLocalTimeRecordList: [] }; return newConfig; } diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index 0223acee..63e2d4cf 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -62,7 +62,7 @@ class GetGroupMemberList extends BaseAction { MemberMap.set(webGroupMembers[i]?.uin, MemberData); } } - } else if (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.includes(payload.group_id)) { + } else if (ob11Config.GroupLocalTimeRecord && ob11Config.GroupLocalTimeRecordList[0] === -1 || ob11Config.GroupLocalTimeRecordList.includes(payload.group_id)) { const _sendAndJoinRember = await dbUtil.getLastSentTimeAndJoinTime(payload.group_id); _sendAndJoinRember.forEach((element) => { let MemberData = MemberMap.get(element.user_id); diff --git a/src/onebot11/config.ts b/src/onebot11/config.ts index d4193d5f..7c5c4498 100644 --- a/src/onebot11/config.ts +++ b/src/onebot11/config.ts @@ -32,8 +32,8 @@ export interface OB11Config { musicSignUrl: string; reportSelfMessage: boolean; token: string; - - GroupLocalTimeRecord: Array; + GroupLocalTimeRecord: boolean; + GroupLocalTimeRecordList: Array; read(): OB11Config; @@ -66,8 +66,8 @@ class Config extends ConfigBase implements OB11Config { musicSignUrl = ''; reportSelfMessage = false; token = ''; - - GroupLocalTimeRecord = [] as Array; + GroupLocalTimeRecord = false; + GroupLocalTimeRecordList = [] as Array; getConfigPath() { return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`); diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index d135cffa..aabf797a 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -287,7 +287,7 @@ export class NapCatOnebot11 { if (msg.post_type === 'message') { logMessage(msg as OB11Message).then().catch(logError); // 大概测试了一下,10000个以内 includes 和 find 性能差距不大 - if (msg.message_type == 'group' && msg.group_id && (ob11Config.GroupLocalTimeRecord[0] === -1 || ob11Config.GroupLocalTimeRecord.find(gid=>gid == msg.group_id))) { + if (msg.message_type == 'group' && msg.group_id && ob11Config.GroupLocalTimeRecord && (ob11Config.GroupLocalTimeRecordList[0] === -1 || ob11Config.GroupLocalTimeRecordList.find(gid=>gid == msg.group_id))) { dbUtil.insertLastSentTime(msg.group_id, msg.user_id, msg.time); } } else if (msg.post_type === 'notice') { diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index 240033eb..50c47411 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -69,7 +69,7 @@ async function onSettingWindowCreated(view: Element) {
+ }" placeholder="未设置" />
@@ -101,8 +101,7 @@ async function onSettingWindowCreated(view: Element) { 'control-display-id': 'config-ob11-reverseWs-urls', }) ), - `
+ `
反向 WebSocket 监听地址 @@ -138,7 +137,23 @@ async function onSettingWindowCreated(view: Element) { undefined, `
`, 'ob11.musicSignUrl' + ), + SettingItem( + '启用本地进群时间与发言时间记录', + undefined, + SettingSwitch('ob11.GroupLocalTimeRecord', ob11Config.reverseWs.enable, { + 'control-display-id': 'config-ob11-GroupLocalTimeRecordList', + }) ), + `
+ +
+ 反向 WebSocket 监听地址 +
+ 添加 +
+
+
`, SettingItem( '', undefined, diff --git a/src/webui/ui/components/WebUiApiOB11Config.ts b/src/webui/ui/components/WebUiApiOB11Config.ts index 31aa45a4..6144566b 100644 --- a/src/webui/ui/components/WebUiApiOB11Config.ts +++ b/src/webui/ui/components/WebUiApiOB11Config.ts @@ -26,7 +26,8 @@ export interface OB11Config { musicSignUrl: ''; reportSelfMessage: boolean; token: ''; - GroupLocalTimeRecord: []; + GroupLocalTimeRecord: false; + GroupLocalTimeRecordList: []; } class WebUiApiOB11ConfigWrapper {