mirror of https://github.com/Nofated095/Q2TG.git
feat: 通过命令启用和关闭转发
This commit is contained in:
parent
f241352422
commit
3ca022088d
|
@ -74,6 +74,7 @@ model ForwardPair {
|
|||
instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
joinNotice Boolean @default(true)
|
||||
poke Boolean @default(true)
|
||||
enable Boolean @default(true)
|
||||
|
||||
@@unique([qqRoomId, instanceId])
|
||||
@@unique([tgChatId, instanceId])
|
||||
|
|
|
@ -47,6 +47,14 @@ const groupInChatCommands = [
|
|||
command: 'info',
|
||||
description: '查看本群或选定消息的详情',
|
||||
}),
|
||||
new Api.BotCommand({
|
||||
command: 'forwardoff',
|
||||
description: '暂停消息转发',
|
||||
}),
|
||||
new Api.BotCommand({
|
||||
command: 'forwardon',
|
||||
description: '恢复消息转发',
|
||||
}),
|
||||
];
|
||||
|
||||
const personalInChatCommands = [
|
||||
|
|
|
@ -41,6 +41,7 @@ export default class ForwardController {
|
|||
const target = event.message_type === 'private' ? event.friend : event.group;
|
||||
const pair = this.instance.forwardPairs.find(target);
|
||||
if (!pair) return;
|
||||
if (!pair.enable) return;
|
||||
const tgMessages = await this.forwardService.forwardFromQq(event, pair);
|
||||
for (const tgMessage of tgMessages) {
|
||||
// 更新数据库
|
||||
|
@ -70,6 +71,7 @@ export default class ForwardController {
|
|||
if (message.senderId?.eq(this.instance.botMe.id)) return true;
|
||||
const pair = this.instance.forwardPairs.find(message.chat);
|
||||
if (!pair) return false;
|
||||
if (!pair.enable) return;
|
||||
const qqMessagesSent = await this.forwardService.forwardFromTelegram(message, pair);
|
||||
if (qqMessagesSent) {
|
||||
// 更新数据库
|
||||
|
|
|
@ -36,6 +36,14 @@ export default class InChatCommandsController {
|
|||
case '/poke':
|
||||
await this.service.poke(message, pair);
|
||||
return true;
|
||||
case '/forwardoff':
|
||||
pair.enable = false;
|
||||
await message.reply({ message: '转发已禁用' });
|
||||
return true;
|
||||
case '/forwardon':
|
||||
pair.enable = true;
|
||||
await message.reply({ message: '转发已启用' });
|
||||
return true;
|
||||
case '/refresh':
|
||||
if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false;
|
||||
await pair.updateInfo();
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class ForwardPairs {
|
|||
const qq = oicq.getChat(Number(i.qqRoomId));
|
||||
const tg = await tgBot.getChat(Number(i.tgChatId));
|
||||
if (qq && tg) {
|
||||
this.pairs.push(new Pair(qq, tg, i.id, i.joinNotice, i.poke));
|
||||
this.pairs.push(new Pair(qq, tg, i.id, i.joinNotice, i.poke, i.enable));
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -49,7 +49,7 @@ export default class ForwardPairs {
|
|||
instanceId: this.instanceId,
|
||||
},
|
||||
});
|
||||
this.pairs.push(new Pair(qq, tg, dbEntry.id, true, true));
|
||||
this.pairs.push(new Pair(qq, tg, dbEntry.id, true, true, true));
|
||||
return dbEntry;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@ export class Pair {
|
|||
constructor(public readonly qq: Friend | Group,
|
||||
private _tg: TelegramChat,
|
||||
public dbId: number,
|
||||
public joinNotice: boolean,
|
||||
public poke: boolean) {
|
||||
private _joinNotice: boolean,
|
||||
private _poke: boolean,
|
||||
private _enable: boolean) {
|
||||
}
|
||||
|
||||
// 更新 TG 群组的头像和简介
|
||||
|
@ -56,4 +57,43 @@ export class Pair {
|
|||
})
|
||||
.then(() => log.info(`出现了到超级群组的转换: ${value.id}`));
|
||||
}
|
||||
|
||||
get joinNotice() {
|
||||
return this._joinNotice;
|
||||
}
|
||||
|
||||
set joinNotice(value) {
|
||||
this._joinNotice = value;
|
||||
db.forwardPair.update({
|
||||
where: { id: this.dbId },
|
||||
data: { joinNotice: value },
|
||||
})
|
||||
.then(() => 0);
|
||||
}
|
||||
|
||||
get poke() {
|
||||
return this._poke;
|
||||
}
|
||||
|
||||
set poke(value) {
|
||||
this._poke = value;
|
||||
db.forwardPair.update({
|
||||
where: { id: this.dbId },
|
||||
data: { poke: value },
|
||||
})
|
||||
.then(() => 0);
|
||||
}
|
||||
|
||||
get enable() {
|
||||
return this._enable;
|
||||
}
|
||||
|
||||
set enable(value) {
|
||||
this._enable = value;
|
||||
db.forwardPair.update({
|
||||
where: { id: this.dbId },
|
||||
data: { enable: value },
|
||||
})
|
||||
.then(() => 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue