feat: 自动检查更新

This commit is contained in:
bietiaop 2024-08-20 16:10:17 +08:00
parent 94ae2b5183
commit 0ea8779c58
3 changed files with 81 additions and 15 deletions

View file

@ -3,6 +3,7 @@ import { rulePrefix } from '../lib/common.js';
import { pluginName } from '../lib/path.js';
import settings from '../lib/settings.js';
import { ZZZUpdate } from '../lib/update.js';
import config from '../../../lib/config/config.js';
export class update extends plugin {
constructor() {
@ -18,6 +19,15 @@ export class update extends plugin {
},
],
});
const updateConfig = _.get(settings.getConfig('config'), 'update', {});
const cron = _.get(updateConfig, 'cron', '0 0/10 * * * ?');
this.task = {
name: 'ZZZ-Plugin自动检测更新',
cron: cron,
fnc: () => {
this.checkUpdateTask();
},
};
}
async update(e = this.e) {
@ -27,4 +37,43 @@ export class update extends plugin {
up.e = e;
return up.update();
}
async checkUpdateTask() {
const updateConfig = _.get(settings.getConfig('config'), 'update', {});
const enable = _.get(updateConfig, 'autoCheck', true);
if (!enable) return;
if (!ZZZUpdate) return false;
const up = new ZZZUpdate();
const result = await up.hasUpdate();
if (result.hasUpdate) {
const botInfo = { nickname: 'ZZZ-Plugin更新', user_id: Bot.uin };
const msgs = [
{
message: [`[${pluginName}]有${result.logs.length || 1}个更新`],
...botInfo,
},
];
for (const log of result.logs) {
msgs.push({
message: [`[${log.commit}|${log.date}]${log.msg}`],
...botInfo,
});
}
const msg = Bot.makeForwardMsg(msgs);
try {
ForMsg.data = ForMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(
/___+/,
'<title color="#777777" size="26">ZZZ-Plugin更新</title>'
);
} catch (err) {}
const masters = config.masterQQ;
for (const master of masters) {
if (master.toString().length > 11) continue;
await Bot.pickFriend(master).sendMsg(msg);
}
}
}
}

View file

@ -2,6 +2,8 @@ render:
scale: 100 # 渲染精度
query:
others: true # 允许查询他人信息
update:
autoCheck: true # 自动检查更新
cron: 0 0/10 * * * ? # 更新检查时间
# 自定义绑定设备下载url
url: https://ghproxy.mihomo.me/https://raw.githubusercontent.com/forchannot/get_device_info/main/app/build/outputs/apk/debug/app-debug.apk

View file

@ -48,10 +48,10 @@ export function supportGuoba() {
field: 'config.url',
label: '绑定设备下载url',
bottomHelpMessage: '设置自定义的绑定绑定设备下载url',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入绑定设备apk下载url',
}
},
},
{
field: 'config.query.others',
@ -59,6 +59,21 @@ export function supportGuoba() {
bottomHelpMessage: '是否允许查询他人信息',
component: 'Switch',
},
{
field: 'config.update.autoCheck',
label: '自动检查更新',
bottomHelpMessage: '是否开启自动检查更新(仅检查,不更新)',
component: 'Switch',
},
{
field: 'config.update.cron',
label: '自动检查更新时间',
bottomHelpMessage: '设置自动检查更新的时间cron表达式',
component: 'Input',
componentProps: {
placeholder: '请输入cron表达式',
},
},
{
component: 'Divider',
label: '抽卡分析设置',
@ -203,55 +218,55 @@ export function supportGuoba() {
field: 'device.productName',
label: 'productName(deviceProduct)',
bottomHelpMessage: '设置默认设备productName字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入productName',
}
},
},
{
field: 'device.productType',
label: 'productType(deviceName)',
bottomHelpMessage: '设置默认设备productType字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入productType',
}
},
},
{
field: 'device.modelName',
label: 'modelName(deviceModel)',
bottomHelpMessage: '设置默认设备modelName字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入modelName',
}
},
},
{
field: 'device.oaid',
label: 'oaid',
bottomHelpMessage: '设置默认设备oaid字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入oaid',
}
},
},
{
field: 'device.deviceInfo',
label: 'deviceInfo(deviceFingerprint)',
bottomHelpMessage: '设置默认设备deviceInfo字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入deviceInfo',
}
},
},
{
field: 'device.board',
label: 'board(deviceBoard)',
bottomHelpMessage: '设置默认设备board字段',
component:'Input',
component: 'Input',
componentProps: {
placeholder: '请输入board',
}
},
},
{
component: 'Divider',