(
channelInfo: { title: string; handle: string; linkedGroup?: string },
query: string
)
| 119 | } |
| 120 | |
| 121 | private async searchInChannelWithLinkedGroup( |
| 122 | channelInfo: { title: string; handle: string; linkedGroup?: string }, |
| 123 | query: string |
| 124 | ): Promise<Api.Message[]> { |
| 125 | const videos: Api.Message[] = []; |
| 126 | if (!channelInfo.linkedGroup) return []; |
| 127 | |
| 128 | try { |
| 129 | const linkedGroupEntity = await this.client.getEntity(channelInfo.linkedGroup); |
| 130 | const groupMessages = await safeGetMessages(this.client, linkedGroupEntity, { |
| 131 | limit: 100, |
| 132 | search: query, |
| 133 | }); |
| 134 | |
| 135 | for (const textMsg of groupMessages) { |
| 136 | if (this.isMessageMatching(textMsg, query) && textMsg.replies) { |
| 137 | console.log(`找到匹配消息 #${textMsg.id},正在精确获取其 ${textMsg.replies.replies} 条评论...`); |
| 138 | const comments = await safeGetMessages(this.client, linkedGroupEntity, { |
| 139 | limit: 100, |
| 140 | replyTo: textMsg.id, |
| 141 | }); |
| 142 | |
| 143 | const videoReplies = comments.filter((msg: Api.Message) => |
| 144 | msg.video && |
| 145 | !(msg.media instanceof Api.MessageMediaWebPage) && |
| 146 | !this.isAdContent(msg) |
| 147 | ); |
| 148 | |
| 149 | if (videoReplies.length > 0) { |
| 150 | console.log(`在评论区找到 ${videoReplies.length} 个视频。`); |
| 151 | videos.push(...videoReplies); |
| 152 | return videos; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (videos.length === 0) { |
| 158 | const groupVideoMessages = await safeGetMessages(this.client, linkedGroupEntity, { |
| 159 | limit: 100, |
| 160 | search: query, |
| 161 | filter: new Api.InputMessagesFilterVideo(), |
| 162 | }); |
| 163 | |
| 164 | const pureVideos = groupVideoMessages.filter((v: Api.Message) => |
| 165 | v.video && |
| 166 | !(v.media instanceof Api.MessageMediaWebPage) && |
| 167 | !this.isAdContent(v) |
| 168 | ); |
| 169 | |
| 170 | if (pureVideos.length > 0) { |
| 171 | videos.push(...pureVideos); |
| 172 | } |
| 173 | } |
| 174 | } catch (linkedGroupError: any) { |
| 175 | console.error(`访问关联讨论组失败: ${linkedGroupError.message}`); |
| 176 | } |
| 177 | return videos; |
| 178 | } |
no test coverage detected