MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / resolveFromString

Method resolveFromString

aban/aban.ts:199–245  ·  view source on GitHub ↗
(
    client: TelegramClient,
    message: Api.Message,
    target: string
  )

Source from the content-addressed store, hash-verified

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?.();

Callers 1

resolveTargetMethod · 0.95

Calls 5

safeGetEntityMethod · 0.95
safeGetInputEntityMethod · 0.95
getChatTypeMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected