diff --git a/manifest.json b/manifest.json index 6f457e1..805eb84 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "manifest_version": 4, "type": "extension", - "name": "LLOneBot v3.13.10", + "name": "LLOneBot v3.13.11", "slug": "LLOneBot", "description": "LiteLoaderQQNT的OneBotApi", - "version": "3.13.10", + "version": "3.13.11", "thumbnail": "./icon.png", "authors": [ { diff --git a/scripts/test/test_db.ts b/scripts/test/test_db.ts new file mode 100644 index 0000000..f63f109 --- /dev/null +++ b/scripts/test/test_db.ts @@ -0,0 +1,17 @@ +import {Level} from "level" + +const db = new Level(process.env["level_db_path"], {valueEncoding: 'json'}); + +async function getGroupNotify() { + let keys = await db.keys().all(); + let result = [] + for (const key of keys) { + // console.log(key) + if (key.startsWith("group_notify_")) { + result.push(key) + } + } + return result +} + +getGroupNotify().then(console.log) \ No newline at end of file diff --git a/src/common/data.ts b/src/common/data.ts index a766e5c..30f1b53 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -21,7 +21,6 @@ export const selfInfo: SelfInfo = { } export let groups: Group[] = [] export let friends: Friend[] = [] -export let groupNotifies: Map = new Map() export let friendRequests: Map = new Map() export const llonebotError: LLOneBotError = { ffmpegError: '', diff --git a/src/common/db.ts b/src/common/db.ts index 3600c32..e8141f1 100644 --- a/src/common/db.ts +++ b/src/common/db.ts @@ -1,17 +1,18 @@ import {Level} from "level"; -import {RawMessage} from "../ntqqapi/types"; +import {type GroupNotify, RawMessage} from "../ntqqapi/types"; import {DATA_DIR, log} from "./utils"; import {selfInfo} from "./data"; import {FileCache} from "./types"; class DBUtil { - private readonly DB_KEY_PREFIX_MSG_ID = "msg_id_"; - private readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_"; - private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_"; - private readonly DB_KEY_PREFIX_FILE = "file_"; - private db: Level; - public cache: Record = {} // : RawMessage + public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_"; + public readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_"; + public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_"; + public readonly DB_KEY_PREFIX_FILE = "file_"; + public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_"; + public db: Level; + public cache: Record = {} // : RawMessage private currentShortId: number; /* @@ -203,6 +204,29 @@ class DBUtil { } } + + async addGroupNotify(notify: GroupNotify) { + const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + notify.seq; + let existNotify = this.cache[key] as GroupNotify + if (existNotify){ + return + } + this.cache[key] = notify; + this.db.put(key, JSON.stringify(notify)).then(); + } + + async getGroupNotify(seq: string): Promise { + const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + seq; + if (this.cache[key]) { + return this.cache[key] as GroupNotify + } + try { + let data = await this.db.get(key); + return JSON.parse(data); + } catch (e) { + + } + } } export const dbUtil = new DBUtil(); \ No newline at end of file diff --git a/src/main/main.ts b/src/main/main.ts index 74eda25..f59df63 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -16,7 +16,6 @@ import { friendRequests, getFriend, getGroup, getGroupMember, - groupNotifies, llonebotError, refreshGroupMembers, selfInfo } from "../common/data"; @@ -251,19 +250,17 @@ function onLoad() { for (const notify of notifies) { try { notify.time = Date.now(); - const notifyTime = parseInt(notify.seq) / 1000 + // const notifyTime = parseInt(notify.seq) / 1000 // log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`); // if (notifyTime < startTime) { // continue; // } - let existNotify = groupNotifies[notify.seq]; + let existNotify = await dbUtil.getGroupNotify(notify.seq); if (existNotify) { - if (Date.now() - existNotify.time < 3000) { - continue - } + continue } log("收到群通知", notify); - groupNotifies[notify.seq] = notify; + await dbUtil.addGroupNotify(notify); // let member2: GroupMember; // if (notify.user2.uid) { // member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid); diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index a838867..3310b8d 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -21,7 +21,7 @@ import { CacheFileList, CacheFileListItem, CacheFileType, } from "./types"; import * as fs from "fs"; -import {friendRequests, groupNotifies, selfInfo, uidMaps} from "../common/data"; +import {friendRequests, selfInfo, uidMaps} from "../common/data"; import {v4 as uuidv4} from "uuid" import path from "path"; import {dbUtil} from "../common/db"; @@ -590,11 +590,11 @@ export class NTQQApi { } static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) { - const notify: GroupNotify = groupNotifies[seq]; + const notify: GroupNotify = await dbUtil.getGroupNotify(seq) if (!notify) { throw `${seq}对应的加群通知不存在` } - delete groupNotifies[seq]; + // delete groupNotifies[seq]; return await callNTQQApi({ methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST, args: [ diff --git a/src/ntqqapi/types.ts b/src/ntqqapi/types.ts index 62e9e9e..542f319 100644 --- a/src/ntqqapi/types.ts +++ b/src/ntqqapi/types.ts @@ -366,7 +366,7 @@ export interface GroupNotifies { export interface GroupNotify { time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify - seq: string, // 转成数字,再除以1000应该就是时间戳? + seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳? type: GroupNotifyTypes, status: 0, // 未知 group: { groupCode: string, groupName: string }, diff --git a/src/onebot11/action/SetGroupAddRequest.ts b/src/onebot11/action/SetGroupAddRequest.ts index 434ab43..53f3cec 100644 --- a/src/onebot11/action/SetGroupAddRequest.ts +++ b/src/onebot11/action/SetGroupAddRequest.ts @@ -1,6 +1,5 @@ import BaseAction from "./BaseAction"; -import {groupNotifies} from "../../common/data"; -import {GroupNotify, GroupRequestOperateTypes} from "../../ntqqapi/types"; +import {GroupRequestOperateTypes} from "../../ntqqapi/types"; import {NTQQApi} from "../../ntqqapi/ntcall"; import {ActionName} from "./types"; @@ -17,15 +16,10 @@ export default class SetGroupAddRequest extends BaseAction { protected async _handle(payload: Payload): Promise { const seq = payload.flag.toString(); - const notify: GroupNotify = groupNotifies[seq] - try { - await NTQQApi.handleGroupRequest(seq, - payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, - payload.reason - ) - } catch (e) { - throw e - } + await NTQQApi.handleGroupRequest(seq, + payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, + payload.reason + ) return null } } \ No newline at end of file diff --git a/src/version.ts b/src/version.ts index f519d28..b4b5657 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = "3.13.10" \ No newline at end of file +export const version = "3.13.11" \ No newline at end of file