mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
feat: 自动检查更新
This commit is contained in:
parent
94ae2b5183
commit
0ea8779c58
3 changed files with 81 additions and 15 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue