From 832eeeeec73c9f86c6e4d59bee6935f08a5146ec Mon Sep 17 00:00:00 2001 From: sunlei Date: Sat, 20 Jun 2026 01:49:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DBilibili=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E7=BB=91=E5=AE=9A=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/bilibili-card-application.ts | 16 +---------- .../bilibili-card-application.spec.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/modules/qqbot/plugins/bilibili-card/src/application/bilibili-card-application.ts b/src/modules/qqbot/plugins/bilibili-card/src/application/bilibili-card-application.ts index 8aeefa5..b99c954 100644 --- a/src/modules/qqbot/plugins/bilibili-card/src/application/bilibili-card-application.ts +++ b/src/modules/qqbot/plugins/bilibili-card/src/application/bilibili-card-application.ts @@ -11,10 +11,6 @@ import { parseBilibiliVideoReference } from '../domain/bilibili-url-parser'; import { BilibiliVideoClient } from '../infrastructure/integration/bilibili-video-client'; export class BilibiliCardApplication { - private readonly boundCache = new Map< - string, - { expiresAt: number; value: boolean } - >(); private readonly dedupe = new Map(); private readonly videoClient: BilibiliVideoClient; @@ -117,20 +113,10 @@ export class BilibiliCardApplication { const normalizedSelfId = `${selfId || ''}`.trim(); if (!normalizedSelfId) return false; - const current = this.now(); - const cached = this.boundCache.get(normalizedSelfId); - if (cached && cached.expiresAt > current) return cached.value; - - const config = readBilibiliCardRuntimeConfig(this.host); try { - const value = ( + return ( await this.host.getBoundEventPluginKeys(normalizedSelfId) ).includes(this.manifest.pluginKey); - this.boundCache.set(normalizedSelfId, { - expiresAt: current + Math.min(config.dedupeTtlMs, 60000), - value, - }); - return value; } catch (error) { this.warn(`Bilibili 事件绑定查询失败: ${normalizeError(error)}`); return false; diff --git a/test/modules/qqbot/plugins/bilibili-card/bilibili-card-application.spec.ts b/test/modules/qqbot/plugins/bilibili-card/bilibili-card-application.spec.ts index 2ae3396..a5a0c8c 100644 --- a/test/modules/qqbot/plugins/bilibili-card/bilibili-card-application.spec.ts +++ b/test/modules/qqbot/plugins/bilibili-card/bilibili-card-application.spec.ts @@ -150,6 +150,33 @@ describe('Bilibili card application', () => { expect(host.sendText).toHaveBeenCalledTimes(1); }); + it('rechecks binding after an unbound message so newly bound accounts work immediately', async () => { + let current = 1000; + const host = createHost({ + getBoundEventPluginKeys: jest + .fn() + .mockResolvedValueOnce([]) + .mockResolvedValueOnce(['bilibili-card']), + requestJson: jest.fn().mockResolvedValue(createBilibiliViewResponse()), + }); + const application = new BilibiliCardApplication( + host, + createManifest(), + () => current, + ); + const message = createMessage({ + messageText: 'https://www.bilibili.com/video/BV1xx411c7mD', + }); + + await expect(application.handleMessage(message)).resolves.toBe(false); + current += 1000; + await expect(application.handleMessage(message)).resolves.toBe(true); + + expect(host.getBoundEventPluginKeys).toHaveBeenCalledTimes(2); + expect(host.requestJson).toHaveBeenCalledTimes(1); + expect(host.sendText).toHaveBeenCalledTimes(1); + }); + it('routes generic worker message events to package handler', async () => { const host = createHost({ getBoundEventPluginKeys: jest.fn().mockResolvedValue(['bilibili-card']),