( originMsg: Api.Message, link: string, baselineId: number, )
| 240 | return "客户端未就绪"; |
| 241 | default: |
| 242 | return "原因未知"; |
| 243 | } |
| 244 | }; |
| 245 | |
| 246 | async function forwardChunk(client: any, peer: any, ids: number[]) { |
| 247 | await client.forwardMessages(peer, { |
| 248 | fromPeer: BOT_USERNAME, |
| 249 | messages: ids, |
| 250 | dropAuthor: true, |
| 251 | }); |
| 252 | } |
| 253 | |
| 254 | async function relayParseResult( |
| 255 | originMsg: Api.Message, |
| 256 | link: string, |
| 257 | baselineId: number, |
| 258 | ): Promise<RelayOutcome> { |
| 259 | const client = originMsg.client; |
| 260 | if (!client) { |
| 261 | return { lastId: baselineId, forwarded: false, reason: "no_client" }; |
| 262 | } |
| 263 | |
| 264 | try { |
| 265 | await client.sendMessage(BOT_USERNAME, { message: link }); |
| 266 | } catch (error: any) { |
| 267 | return { |
| 268 | lastId: baselineId, |
| 269 | forwarded: false, |
| 270 | reason: "send_failed", |
| 271 | error: error?.message || String(error), |
| 272 | }; |
| 273 | } |
| 274 | |
| 275 | // Progress msgs (解析中/下载中/上传中) often keep the SAME id and are later |
| 276 | // edited into the final media. Never permanently skip them via processedIds. |
| 277 | const progressIds = new Set<number>(); |
| 278 | const finalMessages = new Map<number, Api.Message>(); |
| 279 | |
| 280 | let deadline = Date.now() + MAX_WAIT_MS; |
| 281 | let lastId = baselineId; |
| 282 | let lastFinalActivity = 0; |
| 283 | let lastProgressActivity = Date.now(); |
| 284 | let firstRunIgnore = shouldIgnoreNextBotMessage; |
| 285 | |
| 286 | while (Date.now() < deadline) { |
| 287 | await sleep(POLL_INTERVAL_MS); |
| 288 | |
| 289 | let messages: Api.Message[] = []; |
| 290 | try { |
| 291 | messages = await safeGetMessages(client, BOT_USERNAME, { limit: FETCH_LIMIT }); |
| 292 | } catch (error: any) { |
| 293 | return { |
| 294 | lastId, |
| 295 | forwarded: false, |
| 296 | reason: "fetch_failed", |
| 297 | error: error?.message || String(error), |
| 298 | }; |
| 299 | } |
no test coverage detected