(
message: Api.Message,
text: string,
deleteAfter: number = CONFIG.MESSAGE_AUTO_DELETE,
parseMode: "html" | "md" = "html"
)
| 376 | if (!participant) { |
| 377 | participant = await this.resolveParticipantFromContext(client, message, userId, entity); |
| 378 | } |
| 379 | |
| 380 | // 当前频道/超群:getParticipant(accessHash=0) 可回填实体(即使目标已不在群,有时仍可) |
| 381 | if (!participant && (message as any).isChannel) { |
| 382 | participant = await this.resolveUserViaGetParticipant(client, (message as any).peerId, userId); |
| 383 | if (!entity && participant) { |
| 384 | entity = await this.safeGetEntity(client, userId); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (!participant) { |
| 389 | const cross = await this.resolveUserAcrossManagedGroups(client, userId, (message as any).peerId); |
| 390 | if (cross.participant) { |
| 391 | participant = cross.participant; |
| 392 | if (!entity && cross.entity) entity = cross.entity; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | // 频道/超群:仍无 hash 时用 accessHash=0 试探(预封禁场景) |
| 397 | if (!participant && (message as any).isChannel) { |
| 398 | try { |
| 399 | participant = new Api.InputPeerUser({ |
| 400 | userId: bigInt(userId), |
| 401 | accessHash: bigInt(0), |
| 402 | }); |
| 403 | } catch { |
| 404 | participant = undefined; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return { user: entity, participant }; |
| 409 | } |
| 410 | |
| 411 | /** 频道内用裸 userId + accessHash 0 解析成员 */ |
| 412 | private static async resolveUserViaGetParticipant( |
| 413 | client: TelegramClient, |
| 414 | chat: any, |
| 415 | userId: number, |
| 416 | ): Promise<any | undefined> { |
| 417 | if (!chat || !userId) return undefined; |
| 418 | try { |
| 419 | const res: any = await client.invoke( |
| 420 | new Api.channels.GetParticipant({ |
| 421 | channel: chat, |
| 422 | participant: new Api.InputPeerUser({ |
| 423 | userId: bigInt(userId), |
| 424 | accessHash: bigInt(0), |
| 425 | }), |
| 426 | }) |
no test coverage detected