(
client: TelegramClient,
chatId: any
)
| 568 | }, deleteAfter * 1000, { label: 'aban:smartEdit-delayed-delete' }); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | return message; |
| 573 | } catch (error: any) { |
| 574 | const errMsg = error.message || String(error); |
| 575 | if (errMsg.includes('MESSAGE_ID_INVALID')) { |
| 576 | // Expected when the target message was already deleted - not actionable |
| 577 | } else { |
| 578 | console.error(`编辑消息失败: ${errMsg}`); |
| 579 | } |
| 580 | return message; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | // ==================== 权限管理器 ==================== |
| 586 | type ManagedGroup = { |
| 587 | id: number; |
| 588 | title: string; |
| 589 | kind: ChatKind; |
| 590 | // bigint 序列化为字符串。channel 必填;basic group 不需要 |
| 591 | accessHash?: string; |
| 592 | }; |
| 593 | |
| 594 | /** |
| 595 | * 把 ManagedGroup 转成可以直接喂给 Api.channels.* 的 channel 参数。 |
| 596 | * - channel 有 accessHash → 构造完整 InputChannel,直接走,不触发 GetChannels 兜底 |
| 597 | * - channel 无 accessHash(旧缓存或未填)→ 通过 getInputEntity 让 teleproto 自行解析 |
| 598 | * - basic group → 返回裸 id(调用方应通过 kind 分流到 messages.* 路径) |
| 599 | */ |
| 600 | async function resolveChannelInput( |
| 601 | client: TelegramClient, |
| 602 | group: ManagedGroup |
| 603 | ): Promise<any> { |
| 604 | if (group.kind !== 'channel') { |
| 605 | return group.id; |
| 606 | } |
no test coverage detected