(msg: Api.Message)
| 567 | |
| 568 | // 主处理函数 |
| 569 | async function handleKomariRequest(msg: Api.Message): Promise<void> { |
| 570 | const [, ...args] = msg.message.slice(1).split(" "); |
| 571 | |
| 572 | try { |
| 573 | // 检查是否是配置命令 |
| 574 | if (args.length === 2 && args[0].startsWith("_set_")) { |
| 575 | const configKey = args[0]; |
| 576 | const configValue = args[1].trim(); |
| 577 | |
| 578 | let actualKey: string; |
| 579 | let displayName: string; |
| 580 | |
| 581 | if (configKey !== "_set_url") { |
| 582 | await msg.edit({ text: "❌ 未知的配置项" }); |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | displayName = "Komari URL"; |
| 587 | ConfigManager.set(CONFIG_KEYS.KOMARI_URL, configValue); |
| 588 | const displayValue = configValue; |
| 589 | |
| 590 | await msg.edit({ |
| 591 | text: `✅ 已设置 ${displayName}: \`${displayValue}\``, |
| 592 | parseMode: "markdown", |
| 593 | }); |
| 594 | |
| 595 | setTimeout(() => { |
| 596 | msg.delete().catch(() => {}); |
| 597 | }, 5000); |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | // 获取配置 |
| 602 | const baseUrl = ConfigManager.get(CONFIG_KEYS.KOMARI_URL); |
| 603 | if (!baseUrl) { |
| 604 | await msg.edit({ |
| 605 | text: "❌ 请先设置 Komari URL\n使用命令: `komari _set_url <URL>`", |
| 606 | parseMode: "markdown", |
| 607 | }); |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | // 处理不同的子命令 |
| 612 | if (args.length === 0 || args[0] === "status") { |
| 613 | await msg.edit({ text: "🔄 获取服务器信息中..." }); |
| 614 | const result = await getServerInfo(baseUrl); |
| 615 | await msg.edit({ |
| 616 | text: result, |
| 617 | parseMode: "markdown", |
| 618 | }); |
| 619 | } else if (args[0] === "total") { |
| 620 | await msg.edit({ text: "🔄 获取节点总览中..." }); |
| 621 | const result = await getNodesOverview(baseUrl); |
| 622 | await msg.edit({ |
| 623 | text: result, |
| 624 | parseMode: "markdown", |
| 625 | }); |
| 626 | } else if (args[0] === "show" && args.length >= 2) { |
nothing calls this directly
no test coverage detected