From 108cc5399ba6f013eb7c798d007eb67e96b968a8 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Tue, 20 Aug 2024 16:51:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E6=8D=B7=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/help.js | 14 +++++++ apps/manage.js | 10 +++++ apps/manage/version.js | 44 ++++++++++++++++++++++ apps/update.js | 1 + lib/render.js | 84 ------------------------------------------ lib/settings.js | 6 ++- 6 files changed, 74 insertions(+), 85 deletions(-) delete mode 100644 lib/render.js diff --git a/apps/help.js b/apps/help.js index 36b8759..5a49311 100644 --- a/apps/help.js +++ b/apps/help.js @@ -331,6 +331,20 @@ export class Help extends ZZZPlugin { needSK: false, commands: ['设置默认设备'], }, + { + title: '开启/关闭自动更新推送', + desc: '开启/关闭自动更新推送,自动更新仅推送给第一个主人', + needCK: false, + needSK: false, + commands: ['开启/关闭自动更新'], + }, + { + title: '设置自动更新时间', + desc: '设置自动更新时间,cron表达式,如0 0/10 * * * ?', + needCK: false, + needSK: false, + commands: ['设置自动更新时间+cron表达式'], + }, ], }, ]; diff --git a/apps/manage.js b/apps/manage.js index ad54a0e..9527064 100644 --- a/apps/manage.js +++ b/apps/manage.js @@ -76,6 +76,14 @@ export class Panel extends ZZZPlugin { reg: `${rulePrefix}设置默认设备`, fnc: 'setDefaultDevice', }, + { + reg: `${rulePrefix}(开启|关闭)自动更新$`, + fnc: 'enableAutoUpdatePush', + }, + { + reg: `${rulePrefix}设置自动更新时间(.+)$`, + fnc: 'setCheckUpdateCron', + }, ], }); @@ -94,6 +102,8 @@ export class Panel extends ZZZPlugin { this.getChangeLog = manage.version.getChangeLog; this.getCommitLog = manage.version.getCommitLog; this.hasUpdate = manage.version.hasUpdate; + this.enableAutoUpdatePush = manage.version.enableAutoUpdatePush; + this.setCheckUpdateCron = manage.version.setCheckUpdateCron; this.setDefaultDevice = manage.device.setDefaultDevice; this.toSetDefaultDevice = manage.device.toSetDefaultDevice; } diff --git a/apps/manage/version.js b/apps/manage/version.js index 41211f6..0c17330 100644 --- a/apps/manage/version.js +++ b/apps/manage/version.js @@ -1,6 +1,7 @@ import version from '../../lib/version.js'; import { ZZZUpdate } from '../../lib/update.js'; import { pluginName } from '../../lib/path.js'; +import settings from '../../lib/settings.js'; export async function getChangeLog() { const versionData = version.changelogs; @@ -49,3 +50,46 @@ export async function hasUpdate() { } return true; } + +/** 开启/关闭自动更新推送 */ +export async function enableAutoUpdatePush() { + if (!this.e.isMaster) { + this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + return false; + } + let enable = true; + if (this.e.msg.includes('关闭')) { + enable = false; + } + settings.setSingleConfig('config', 'update', { autoCheck: enable }); + await this.reply( + `[${pluginName}]自动更新推送${enable ? '已开启' : '已关闭'}`, + false, + { at: true, recallMsg: 100 } + ); +} + +/** 设置自动更新时间 */ +export async function setCheckUpdateCron() { + if (!this.e.isMaster) { + this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + return false; + } + const cron = this.e.msg.split('时间')[1]; + if (!cron) { + await this.reply( + `[${pluginName}]设置自动更新频率失败,无cron表达式`, + false, + { + at: true, + recallMsg: 100, + } + ); + return false; + } + settings.setSingleConfig('config', 'update', { cron }); + await this.reply(`[${pluginName}]自动更新频率已设置为${cron}`, false, { + at: true, + recallMsg: 100, + }); +} diff --git a/apps/update.js b/apps/update.js index 768f885..c8baf02 100644 --- a/apps/update.js +++ b/apps/update.js @@ -73,6 +73,7 @@ export class update extends plugin { for (const master of masters) { if (master.toString().length > 11) continue; await Bot.pickFriend(master).sendMsg(msg); + break; } } } diff --git a/lib/render.js b/lib/render.js deleted file mode 100644 index c1d5bc4..0000000 --- a/lib/render.js +++ /dev/null @@ -1,84 +0,0 @@ -import path from 'path'; -import { pluginName, resourcesPath } from './path.js'; -import setting from './settings.js'; -import version from './version.js'; - -/** - * 渲染函数 - * @param {any} e 消息事件 - * @param {string} renderPath 渲染路径 - * @param {object} renderData 渲染数据 - * @param {object} cfg 配置 - * @returns - */ -const render = (e, renderPath, renderData = {}, cfg = {}) => { - // 判断是否存在e.runtime - if (!e.runtime) { - logger.error('未找到e.runtime,请升级至最新版Yunzai'); - } - - // 获取渲染精度配置 - const scaleCfg = setting.getConfig('config')?.render?.scale || 100; - // 计算配置缩放比例 - const scaleCfgValue = Math.min(2, Math.max(0.5, scaleCfg / 100)) * 2; - // 将函数参数中的缩放比例与配置缩放比例相乘 - const scale = (cfg?.scale || 1) * scaleCfgValue; - // 将缩放比例转换为style属性 - const pct = `style='transform:scale(${scale})'`; - // 获取布局路径 - const layoutPathFull = path.join(resourcesPath, 'common/layout/'); - - // 调用e.runtime.render方法渲染 - return e.runtime.render(pluginName, renderPath, renderData, { - // 合并传入的配置 - ...cfg, - beforeRender({ data }) { - // 资源路径 - const resPath = data.pluResPath; - // 布局路径 - const layoutPath = data.pluResPath + 'common/layout/'; - // 当前的渲染路径 - const renderPathFull = data.pluResPath + renderPath.split('/')[0] + '/'; - // 合并数据 - return { - // 玩家信息 - player: e?.playerCard?.player, - // 玩家头像 - avatar: e?.playerCard?.avatar, - // 传入的数据 - ...data, - // 资源路径 - _res_path: resPath, - // 布局路径 - _layout_path: layoutPath, - // 默认布局路径 - defaultLayout: path.join(layoutPathFull, 'index.html'), - // 系统配置 - sys: { - // 缩放比例 - scale: pct, - // 资源路径 - resourcesPath: resPath, - // 当前渲染的路径 - currentPath: renderPathFull, - /** - * 下面两个模块的作用在于,你可以在你的布局文件中使用这两个模块,就可以显示用户信息和特殊标题,使用方法如下: - * 1. 展示玩家信息:首先你要在查询的时候调用`this.getPlayerInfo()`,这样,玩家数据就会保存在`e.playerCard`中,然后你就可以在布局文件中使用`{{include sys.playerInfo}}`来展示玩家信息。 - * 2. 展示特殊标题:你可以在布局文件中使用`<% include(sys.specialTitle, {en: 'PROPERTY' , cn: '属性' , count: 6 }) %>`来展示特殊标题,其中`count`为可选参数,默认为9。 - */ - // 玩家信息模块 - playerInfo: path.join(layoutPathFull, 'playerinfo.html'), - // 特殊标题模块 - specialTitle: path.join(layoutPathFull, 'specialtitle.html'), - // 版权信息 - copyright: `Created By ${version.name}${version.yunzai} & ${pluginName}${version.version}`, - // 版权信息(简化版) - createdby: `Created By