mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
📃 docs: 更新README
This commit is contained in:
parent
1df3e68893
commit
7575b24ef3
161
apps/update.js
161
apps/update.js
@ -2,10 +2,10 @@
|
|||||||
import Version from "../model/version.js";
|
import Version from "../model/version.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
||||||
|
import lodash from 'lodash'
|
||||||
|
|
||||||
import { exec, execSync } from "node:child_process";
|
import {exec, execSync} from "node:child_process";
|
||||||
|
|
||||||
const _path = process.cwd();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理插件更新
|
* 处理插件更新
|
||||||
@ -24,7 +24,7 @@ export class update extends plugin {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
/** 命令正则匹配 */
|
/** 命令正则匹配 */
|
||||||
reg: "^#(R更新|R强制更新)$",
|
reg: "^#*R(插件)?更新$",
|
||||||
/** 执行方法 */
|
/** 执行方法 */
|
||||||
fnc: "rconsoleUpdate",
|
fnc: "rconsoleUpdate",
|
||||||
},
|
},
|
||||||
@ -44,114 +44,85 @@ export class update extends plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 更新主程序
|
||||||
* @param e oicq传递的事件参数e
|
* @param e
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
async rconsoleUpdate(e) {
|
async rconsoleUpdate(e) {
|
||||||
if (!this.e.isMaster) {
|
if (!this.e.isMaster) {
|
||||||
await this.e.reply("您无权操作");
|
await this.e.reply("您无权操作");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const pluginName = 'rconsole-plugin'
|
||||||
|
|
||||||
let isForce = !!this.e.msg.includes("强制");
|
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
||||||
|
this.oldCommitId = await this.getcommitId(pluginName)
|
||||||
|
await e.reply("正在执行更新操作,请稍等");
|
||||||
|
|
||||||
let command = "git pull";
|
let ret = await this.execSync(command)
|
||||||
|
if (ret.error) {
|
||||||
if (isForce) {
|
e.reply(`更新失败!重试一下!`)
|
||||||
command = "git checkout . && git pull";
|
await this.gitErr(ret.error, ret.stdout)
|
||||||
await this.e.reply("正在执行强制更新操作,请稍等");
|
return false
|
||||||
|
}
|
||||||
|
const time = await this.getTime(pluginName)
|
||||||
|
if (/Already up|已经是最新/g.test(ret.stdout)) {
|
||||||
|
e.reply(`R插件已经是最新: ${this.versionData[0].version}`)
|
||||||
} else {
|
} else {
|
||||||
await this.e.reply("正在执行更新操作,请稍等");
|
this.isUp = true
|
||||||
|
e.reply(`R插件更新成功,最后更新时间:${time}`)
|
||||||
|
e.reply(await this.getLog(pluginName))
|
||||||
}
|
}
|
||||||
const th = this;
|
return true
|
||||||
exec(
|
|
||||||
command,
|
|
||||||
{ cwd: `${_path}/plugins/rconsole-plugin/` },
|
|
||||||
async function (error, stdout, stderr) {
|
|
||||||
if (error) {
|
|
||||||
let isChanges = error
|
|
||||||
.toString()
|
|
||||||
.includes(
|
|
||||||
"Your local changes to the following files would be overwritten by merge"
|
|
||||||
);
|
|
||||||
|
|
||||||
let isNetwork = error.toString().includes("fatal: unable to access");
|
|
||||||
|
|
||||||
if (isChanges) {
|
|
||||||
//git stash && git pull && git stash pop stash@{0}
|
|
||||||
//需要设置email和username,暂不做处理
|
|
||||||
await me.e.reply(
|
|
||||||
"失败!\nError code: " +
|
|
||||||
error.code +
|
|
||||||
"\n" +
|
|
||||||
error.stack +
|
|
||||||
"\n\n本地代码与远程代码存在冲突,上面报错信息中包含冲突文件名称及路径,请尝试处理冲突\n如果不想保存本地修改请使用【#强制更新】\n(注意:强制更新命令会忽略所有本地对R插件本身文件的修改,本地修改均不会保存,请注意备份)"
|
|
||||||
);
|
|
||||||
} else if (isNetwork) {
|
|
||||||
await e.reply(
|
|
||||||
"失败!\nError code: " +
|
|
||||||
error.code +
|
|
||||||
"\n" +
|
|
||||||
error.stack +
|
|
||||||
"\n\n可能是网络问题,请关闭加速器之类的网络工具,或请过一会尝试。"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await e.reply(
|
|
||||||
"失败!\nError code: " +
|
|
||||||
error.code +
|
|
||||||
"\n" +
|
|
||||||
error.stack +
|
|
||||||
"\n\n出错了。请尝试处理错误"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (/Already up to date/.test(stdout)) {
|
|
||||||
e.reply("目前已经是最新了~");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
await th.restartApp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async restartApp() {
|
async getcommitId(pluginName) {
|
||||||
if (!this.e.isMaster) {
|
// let cm = 'git rev-parse --short HEAD'
|
||||||
await this.e.reply("您无权操作");
|
const command = `git -C ./plugins/${pluginName}/ rev-parse --short HEAD`
|
||||||
return true;
|
let commitId = execSync(command, {encoding: 'utf-8'})
|
||||||
}
|
commitId = lodash.trim(commitId)
|
||||||
await this.e.reply("开始执行重启,请稍等...");
|
return commitId
|
||||||
Bot.logger.mark("开始执行重启,请稍等...");
|
}
|
||||||
|
|
||||||
let data = JSON.stringify({
|
async execSync(cmd) {
|
||||||
isGroup: !!this.e.isGroup,
|
return new Promise((resolve, reject) => {
|
||||||
id: this.e.isGroup ? this.e.group_id : this.e.user_id,
|
exec(cmd, {windowsHide: true}, (error, stdout, stderr) => {
|
||||||
});
|
resolve({error, stdout, stderr})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTime(pluginName) {
|
||||||
|
const cm = `cd ./plugins/${pluginName}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`
|
||||||
|
let time = ''
|
||||||
try {
|
try {
|
||||||
await redis.set("Yunzai:rconsole:restart", data, { EX: 120 });
|
time = execSync(cm, {encoding: 'utf-8'})
|
||||||
|
time = lodash.trim(time)
|
||||||
let cm = `npm run start`;
|
|
||||||
if (process.argv[1].includes("pm2")) {
|
|
||||||
cm = `npm run restart`;
|
|
||||||
}
|
|
||||||
|
|
||||||
exec(cm, async (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
await redis.del(`Yunzai:rconsole:restart`);
|
|
||||||
await this.e.reply(`操作失败!\n${error.stack}`);
|
|
||||||
Bot.logger.error(`重启失败\n${error.stack}`);
|
|
||||||
} else if (stdout) {
|
|
||||||
Bot.logger.mark("重启成功,运行已转为后台,查看日志请用命令:npm run log");
|
|
||||||
Bot.logger.mark("停止后台运行命令:npm stop");
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
redis.del(`Yunzai:rconsole:restart`);
|
time = '获取时间失败'
|
||||||
await this.e.reply(`操作失败!\n${error.stack}`);
|
|
||||||
}
|
}
|
||||||
|
return time
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLog (pluginName) {
|
||||||
|
let cm = 'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"'
|
||||||
|
if (pluginName) { cm = `cd ./plugins/${pluginName}/ && ${cm}` }
|
||||||
|
let logAll
|
||||||
|
try { logAll = execSync(cm, { encoding: 'utf-8' }) } catch (error) { this.reply(error.toString(), true) }
|
||||||
|
if (!logAll) return false
|
||||||
|
logAll = logAll.split('\n')
|
||||||
|
let log = []
|
||||||
|
for (let str of logAll) {
|
||||||
|
str = str.split('||')
|
||||||
|
if (str[0] === this.oldCommitId) break
|
||||||
|
if (str[1].includes('Merge branch')) continue
|
||||||
|
log.push(str[1])
|
||||||
|
}
|
||||||
|
let line = log.length
|
||||||
|
log = log.join('\n')
|
||||||
|
if (log.length <= 0) return ''
|
||||||
|
logger.info(`${pluginName || 'Yunzai-Bot'}更新日志,共${line}条\n${log}`)
|
||||||
|
return log
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- {
|
- {
|
||||||
version: 1.0.3,
|
version: 1.0.4,
|
||||||
data:
|
data:
|
||||||
[
|
[
|
||||||
增加<span class="cmd">#小红书</span>的图片解析,
|
增加<span class="cmd">#小红书</span>的图片解析,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user