| 81 | } |
| 82 | |
| 83 | private async discoverLinkedGroup(channel: Api.Channel): Promise<string | undefined> { |
| 84 | try { |
| 85 | const fullChannel = await this.client.invoke( |
| 86 | new Api.channels.GetFullChannel({ |
| 87 | channel: channel, |
| 88 | }) |
| 89 | ); |
| 90 | |
| 91 | if (fullChannel.fullChat.linkedChatId) { |
| 92 | const linkedChatId = fullChannel.fullChat.linkedChatId; |
| 93 | const linkedGroup = await this.client.getEntity(linkedChatId); |
| 94 | if (linkedGroup instanceof Api.Channel && linkedGroup.megagroup) { |
| 95 | if (linkedGroup.username) { |
| 96 | return `@${linkedGroup.username}`; |
| 97 | } else { |
| 98 | try { |
| 99 | const inviteLink = await this.client.invoke( |
| 100 | new Api.messages.ExportChatInvite({ |
| 101 | peer: linkedGroup |
| 102 | }) |
| 103 | ); |
| 104 | if (inviteLink instanceof Api.ChatInviteExported) { |
| 105 | return inviteLink.link; |
| 106 | } |
| 107 | } catch (linkError: any) { |
| 108 | console.log(`获取邀请链接失败: ${linkError.message}`); |
| 109 | } |
| 110 | return undefined; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | return undefined; |
| 115 | } catch (error: any) { |
| 116 | console.log(`获取频道关联讨论组失败: ${error.message}`); |
| 117 | return undefined; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | private async searchInChannelWithLinkedGroup( |
| 122 | channelInfo: { title: string; handle: string; linkedGroup?: string }, |