(
client: TelegramClient,
message: Api.Message,
args: string[]
)
| 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 | } |
no test coverage detected