diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index 66dac82..4976b9e 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -158,36 +158,6 @@ export default class ConfigService { await status.edit({ text: '正在创建 Telegram 群…', buttons: Button.clear() }); } - if (!chat) { - // 创建群聊,拿到的是 user 的 chat - chat = await this.tgUser.createChat(title, await getAboutText(room, false)); - - // 添加机器人 - status && await status.edit({ text: '正在添加机器人…' }); - await chat.inviteMember(this.tgBot.me.id); - } - - // 设置管理员 - status && await status.edit({ text: '正在设置管理员…' }); - await chat.setAdmin(this.tgBot.me.username); - - // 添加到 Filter - try { - status && await status.edit({ text: '正在将群添加到文件夹…' }); - const dialogFilters = await this.tgUser.getDialogFilters() as Api.DialogFilter[]; - const filter = dialogFilters.find(e => e.id === DEFAULT_FILTER_ID); - if (filter) { - filter.includePeers.push(utils.getInputPeer(chat)); - await this.tgUser.updateDialogFilter({ - id: DEFAULT_FILTER_ID, - filter, - }); - } - } - catch (e) { - errorMessage += `\n添加到文件夹失败:${e.message}`; - } - // 关闭【添加成员】快捷条 try { status && await status.edit({ text: '正在关闭【添加成员】快捷条…' }); @@ -270,56 +240,7 @@ export default class ConfigService { } } else { - const chat = await this.tgUser.getChat(tgChatId); - await this.createGroupAndLink(qqRoomId, undefined, true, chat); - } - } - - // 创建 QQ 群组的文件夹 - public async setupFilter() { - const result = await this.tgUser.getDialogFilters() as Api.DialogFilter[]; - let filter = result.find(e => e.id === DEFAULT_FILTER_ID); - if (!filter) { - this.log.info('创建 TG 文件夹'); - // 要自己计算新的 id,随意 id 也是可以的 - // https://github.com/morethanwords/tweb/blob/7d646bc9a87d943426d831f30b69d61b743f51e0/src/lib/storages/filters.ts#L251 - // 创建 - filter = new Api.DialogFilter({ - id: DEFAULT_FILTER_ID, - title: 'QQ', - pinnedPeers: [ - (await this.tgUser.getChat(this.tgBot.me.username)).inputPeer, - ], - includePeers: [], - excludePeers: [], - emoticon: '🐧', - }); - let errorText = '设置文件夹失败'; - try { - const isSuccess = await this.tgUser.updateDialogFilter({ - id: DEFAULT_FILTER_ID, - filter, - }); - if (!isSuccess) { - this.log.error(errorText); - await (await this.owner).sendMessage(errorText); - } - } - catch (e) { - this.log.error(errorText, e); - await (await this.owner).sendMessage(errorText + `\n${e}`); - } - } - } - - public async migrateAllChats() { - const dbPairs = await db.forwardPair.findMany(); - for (const forwardPair of dbPairs) { - const chatForUser = await this.tgUser.getChat(Number(forwardPair.tgChatId)); - if (chatForUser.entity instanceof Api.Chat) { - this.log.info('升级群组 ', chatForUser.id); - await chatForUser.migrate(); - } + const chat = await tgChat = await this.tgBot.getChat(tgChatId); } } }