From 90776f701a557c98421d7ef858a6b2d9596cbc22 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Sat, 7 Jan 2023 18:43:55 +0800 Subject: [PATCH] =?UTF-8?q?updte=20=E4=B8=8D=E5=BC=BA=E5=88=B6=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E4=BE=9D=E8=B5=96=EF=BC=8C=E4=B8=8D=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=B0=86=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8=E6=A4=B0=E5=A5=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/state.js | 4 +++- index.js | 16 +++++++++++++++- model/CPU.js | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/state.js b/apps/state.js index 6751658..d7799d0 100644 --- a/apps/state.js +++ b/apps/state.js @@ -3,7 +3,8 @@ import os from 'os'; import { render, Config } from '../components/index.js' import { CPU, Cfg, common } from '../model/index.js' import moment from 'moment'; -import si from 'systeminformation' +// import si from 'systeminformation' +let si = await redis.get('yenai:node_modules') ? await import("systeminformation") : false import lodash from 'lodash' let interval = false; export class example extends plugin { @@ -26,6 +27,7 @@ export class example extends plugin { if (!/椰奶/.test(e.msg) && !Config.Notice.state) { return false; } + if (!si) return e.reply("❎ 没有检测到systeminformation依赖,请运行:'pnpm add systeminformation -w'进行安装") //防止多次触发 if (interval) { return } else interval = true; //系统 diff --git a/index.js b/index.js index f4bc94b..3c153f9 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ import fs from 'node:fs' import Ver from './components/Version.js' import chalk from 'chalk' -import si from 'systeminformation' const files = fs.readdirSync('./plugins/yenai-plugin/apps').filter(file => file.endsWith('.js')) @@ -11,6 +10,21 @@ logger.info(chalk.rgb(253, 235, 255)('----ヾ( ̄▽ ̄)Bye~Bye~----')) logger.info(chalk.rgb(255, 207, 247)(`椰奶插件${Ver.ver}初始化~`)) logger.info(chalk.rgb(253, 235, 255)('-------------------------')) +try { + await import('systeminformation') + await redis.set('yenai:node_modules', '1') +} catch (error) { + if (error.stack.includes('Cannot find package')) { + logger.warn('--------椰奶依赖缺失--------') + logger.warn("yenai-plugin 没有检测到systeminformation依赖将无法使用椰奶状态") + logger.warn(`如需使用请运行:${logger.red('pnpm add systeminformation -w')}`) + logger.warn('---------------------') + } else { + logger.error(`椰奶载入依赖错误:${logger.red('systeminformation')}`) + logger.error(decodeURI(error.stack)) + } + await redis.del('yenai:node_modules') +} files.forEach((file) => { ret.push(import(`./apps/${file}`)) diff --git a/model/CPU.js b/model/CPU.js index 0c84086..4aa97ff 100644 --- a/model/CPU.js +++ b/model/CPU.js @@ -1,9 +1,10 @@ import os from 'os'; -import si from 'systeminformation' +// import si from 'systeminformation' import lodash from 'lodash' import fs from 'fs' import { common } from './index.js' import { Config } from '../components/index.js' +let si = await redis.get('yenai:node_modules') ? await import("systeminformation") : false class OSUtils { constructor() { this.cpuUsageMSDefault = 1000; // CPU 利用率默认时间段 @@ -14,6 +15,7 @@ class OSUtils { } async init() { + if (!si) return //初始化GPU获取 if ((await si.graphics()).controllers.find(item => item.memoryUsed && item.memoryFree && item.utilizationGpu)) { this.isGPU = true