(
client: TelegramClient,
chatId: any,
userId: number,
participant?: any
)
| 872 | failedGroups: string[]; |
| 873 | failureDetails: BatchGroupFailure[]; |
| 874 | unresolved: boolean; |
| 875 | unresolvedReason?: string; |
| 876 | }; |
| 877 | |
| 878 | class BanManager { |
| 879 | static async resolveParticipant( |
| 880 | client: TelegramClient, |
| 881 | userId: number, |
| 882 | participant?: any |
| 883 | ): Promise<any> { |
| 884 | if (participant) { |
| 885 | return participant; |
| 886 | } |
| 887 | return client.getInputEntity(userId); |
| 888 | } |
| 889 | |
| 890 | private static getErrorReason(error: unknown): string { |
| 891 | const message = error instanceof Error ? error.message : String(error || "UNKNOWN_ERROR"); |
| 892 | // 优先取 Telegram RPC 错误码;勿用 /[A-Z_]{3,}/ 以免命中 "Telegram API error" 里的 API |
| 893 | const rpcCodes = message.match(/\b[A-Z][A-Z0-9_]{4,}\b/g) || []; |
| 894 | const skip = new Set(["TELEGRAM", "ERROR", "UNKNOWN", "UNKNOWN_ERROR"]); |
| 895 | for (const code of rpcCodes) { |
| 896 | if (skip.has(code)) continue; |
| 897 | if (code === "API") continue; |
| 898 | return code; |
| 899 | } |
| 900 | const textField = (error as any)?.text; |
| 901 | if (typeof textField === "string" && /^[A-Z][A-Z0-9_]{3,}$/.test(textField)) { |
| 902 | return textField; |
| 903 | } |
| 904 | return message.slice(0, 80) || "UNKNOWN_ERROR"; |
| 905 | } |
| 906 | |
| 907 | private static getChatKind(chatId: any): ChatKind { |
| 908 | if (chatId?.kind === 'chat' || chatId?.kind === 'channel') { |
no test coverage detected