perf: 现有群升级为超级群后自动配置权限或者提示

This commit is contained in:
Clansty 2022-03-05 20:23:52 +08:00
parent 5d498f1a59
commit 7f3cb6e4f0
No known key found for this signature in database
GPG Key ID: 05F8479BA63A8E92
3 changed files with 17 additions and 5 deletions

View File

@ -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,
}),
);
}

View File

@ -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);
};
}

View File

@ -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: '正在将群添加到文件夹…' });