(msg: Api.Message)
| 331 | const storedToken = await getStoredToken(); |
| 332 | await msg.edit({ |
| 333 | text: `🔐 当前本地 Token:${maskToken(storedToken)}\n• 设置方式:<code>${mainPrefix}cximg token 你的codex access token(通常在 .codex/auth.json)</code>`, |
| 334 | parseMode: "html", |
| 335 | }); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | await setStoredToken(tokenValue); |
| 340 | await msg.edit({ text: "✅ 已保存 Codex Access Token" }); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | const prompt = argsText; |
| 345 | if (!prompt) { |
| 346 | await msg.edit({ |
| 347 | text: `❌ 请输入提示词,例如:<code>${mainPrefix}cximg 一只戴墨镜的柴犬坐在跑车里</code>\n• 设置 Token:<code>${mainPrefix}cximg token 你的codex access token(通常在 .codex/auth.json)</code>`, |
| 348 | parseMode: "html", |
| 349 | }); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | let referenceImage: { buffer: Buffer; mimeType: string } | null = null; |
| 354 | try { |
| 355 | referenceImage = await downloadReplyImage(msg); |
| 356 | } catch (error: any) { |
| 357 | await msg.edit({ |
| 358 | text: `❌ 参考图下载失败:${htmlEscape(error.message || String(error))}`, |
| 359 | parseMode: "html", |
| 360 | }); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | const initialStatus = referenceImage |
| 365 | ? "🖼️ 已检测到参考图,正在生成图片..." |
| 366 | : "🎨 正在根据提示词生成图片..."; |
| 367 | await msg.edit({ |
| 368 | text: initialStatus, |
| 369 | }); |
| 370 | |
| 371 | const startedAt = Date.now(); |
| 372 | const deadlineAt = startedAt + CODEX_MAX_WAIT_MS; |
| 373 | let lastStatusUpdateAt = 0; |
| 374 | let currentPhaseText = initialStatus; |
| 375 | let heartbeatStopped = false; |
| 376 | const updateProgressStatus = async (phaseText: string): Promise<void> => { |
| 377 | currentPhaseText = phaseText; |
| 378 | const now = Date.now(); |
| 379 | if (now - lastStatusUpdateAt < 1500) return; |
| 380 | lastStatusUpdateAt = now; |
| 381 | const elapsed = formatDuration(now - startedAt); |
| 382 | try { |
| 383 | await msg.edit({ |
| 384 | text: `${phaseText}\n⏱️ 已耗时:${elapsed}`, |
| 385 | }); |
| 386 | } catch {} |
| 387 | }; |
| 388 | |
| 389 | const heartbeat = (async () => { |
| 390 | while (!heartbeatStopped) { |
nothing calls this directly
no test coverage detected