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

Method resolveTarget

aban/aban.ts:165–197  ·  view source on GitHub ↗
(
    client: TelegramClient,
    message: Api.Message,
    args: string[]
  )

Source from the content-addressed store, hash-verified

163 return a === "true" || a === "false" || a === "confirm";
164 }
165
166 static async resolveTarget(
167 client: TelegramClient,
168 message: Api.Message,
169 args: string[]
170 ): Promise<ResolvedTarget> {
171 // true/false 是确认位,不是目标;`.sb true` 应回落到回复消息
172 const targetArgs = args.filter((a) => !this.isMetaFlag(a));
173
174 // 从参数解析
175 if (targetArgs.length > 0) {
176 return await this.resolveFromString(client, message, targetArgs[0]);
177 }
178
179 // 从回复消息解析
180 const reply = await safeGetReplyMessage(message);
181 if (reply?.senderId) {
182 const uid = Number(reply.senderId);
183 const sender = await this.getReplySender(reply);
184 const participant = sender instanceof Api.User
185 ? await this.safeGetInputEntity(client, sender)
186 : await this.safeGetInputEntity(client, uid);
187 const fallbackParticipant = participant || await this.resolveParticipantFromContext(client, message, uid, sender);
188
189 return {
190 user: sender || reply.sender,
191 uid,
192 participant: fallbackParticipant,
193 source: "reply",
194 resolutionError: fallbackParticipant ? undefined : "TARGET_ENTITY_UNRESOLVABLE",
195 chatType: this.getChatType(message),
196 };
197 }
198
199 return { user: null, uid: null, source: "unknown", resolutionError: "NO_TARGET", chatType: this.getChatType(message) };
200 }

Callers 3

handleBasicCommandMethod · 0.45
handleSuperBanMethod · 0.45
handleSuperUnbanMethod · 0.45

Calls 5

resolveFromStringMethod · 0.95
getReplySenderMethod · 0.95
safeGetInputEntityMethod · 0.95
getChatTypeMethod · 0.95

Tested by

no test coverage detected