From 71684c95b6830fca350cd5182c331dece2f6d6d4 Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 00:15:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E4=BB=A5=E5=9C=A8=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=BD=BF=E7=94=A8=20/q=20?= =?UTF-8?q?=E7=94=9F=E6=88=90=20QuotLy=20=E6=80=AA=E8=AF=9D=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/QuotLyController.ts | 46 ++++++++++++++++++----------- src/models/Instance.ts | 5 +--- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/controllers/QuotLyController.ts b/src/controllers/QuotLyController.ts index 4371026..fb759c3 100644 --- a/src/controllers/QuotLyController.ts +++ b/src/controllers/QuotLyController.ts @@ -25,6 +25,7 @@ export default class { } private onQqMessage = async (event: PrivateMessageEvent | GroupMessageEvent) => { + if (this.instance.workMode === 'personal') return; if (event.message_type !== 'group') return; const pair = this.instance.forwardPairs.find(event.group); if (!pair) return; @@ -53,13 +54,16 @@ export default class { this.log.error('找不到 sourceMessage'); return true; } - try { - await this.sendQuote(pair, sourceMessage); - } - catch (e) { - this.log.error(e); - await event.reply(e.toString(), true); - } + setTimeout(async () => { + // 异步发送,为了让 /q 先到达 + try { + await this.sendQuote(pair, sourceMessage); + } + catch (e) { + this.log.error(e); + await event.reply(e.toString(), true); + } + }, 50); }; private onTelegramMessage = async (message: Api.Message) => { @@ -86,15 +90,20 @@ export default class { this.log.error('找不到 sourceMessage'); return true; } - try { - await this.sendQuote(pair, sourceMessage); - } - catch (e) { - this.log.error(e); - await message.reply({ - message: e.toString(), - }); - } + setTimeout(async () => { + try { + await this.sendQuote(pair, sourceMessage); + } + catch (e) { + this.log.error(e); + await message.reply({ + message: e.toString(), + }); + } + }, 50); + + // 个人模式下,/q 这条消息不转发到 QQ,怪话图只有自己可见 + if (this.instance.workMode === 'personal') return true; }; private async genQuote(message: Message) { @@ -287,10 +296,13 @@ export default class { const tgMessage = await pair.tg.sendMessage({ file: new CustomFile('quote.webp', image.length, undefined, image), }); + + if (this.instance.workMode === 'personal') return; + const qqMessage = await pair.qq.sendMsg({ type: 'image', file: image, - asface: true + asface: true, }); await db.message.create({ data: { diff --git a/src/models/Instance.ts b/src/models/Instance.ts index 604fd0b..e93bd59 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -151,11 +151,8 @@ export default class Instance { if (this.workMode === 'group') { this.hugController = new HugController(this, this.tgBot, this.oicq); } + this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); this.forwardController = new ForwardController(this, this.tgBot, this.tgUser, this.oicq); - if (this.workMode === 'group') { - // 希望那个 /q 也被转发 - this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); - } this.fileAndFlashPhotoController = new FileAndFlashPhotoController(this, this.tgBot, this.oicq); })() .then(() => this.log.info('初始化已完成'));