From 857be5ee49fb2b0a281bd2e9bf86963c4248c1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 22 Jan 2026 14:22:04 +0800 Subject: [PATCH] Add uptime display to version info message Introduced a function to format and display the application's uptime in the version information message. This provides users with additional context about how long the application has been running. --- packages/napcat-plugin-builtin/index.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/napcat-plugin-builtin/index.ts b/packages/napcat-plugin-builtin/index.ts index 916c6219..6b1dc263 100644 --- a/packages/napcat-plugin-builtin/index.ts +++ b/packages/napcat-plugin-builtin/index.ts @@ -4,6 +4,7 @@ import type { PluginModule } from 'napcat-onebot/network/plugin'; import type { OB11Message, OB11PostSendMsg } from 'napcat-onebot/types/message'; let actions: ActionMap | undefined = undefined; +let startTime: number = Date.now(); /** * 插件初始化 @@ -54,11 +55,32 @@ async function getVersionInfo (adapter: string, config: any) { } } +/** + * 格式化运行时间 + */ +function formatUptime (ms: number): string { + const seconds = Math.floor(ms / 1000); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + + if (days > 0) { + return `${days}天 ${hours % 24}小时 ${minutes % 60}分钟`; + } else if (hours > 0) { + return `${hours}小时 ${minutes % 60}分钟`; + } else if (minutes > 0) { + return `${minutes}分钟 ${seconds % 60}秒`; + } else { + return `${seconds}秒`; + } +} + /** * 格式化版本信息消息 */ function formatVersionMessage (info: { appName: string; appVersion: string; protocolVersion: string; }) { - return `NapCat 信息\n版本: ${info.appVersion}\n平台: ${process.platform}${process.arch === 'x64' ? ' (64-bit)' : ''}`; + const uptime = Date.now() - startTime; + return `NapCat 信息\n版本: ${info.appVersion}\n平台: ${process.platform}${process.arch === 'x64' ? ' (64-bit)' : ''}\n运行时间: ${formatUptime(uptime)}`; } /**