2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 11:40:51 +08:00
This commit is contained in:
leiyilu 2022-06-22 12:51:47 +08:00
parent b6c9110141
commit 62b9026473
2 changed files with 129 additions and 108 deletions

View File

@ -1,26 +1,36 @@
import { segment } from "oicq"; import {
segment
} from "oicq";
import fs from "fs"; import fs from "fs";
import lodash from "lodash"; import lodash from "lodash";
import { createRequire } from "module"; import {
import { exec } from "child_process"; createRequire
import { Cfg } from "../components/index.js"; } from "module";
import {
exec
} from "child_process";
import {
Cfg
} from "../components/index.js";
import Common from "../components/Common.js"; import Common from "../components/Common.js";
import {
init
} from "../apps/xiaoyao_image.js"
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
export const rule = { export const rule = {
updateRes: { updateRes: {
hashMark: true, hashMark: true,
reg: "^#图鉴更新$", reg: "^#图鉴更新$",
describe: "【#管理】更新素材", describe: "【#管理】更新素材",
}, },
updateMiaoPlugin: { updateMiaoPlugin: {
hashMark: true, hashMark: true,
reg: "^#图鉴插件(强制)?更新", reg: "^#图鉴插件(强制)?更新",
describe: "【#管理】图鉴更新", describe: "【#管理】图鉴更新",
}, },
}; };
@ -29,107 +39,117 @@ const _path = process.cwd();
const resPath = `${_path}/plugins/xiaoyao-cvs-plugin/resources/`; const resPath = `${_path}/plugins/xiaoyao-cvs-plugin/resources/`;
const plusPath = `${resPath}/xiaoyao-plus/`; const plusPath = `${resPath}/xiaoyao-plus/`;
const checkAuth = async function (e) { const checkAuth = async function(e) {
return await e.checkAuth({ return await e.checkAuth({
auth: "master", auth: "master",
replyMsg: `只有主人才能命令喵喵哦~ replyMsg: `只有主人才能命令喵喵哦~
(*/ω*)` (*/ω*)`
}); });
} }
const getStatus = function (rote, def = true) { const getStatus = function(rote, def = true) {
if (Cfg.get(rote, def)) { if (Cfg.get(rote, def)) {
return `<div class="cfg-status" >已开启</div>`; return `<div class="cfg-status" >已开启</div>`;
} else { } else {
return `<div class="cfg-status status-off">已关闭</div>`; return `<div class="cfg-status status-off">已关闭</div>`;
} }
} }
export async function updateRes(e) { export async function updateRes(e) {
if (!await checkAuth(e)) { if (!await checkAuth(e)) {
return true; return true;
} }
let command = ""; let command = "";
if (fs.existsSync(`${resPath}/xiaoyao-plus/`)) { if (fs.existsSync(`${resPath}/xiaoyao-plus/`)) {
e.reply("开始尝试更新,请耐心等待~"); e.reply("开始尝试更新,请耐心等待~");
command = `git pull`; command = `git pull`;
exec(command, { cwd: `${resPath}/xiaoyao-plus/` }, function (error, stdout, stderr) { exec(command, {
//console.log(stdout); cwd: `${resPath}/xiaoyao-plus/`
if (/Already up to date/.test(stdout)) { }, function(error, stdout, stderr) {
e.reply("目前所有图片都已经是最新了~"); //console.log(stdout);
return true; if (/Already up to date/.test(stdout)) {
} e.reply("目前所有图片都已经是最新了~");
let numRet = /(\d*) files changed,/.exec(stdout); return true;
if (numRet && numRet[1]) { }
e.reply(`报告主人,更新成功,此次更新了${numRet[1]}个图片~`); let numRet = /(\d*) files changed,/.exec(stdout);
return true; if (numRet && numRet[1]) {
} init()
if (error) { e.reply(`报告主人,更新成功,此次更新了${numRet[1]}个图片~`);
e.reply("更新失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。"); return true;
} else { }
e.reply("图片加量包更新成功~"); if (error) {
} e.reply("更新失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。");
}); } else {
} else { init()
//gitee图床 e.reply("图片加量包更新成功~");
command =`git clone https://gitee.com/Ctrlcvs/xiaoyao-plus.git "${resPath}/xiaoyao-plus/"` }
// command = `git clone https://github.com/ctrlcvs/xiaoyao_plus.git "${resPath}/xiaoyao-plus/"`;\n此链接为github图床,如异常请请求多次 });
e.reply("开始尝试安装图鉴加量包,可能会需要一段时间,请耐心等待~"); } else {
exec(command, function (error, stdout, stderr) { //gitee图床
if (error) { command = `git clone https://gitee.com/Ctrlcvs/xiaoyao-plus.git "${resPath}/xiaoyao-plus/"`
e.reply("角色图片加量包安装失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。"); // command = `git clone https://github.com/ctrlcvs/xiaoyao_plus.git "${resPath}/xiaoyao-plus/"`;\n此链接为github图床,如异常请请求多次
} else { e.reply("开始尝试安装图鉴加量包,可能会需要一段时间,请耐心等待~");
e.reply("角色图片加量包安装成功!您后续也可以通过 #图鉴更新 命令来更新图像"); exec(command, function(error, stdout, stderr) {
} if (error) {
}); e.reply("角色图片加量包安装失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。");
} } else {
return true; init()
e.reply("角色图片加量包安装成功!您后续也可以通过 #图鉴更新 命令来更新图像");
}
});
}
return true;
} }
let timer; let timer;
export async function updateMiaoPlugin(e) { export async function updateMiaoPlugin(e) {
if (!await checkAuth(e)) { if (!await checkAuth(e)) {
return true; return true;
} }
let isForce = e.msg.includes("强制"); let isForce = e.msg.includes("强制");
let command = "git pull"; let command = "git pull";
if (isForce) { if (isForce) {
command = "git checkout . && git pull"; command = "git checkout . && git pull";
e.reply("正在执行强制更新操作,请稍等"); e.reply("正在执行强制更新操作,请稍等");
} else { } else {
e.reply("正在执行更新操作,请稍等"); e.reply("正在执行更新操作,请稍等");
} }
exec(command, { cwd: `${_path}/plugins/xiaoyao-cvs-plugin/` }, function (error, stdout, stderr) { exec(command, {
//console.log(stdout); cwd: `${_path}/plugins/xiaoyao-cvs-plugin/`
if (/Already up to date/.test(stdout)) { }, function(error, stdout, stderr) {
e.reply("目前已经是最新版图鉴插件了~"); //console.log(stdout);
return true; if (/Already up to date/.test(stdout)) {
} e.reply("目前已经是最新版图鉴插件了~");
if (error) { return true;
e.reply("图鉴插件更新失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。"); }
return true; if (error) {
} e.reply("图鉴插件更新失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。");
e.reply("图鉴插件更新成功尝试重新启动Yunzai以应用更新..."); return true;
timer && clearTimeout(timer); }
redis.set("xiaoyao:restart-msg", JSON.stringify({ e.reply("图鉴插件更新成功尝试重新启动Yunzai以应用更新...");
msg: "重启成功,新版图鉴插件已经生效", timer && clearTimeout(timer);
qq: e.user_id redis.set("xiaoyao:restart-msg", JSON.stringify({
}), { EX: 30 }); msg: "重启成功,新版图鉴插件已经生效",
timer = setTimeout(function () { qq: e.user_id
let command = "npm run restart"; }), {
exec(command, function (error, stdout, stderr) { EX: 30
if (error) { });
if (/Yunzai not found/.test(error)) { timer = setTimeout(function() {
e.reply("自动重启失败,请手动重启以应用新版图鉴插件。请使用 npm run start 命令启动Yunzai-Bot"); let command = "npm run restart";
} else { exec(command, function(error, stdout, stderr) {
e.reply("重启失败!\nError code: " + error.code + "\n" + error.stack + "\n 请稍后重试。"); if (error) {
} if (/Yunzai not found/.test(error)) {
return true; e.reply("自动重启失败,请手动重启以应用新版图鉴插件。请使用 npm run start 命令启动Yunzai-Bot");
} } else {
}) e.reply("重启失败!\nError code: " + error.code + "\n" + error.stack +
}, 1000); "\n 请稍后重试。");
}
return true;
}
})
}, 1000);
}); });
return true; return true;
} }

View File

@ -48,6 +48,7 @@
"丘丘岩盔王": ["岩丘丘王"], "丘丘岩盔王": ["岩丘丘王"],
"丘丘雷兜王": ["雷丘丘王"], "丘丘雷兜王": ["雷丘丘王"],
"丘丘霜铠王": ["冰丘丘王"], "丘丘霜铠王": ["冰丘丘王"],
"丘丘人":["丘丘人"],
"射手丘丘人": ["弓箭丘丘人"], "射手丘丘人": ["弓箭丘丘人"],
"冰弹丘丘人": ["冰丘丘人"], "冰弹丘丘人": ["冰丘丘人"],
"冰箭丘丘人": ["冰弓丘丘人"], "冰箭丘丘人": ["冰弓丘丘人"],