MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / safeEditMessage

Method safeEditMessage

save/save.ts:401–423  ·  view source on GitHub ↗
(
    msg: Api.Message,
    text: string,
    force: boolean = false
  )

Source from the content-addressed store, hash-verified

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 }

Callers 8

downloadMediaMethod · 0.95
sendSingleMediaMethod · 0.95
processMessageMethod · 0.95
processMessageToLocalMethod · 0.95
processMessageRangeMethod · 0.95
handleCommandMethod · 0.95

Calls 3

getMethod · 0.45
editMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected