| 325 | (msg: Api.Message, trigger?: Api.Message) => Promise<void> |
| 326 | > = { |
| 327 | isalive: async (msg: Api.Message, trigger?: Api.Message) => { |
| 328 | const client = await getGlobalClient(); |
| 329 | if (!client) { |
| 330 | await msg.edit({ text: "Client not initialized." }); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | const rawText = (msg.message || msg.text || "").trim(); |
| 335 | const [, ...args] = rawText.split(/\s+/); |
| 336 | const input = args.join(" ").trim(); |
| 337 | |
| 338 | if (!input) { |
| 339 | await msg.edit({ |
| 340 | text: `Missing parameter.\n\n${help_text}`, |
| 341 | parseMode: "html", |
| 342 | }); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | let entity: Api.User | null = null; |
| 347 | |
| 348 | // 立即显示查询状态 |
| 349 | await msg.edit({ |
| 350 | text: "🔍 正在查询中...", |
| 351 | parseMode: "html", |
| 352 | }); |
| 353 | |
| 354 | try { |
| 355 | if (/^-?\d+$/.test(input)) { |
| 356 | const userId = Number(input); |
| 357 | // 先尝试常规方式获取 |
| 358 | try { |
| 359 | entity = (await client.getEntity(userId)) as Api.User; |
| 360 | } catch { |
| 361 | // 常规方式失败,尝试从群组成员中查找 |
| 362 | await msg.edit({ |
| 363 | text: "🔍 正在从群组成员中查找用户...", |
| 364 | parseMode: "html", |
| 365 | }); |
| 366 | entity = await findUserFromGroups(client, userId); |
| 367 | } |
| 368 | } else { |
| 369 | const username = input.startsWith("@") ? input : `@${input}`; |
| 370 | entity = (await client.getEntity(username)) as Api.User; |
| 371 | } |
| 372 | } catch (error: any) { |
| 373 | await msg.edit({ |
| 374 | text: `❌ 无法解析用户: ${htmlEscape( |
| 375 | error?.message || String(error) |
| 376 | )}\n\n<i>提示: 使用 UID 查询需要你与该用户有过交互(私聊、同群等)</i>`, |
| 377 | parseMode: "html", |
| 378 | }); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | if (!entity || entity.className !== "User") { |
| 383 | await msg.edit({ |
| 384 | text: "❌ 查询失败,提供的用户名或ID可能不存在或有误。", |
nothing calls this directly
no test coverage detected