(
client: TelegramClient,
message: Api.Message,
target: string
)
| 197 | } |
| 198 | |
| 199 | return { user: null, uid: null, source: "unknown", resolutionError: "NO_TARGET", chatType: this.getChatType(message) }; |
| 200 | } |
| 201 | |
| 202 | private static async resolveFromString( |
| 203 | client: TelegramClient, |
| 204 | message: Api.Message, |
| 205 | target: string |
| 206 | ): Promise<ResolvedTarget> { |
| 207 | try { |
| 208 | // @username 格式 |
| 209 | if (target.startsWith("@")) { |
| 210 | const entity = await this.safeGetEntity(client, target); |
| 211 | const participant = entity ? await this.safeGetInputEntity(client, entity) : undefined; |
| 212 | const uid = entity?.id ? Number(entity.id) : null; |
| 213 | const fallbackParticipant = uid |
| 214 | ? participant || await this.resolveParticipantFromContext(client, message, uid, entity) |
| 215 | : undefined; |
| 216 | return { |
| 217 | user: entity, |
| 218 | uid, |
| 219 | participant: fallbackParticipant, |
| 220 | source: "username", |
| 221 | resolutionError: fallbackParticipant || uid === null ? undefined : "TARGET_ENTITY_UNRESOLVABLE", |
| 222 | chatType: this.getChatType(message), |
| 223 | }; |
| 224 | } |
| 225 | |
| 226 | // 纯数字 ID(不要求目标在当前聊天) |
| 227 | if (/^-?\d+$/.test(target)) { |
| 228 | const userId = parseInt(target, 10); |
| 229 | const resolved = await this.resolveNumericUser(client, message, userId); |
| 230 | return { |
| 231 | user: resolved.user, |
| 232 | uid: userId, |
| 233 | participant: resolved.participant, |
| 234 | source: "numeric", |
| 235 | resolutionError: resolved.participant ? undefined : "TARGET_ENTITY_UNRESOLVABLE", |
| 236 | chatType: this.getChatType(message), |
| 237 | }; |
| 238 | } |
| 239 | } catch (error) { |
| 240 | console.error(`[UserResolver] 解析失败: ${error}`); |
| 241 | } |
| 242 | |
| 243 | return { user: null, uid: null, source: "unknown", resolutionError: "INVALID_TARGET", chatType: this.getChatType(message) }; |
| 244 | } |
| 245 | |
| 246 | private static async getReplySender(reply: Api.Message): Promise<any> { |
| 247 | try { |
| 248 | return await (reply as any).getSender?.(); |
no test coverage detected