mirror of https://github.com/Nofated095/Q2TG.git
fix: mapInstance 启用时触发多次 /q
This commit is contained in:
parent
084e23be4a
commit
df9fd35a32
|
@ -0,0 +1,29 @@
|
|||
import Instance from '../models/Instance';
|
||||
import Telegram from '../client/Telegram';
|
||||
import OicqClient from '../client/OicqClient';
|
||||
import { GroupMessageEvent, MiraiElem, PrivateMessageEvent } from 'icqq';
|
||||
|
||||
export default class {
|
||||
constructor(private readonly instance: Instance,
|
||||
private readonly tgBot: Telegram,
|
||||
private readonly tgUser: Telegram,
|
||||
private readonly qqBot: OicqClient) {
|
||||
qqBot.addNewMessageEventHandler(this.onQqMessage);
|
||||
}
|
||||
|
||||
// 当 mapInstance 用同服务器其他个人模式账号发送消息后,message mirai 会带 q2tgSkip=true
|
||||
// 防止 bot 重新收到消息再转一圈回来重新转发或者重新响应命令
|
||||
private onQqMessage = async (event: PrivateMessageEvent | GroupMessageEvent) => {
|
||||
if ('friend' in event) return;
|
||||
if (!event.message) return;
|
||||
const messageMirai = event.message.find(it => it.type === 'mirai') as MiraiElem;
|
||||
if (messageMirai) {
|
||||
try {
|
||||
const miraiData = JSON.parse(messageMirai.data);
|
||||
if (miraiData.q2tgSkip) return true;
|
||||
}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -23,6 +23,7 @@ import { QqBot } from '@prisma/client';
|
|||
import StatusReportController from '../controllers/StatusReportController';
|
||||
import HugController from '../controllers/HugController';
|
||||
import QuotLyController from '../controllers/QuotLyController';
|
||||
import MiraiSkipFilterController from '../controllers/MiraiSkipFilterController';
|
||||
|
||||
export default class Instance {
|
||||
private _owner = 0;
|
||||
|
@ -55,6 +56,7 @@ export default class Instance {
|
|||
private statusReportController: StatusReportController;
|
||||
private hugController: HugController;
|
||||
private quotLyController: QuotLyController;
|
||||
private miraiSkipFilterController: MiraiSkipFilterController;
|
||||
|
||||
private constructor(public readonly id: number) {
|
||||
this.log = getLogger(`Instance - ${this.id}`);
|
||||
|
@ -149,6 +151,7 @@ export default class Instance {
|
|||
this.requestController = new RequestController(this, this.tgBot, this.oicq);
|
||||
this.configController = new ConfigController(this, this.tgBot, this.tgUser, this.oicq);
|
||||
this.deleteMessageController = new DeleteMessageController(this, this.tgBot, this.tgUser, this.oicq);
|
||||
this.miraiSkipFilterController = new MiraiSkipFilterController(this, this.tgBot, this.tgUser, this.oicq);
|
||||
this.inChatCommandsController = new InChatCommandsController(this, this.tgBot, this.tgUser, this.oicq);
|
||||
if (this.workMode === 'group') {
|
||||
this.hugController = new HugController(this, this.tgBot, this.oicq);
|
||||
|
|
|
@ -91,16 +91,6 @@ export default class ForwardService {
|
|||
|
||||
public async forwardFromQq(event: PrivateMessageEvent | GroupMessageEvent, pair: Pair) {
|
||||
try {
|
||||
const messageMirai = event.message.find(it => it.type === 'mirai') as MiraiElem;
|
||||
if (messageMirai) {
|
||||
try {
|
||||
const miraiData = JSON.parse(messageMirai.data);
|
||||
if (miraiData.q2tgSkip) return;
|
||||
}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
|
||||
const tempFiles: FileResult[] = [];
|
||||
let message = '', files: FileLike[] = [], buttons: ButtonLike[] = [], replyTo = 0;
|
||||
let messageHeader = '', sender = '';
|
||||
|
|
Loading…
Reference in New Issue