(
msg: Api.Message,
text: string,
force: boolean = false
)
| 399 | force: boolean = false |
| 400 | ): Promise<void> { |
| 401 | const msgId = `${msg.chatId}_${msg.id}`; |
| 402 | const lastText = this.lastEditText.get(msgId); |
| 403 | |
| 404 | // 关键兜底:绝对不给空字符串 |
| 405 | const safeText = text?.trim() || ' '; // 用不可见空格占位 |
| 406 | if (!force && lastText === safeText) return; |
| 407 | |
| 408 | try { |
| 409 | await msg.edit({ text: safeText, parseMode: 'html' }); |
| 410 | this.lastEditText.set(msgId, safeText); |
| 411 | } catch (err: any) { |
| 412 | if (err.message?.includes('MESSAGE_NOT_MODIFIED')) { |
| 413 | this.lastEditText.set(msgId, safeText); |
| 414 | return; |
| 415 | } |
| 416 | throw err; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | private async initDB(): Promise<void> { |
| 421 | try { |
| 422 | const dbPath = path.join(createDirectoryInAssets("prometheus"), "config.json"); |
| 423 | this.db = await JSONFilePreset<PrometheusDB>(dbPath, { users: {} }); |
| 424 | } catch (error) { |
| 425 | console.error(`初始化数据库失败:`, error); |
| 426 | } |
no test coverage detected