From 3c03ce63d37613f79449de491139029cb89e09a1 Mon Sep 17 00:00:00 2001 From: Clansty Date: Wed, 2 Mar 2022 14:07:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=85=A5=E6=96=B0=E7=BE=A4?= =?UTF-8?q?=E6=97=B6=E8=AF=A2=E9=97=AE=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ConfigController.ts | 10 +++++++++- src/services/ConfigService.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/controllers/ConfigController.ts b/src/controllers/ConfigController.ts index 657c46b..17b2754 100644 --- a/src/controllers/ConfigController.ts +++ b/src/controllers/ConfigController.ts @@ -5,7 +5,7 @@ import ConfigService from '../services/ConfigService'; import { config } from '../providers/userConfig'; import regExps from '../constants/regExps'; import forwardPairs from '../providers/forwardPairs'; -import { GroupMessageEvent, PrivateMessageEvent } from 'oicq'; +import { GroupMessageEvent, MemberIncreaseEvent, PrivateMessageEvent } from 'oicq'; export default class ConfigController { private readonly configService: ConfigService; @@ -18,6 +18,7 @@ export default class ConfigController { tgBot.addNewMessageEventHandler(this.handleMessage); tgBot.addNewServiceMessageEventHandler(this.handleServiceMessage); oicq.addNewMessageEventHandler(this.handleQqMessage); + config.workMode === 'personal' && oicq.on('notice.group.increase', this.handleMemberIncrease); this.configService.configCommands(); config.workMode === 'personal' && this.configService.setupFilter(); } @@ -66,6 +67,7 @@ export default class ConfigController { }; private handleServiceMessage = async (message: Api.MessageService) => { + // 用于检测群升级为超级群的情况 if (message.action instanceof Api.MessageActionChatMigrateTo) { const pair = forwardPairs.find((message.peerId as Api.PeerChat).chatId); if (!pair) return; @@ -89,4 +91,10 @@ export default class ConfigController { await promise; return false; }; + + private handleMemberIncrease = async (event: MemberIncreaseEvent) => { + if(event.user_id!==this.oicq.uin||await forwardPairs.find(event.group)) return; + // 是新群并且是自己加入了 + await this.configService.promptNewGroup(event.group) + }; } diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index 2851a1d..2c201a8 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -109,7 +109,13 @@ export default class ConfigService { // endregion - public async createGroupAndLink(roomId: number, title?: string, silent = false) { + /** + * + * @param roomId + * @param title + * @param status 传入 false 的话就不显示状态信息,可以传入一条已有消息覆盖 + */ + public async createGroupAndLink(roomId: number, title?: string, status: boolean | Api.Message = true) { this.log.info(`创建群组并关联:${roomId}`); const qEntity = this.oicq.getChat(roomId); if (!title) { @@ -124,7 +130,12 @@ export default class ConfigService { let isFinish = false; try { // 状态信息 - const status = !silent && await (await this.owner).sendMessage('正在创建 Telegram 群…'); + if (status === true) { + status = await (await this.owner).sendMessage('正在创建 Telegram 群…'); + } + else if (status instanceof Api.Message) { + await status.edit({ text: '正在创建 Telegram 群…', buttons: Button.clear() }); + } // 创建群聊,拿到的是 user 的 chat const chat = await this.tgUser.createChat({ @@ -189,6 +200,19 @@ export default class ConfigService { } } + public async promptNewGroup(group: Group) { + const message = await (await this.owner).sendMessage({ + message: '你加入了一个新的群:\n' + + `${group.name}\n` + + `${group.info.member_count} 名成员\n` + + `群号:${group.group_id}\n` + + '要创建关联群吗', + buttons: Button.inline('创建', this.tgBot.registerCallback( + () => this.createGroupAndLink(-group.group_id, group.name, message))), + }); + return message; + } + public async createLinkGroup(qqRoomId: number, tgChatId: number) { let message: string; try {