From 7f3cb6e4f04812253f47b5888a91b434e0316efc Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 5 Mar 2022 20:23:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=8E=B0=E6=9C=89=E7=BE=A4=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E4=B8=BA=E8=B6=85=E7=BA=A7=E7=BE=A4=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=85=8D=E7=BD=AE=E6=9D=83=E9=99=90=E6=88=96=E8=80=85?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/TelegramChat.ts | 4 ++-- src/controllers/ConfigController.ts | 16 ++++++++++++++-- src/services/ConfigService.ts | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/client/TelegramChat.ts b/src/client/TelegramChat.ts index 43ea4c9..376c53f 100644 --- a/src/client/TelegramChat.ts +++ b/src/client/TelegramChat.ts @@ -89,7 +89,7 @@ export default class TelegramChat { } } - public async editAdmin(user: EntityLike, isAdmin: boolean) { + public async setAdmin(user: EntityLike) { if (!(this.entity instanceof Api.Chat || this.entity instanceof Api.Channel)) throw new Error('不是群组,无法设置管理员'); if (this.entity instanceof Api.Chat) { @@ -97,7 +97,7 @@ export default class TelegramChat { new Api.messages.EditChatAdmin({ chatId: this.id, userId: user, - isAdmin, + isAdmin: true, }), ); } diff --git a/src/controllers/ConfigController.ts b/src/controllers/ConfigController.ts index 17b2754..247a63c 100644 --- a/src/controllers/ConfigController.ts +++ b/src/controllers/ConfigController.ts @@ -71,7 +71,19 @@ export default class ConfigController { if (message.action instanceof Api.MessageActionChatMigrateTo) { const pair = forwardPairs.find((message.peerId as Api.PeerChat).chatId); if (!pair) return; + // 会自动写入数据库 pair.tg = await this.tgBot.getChat(message.action.channelId); + // 升级之后 bot 的管理权限可能没了,需要修复一下 + if (config.workMode === 'personal') { + const chatForUser = await this.tgUser.getChat(message.action.channelId); + await chatForUser.setAdmin(this.tgBot.me.username); + } + else { + await pair.tg.sendMessage({ + message: '本群已升级为超级群,可能需要重新设置一下管理员权限', + silent: true, + }); + } } }; @@ -93,8 +105,8 @@ export default class ConfigController { }; private handleMemberIncrease = async (event: MemberIncreaseEvent) => { - if(event.user_id!==this.oicq.uin||await forwardPairs.find(event.group)) return; + if (event.user_id !== this.oicq.uin || await forwardPairs.find(event.group)) return; // 是新群并且是自己加入了 - await this.configService.promptNewGroup(event.group) + await this.configService.promptNewGroup(event.group); }; } diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index eec644d..3cb5210 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -151,7 +151,7 @@ export default class ConfigService { // 设置管理员 status && await status.edit({ text: '正在设置管理员…' }); - await chat.editAdmin(this.tgBot.me.username, true); + await chat.setAdmin(this.tgBot.me.username); // 添加到 Filter status && await status.edit({ text: '正在将群添加到文件夹…' });