重启核心功能

This commit is contained in:
Jerry 2025-05-04 10:30:20 +08:00
parent fd360ed29c
commit ba997f8a58
3 changed files with 55 additions and 1 deletions

34
apps/coreRestart.js Normal file
View File

@ -0,0 +1,34 @@
import systemControl from '../lib/core/systemControl.js';
import tools from '../components/tool.js';
export default class CoreRestart extends plugin {
constructor() {
super({
name: 'crystelf重启核心',
dsc: '实现核心的重启功能',
rule: [
{
reg: '^#core重启$',
fnc: 'restart',
permission: 'master',
},
],
});
}
async restart(e) {
const returnData = await systemControl.systemRestart();
if (returnData?.data?.success) {
e.reply(`操作成功:${returnData?.data?.data}..`);
} else {
e.reply(`操作失败:${returnData?.data?.data}..`);
}
await tools.sleep(8000);
const restartTime = await systemControl.getRestartTime();
if (restartTime) {
e.reply(`晶灵核心重启成功!耗时${restartTime?.data?.data}秒..`);
} else {
e.reply(`核心重启花的时间有点久了呢..${restartTime?.data?.data}`);
}
}
}

View File

@ -14,7 +14,7 @@ export default class ReportBots extends plugin {
],
task: {
name: 'crystelf定时同步',
corn: '0 */30 * * * *',
corn: '*/30 * * * *',
fnc: 'autoReport',
},
});

20
lib/core/systemControl.js Normal file
View File

@ -0,0 +1,20 @@
import configControl from '../config/configControl.js';
import axios from 'axios';
let systemControl = {
async systemRestart() {
const token = configControl.get('coreConfig')?.token;
const coreUrl = configControl.get('coreConfig')?.coreUrl;
const postUrl = coreUrl + '/api/system/restart';
//logger.info(returnData);
return await axios.post(postUrl, { token: token });
},
async getRestartTime() {
const token = configControl.get('coreConfig')?.token;
const coreUrl = configControl.get('coreConfig')?.coreUrl;
const postUrl = coreUrl + '/api/system/getRestartTime';
return axios.post(postUrl, { token: token });
},
};
export default systemControl;