( message: any, isEdited?: boolean )
| 2265 | replyTo: options?.replyTo, |
| 2266 | }); |
| 2267 | |
| 2268 | console.log( |
| 2269 | `[SHIFT] 转发成功: ${fromChatId} -> ${toChatId}, msg=${messageId}, depth=${depth}` |
| 2270 | ); |
| 2271 | |
| 2272 | // Check for chained forwarding |
| 2273 | const nextRule = await getShiftRule(toChatId); |
| 2274 | if (nextRule && !nextRule.paused && nextRule.target_id) { |
| 2275 | // Wait for message to arrive |
| 2276 | await abortableSleep(200, tryGetCurrentGenerationContext()?.signal); |
| 2277 | |
| 2278 | // Recursive forwarding with depth tracking |
| 2279 | await shiftForwardMessage( |
| 2280 | client, |
| 2281 | toChatId, |
| 2282 | nextRule.target_id, |
| 2283 | messageId, |
| 2284 | depth + 1, |
| 2285 | options |
| 2286 | ); |
| 2287 | } |
| 2288 | } catch (error) { |
| 2289 | console.error( |
| 2290 | `[SHIFT] 转发失败: ${fromChatId} -> ${toChatId}, msg=${messageId}`, |
| 2291 | error |
| 2292 | ); |
| 2293 | throw error; |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | // Message handler for automatic forwarding |
| 2298 | async function handleIncomingMessage( |
| 2299 | message: any, |
| 2300 | isEdited?: boolean |
| 2301 | ): Promise<void> { |
| 2302 | try { |
| 2303 | if (!message || !message.chat) { |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| 2307 | const sourceId = getChatIdFromMessage(message, isEdited); |
| 2308 | if (!sourceId) { |
| 2309 | return; |
| 2310 | } |
| 2311 | |
| 2312 | const rule = await getShiftRule(sourceId); |
| 2313 | if (!rule || rule.paused) { |
| 2314 | return; |
| 2315 | } |
| 2316 | |
| 2317 | const targetId = rule.target_id; |
| 2318 | if (!targetId) { |
| 2319 | return; |
| 2320 | } |
| 2321 | |
| 2322 | // Check content protection |
| 2323 | if (message.chat.noforwards) { |
| 2324 | console.log( |
no test coverage detected