| 134 | description: string = help_text; |
| 135 | private apiUrl: string = "https://api.open-meteo.com/v1"; |
| 136 | private geocodingUrl: string = "https://geocoding-api.open-meteo.com/v1/search"; |
| 137 | |
| 138 | cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = { |
| 139 | weather: async (msg: Api.Message) => await this.handleWeather(msg) |
| 140 | }; |
| 141 | |
| 142 | private async handleWeather(msg: Api.Message): Promise<void> { |
| 143 | const client = await getGlobalClient(); |
| 144 | |
| 145 | if (!client) { |
| 146 | await msg.edit({ |
| 147 | text: "❌ <b>客户端未初始化</b>", |
| 148 | parseMode: "html" |
| 149 | }); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | try { |
| 154 | // 参数解析(严格按acron.ts模式) |
| 155 | const lines = msg.text?.trim()?.split(/\r?\n/g) || []; |
| 156 | const parts = lines?.[0]?.split(/\s+/) || []; |
| 157 | const [, ...args] = parts; |
| 158 | |
| 159 | // 无参数时显示错误提示 |
| 160 | if (args.length === 0) { |
| 161 | await msg.edit({ |
| 162 | text: `❌ <b>请指定城市名</b>\n\n<b>用法:</b>\n<code>${mainPrefix}weather <城市名></code>\n\n<b>示例:</b>\n<code>${mainPrefix}weather 北京</code>\n<code>${mainPrefix}weather London</code>`, |
| 163 | parseMode: "html" |
| 164 | }); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | // 明确请求帮助时才显示 |
| 169 | if (args[0].toLowerCase() === "help" || args[0].toLowerCase() === "h") { |
| 170 | await msg.edit({ |
| 171 | text: help_text, |
| 172 | parseMode: "html" |
| 173 | }); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | let cityName = args.join(' '); |
| 178 | const originalCityInput = cityName; |
| 179 | |
| 180 | // 渐进式状态反馈 |
| 181 | await msg.edit({ |
| 182 | text: `🔍 <b>正在识别城市...</b>\n<i>${htmlEscape(originalCityInput)}</i>`, |
| 183 | parseMode: "html" |
| 184 | }); |
| 185 | |
| 186 | // 自动检测并转换中文 |
| 187 | cityName = await this.processCityName(cityName); |
| 188 | |
| 189 | // 如果进行了翻译,显示翻译结果 |
| 190 | if (cityName !== originalCityInput) { |
| 191 | await msg.edit({ |
| 192 | text: `🌍 <b>正在搜索...</b>\n<i>${htmlEscape(originalCityInput)} → ${htmlEscape(cityName)}</i>`, |
| 193 | parseMode: "html" |
nothing calls this directly
no test coverage detected