( client: TelegramClient, fromChatId: number, toChatId: number, messageId: number, depth: number = 0, options?: any )
| 2214 | } |
| 2215 | |
| 2216 | // Get chat ID from message |
| 2217 | function getChatIdFromMessage(message: any, isEdited?: boolean): number | null { |
| 2218 | if ( |
| 2219 | isEdited && |
| 2220 | message.peerId?.channelId && |
| 2221 | message.fwdFrom?.channelPost && |
| 2222 | message.fwdFrom?.fromId?.channelId |
| 2223 | ) { |
| 2224 | message.id = message.fwdFrom?.channelPost; |
| 2225 | const channelId = |
| 2226 | message.fwdFrom.fromId.channelId.value || |
| 2227 | message.fwdFrom.fromId.channelId; |
| 2228 | return ensureChannelId(channelId); |
| 2229 | } |
| 2230 | if (message.chatId) { |
| 2231 | return Number(message.chatId); |
| 2232 | } |
| 2233 | if (message.peerId) { |
| 2234 | if (message.peerId.channelId) { |
| 2235 | return ensureChannelId(message.peerId.channelId); |
| 2236 | } else if (message.peerId.chatId) { |
| 2237 | return -Number(message.peerId.chatId); |
| 2238 | } else if (message.peerId.userId) { |
| 2239 | return Number(message.peerId.userId); |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | return null; |
| 2244 | } |
| 2245 | |
| 2246 | // Forward message using universal access hash handler |
| 2247 | async function shiftForwardMessage( |
| 2248 | client: TelegramClient, |
| 2249 | fromChatId: number, |
| 2250 | toChatId: number, |
| 2251 | messageId: number, |
| 2252 | depth: number = 0, |
| 2253 | options?: any |
| 2254 | ): Promise<void> { |
| 2255 | if (depth > 5) { |
| 2256 | console.log(`[SHIFT] 转发深度超限: ${depth}`); |
| 2257 | return; |
| 2258 | } |
| 2259 | |
| 2260 | try { |
| 2261 | // 使用通用的安全转发函数 |
| 2262 | await safeForwardMessage(client, fromChatId, toChatId, messageId, { |
| 2263 | maxRetries: 3, |
| 2264 | silent: options?.silent, |
| 2265 | replyTo: options?.replyTo, |
| 2266 | }); |
| 2267 |
no test coverage detected