feat: #静默全部更新
This commit is contained in:
parent
de3e7f377c
commit
b2516e8b71
|
@ -11,7 +11,7 @@ const { exec, execSync } = require('child_process')
|
||||||
let uping = false
|
let uping = false
|
||||||
|
|
||||||
export class update extends plugin {
|
export class update extends plugin {
|
||||||
constructor () {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
name: '更新',
|
name: '更新',
|
||||||
dsc: '#更新 #强制更新',
|
dsc: '#更新 #强制更新',
|
||||||
|
@ -27,7 +27,7 @@ export class update extends plugin {
|
||||||
fnc: 'update'
|
fnc: 'update'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '^#全部(强制)?更新$',
|
reg: '^#(静默?)全部(强制)?更新$',
|
||||||
fnc: 'updateAll',
|
fnc: 'updateAll',
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,10 @@ export class update extends plugin {
|
||||||
})
|
})
|
||||||
|
|
||||||
this.typeName = 'Miao-Yunzai'
|
this.typeName = 'Miao-Yunzai'
|
||||||
|
this.messages = []
|
||||||
}
|
}
|
||||||
|
|
||||||
async update () {
|
async update() {
|
||||||
if (!this.e.isMaster) return false
|
if (!this.e.isMaster) return false
|
||||||
if (uping) return this.reply('已有命令更新中..请勿重复操作')
|
if (uping) return this.reply('已有命令更新中..请勿重复操作')
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ export class update extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlugin (plugin = '') {
|
getPlugin(plugin = '') {
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
plugin = this.e.msg.replace(/#(强制)?更新(日志)?/, '')
|
plugin = this.e.msg.replace(/#(强制)?更新(日志)?/, '')
|
||||||
if (!plugin) return ''
|
if (!plugin) return ''
|
||||||
|
@ -76,7 +77,7 @@ export class update extends plugin {
|
||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
async execSync (cmd) {
|
async execSync(cmd) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
||||||
resolve({ error, stdout, stderr })
|
resolve({ error, stdout, stderr })
|
||||||
|
@ -84,7 +85,7 @@ export class update extends plugin {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async runUpdate (plugin = '') {
|
async runUpdate(plugin = '') {
|
||||||
this.isNowUp = false
|
this.isNowUp = false
|
||||||
|
|
||||||
let cm = 'git pull --no-rebase'
|
let cm = 'git pull --no-rebase'
|
||||||
|
@ -125,7 +126,7 @@ export class update extends plugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async getcommitId (plugin = '') {
|
async getcommitId(plugin = '') {
|
||||||
let cm = 'git rev-parse --short HEAD'
|
let cm = 'git rev-parse --short HEAD'
|
||||||
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ export class update extends plugin {
|
||||||
return lodash.trim(commitId)
|
return lodash.trim(commitId)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTime (plugin = '') {
|
async getTime(plugin = '') {
|
||||||
let cm = 'git log -1 --pretty=%cd --date=format:"%F %T"'
|
let cm = 'git log -1 --pretty=%cd --date=format:"%F %T"'
|
||||||
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ export class update extends plugin {
|
||||||
return time
|
return time
|
||||||
}
|
}
|
||||||
|
|
||||||
async gitErr (err, stdout) {
|
async gitErr(err, stdout) {
|
||||||
const msg = '更新失败!'
|
const msg = '更新失败!'
|
||||||
const errMsg = err.toString()
|
const errMsg = err.toString()
|
||||||
stdout = stdout.toString()
|
stdout = stdout.toString()
|
||||||
|
@ -175,9 +176,18 @@ export class update extends plugin {
|
||||||
return this.reply([errMsg, stdout])
|
return this.reply([errMsg, stdout])
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAll () {
|
async updateAll() {
|
||||||
const dirs = fs.readdirSync('./plugins/')
|
const dirs = fs.readdirSync('./plugins/')
|
||||||
|
|
||||||
|
const originalReply = this.reply
|
||||||
|
|
||||||
|
if (/^#静默全部(强制)?更新$/.test(this.e.msg)) {
|
||||||
|
await this.e.reply(`开始执行静默全部更新...请稍等`)
|
||||||
|
this.reply = (message) => {
|
||||||
|
this.messages.push(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await this.runUpdate()
|
await this.runUpdate()
|
||||||
|
|
||||||
for (let plu of dirs) {
|
for (let plu of dirs) {
|
||||||
|
@ -187,17 +197,21 @@ export class update extends plugin {
|
||||||
await this.runUpdate(plu)
|
await this.runUpdate(plu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.e.reply(await common.makeForwardMsg(this.e, this.messages))
|
||||||
|
|
||||||
if (this.isUp) {
|
if (this.isUp) {
|
||||||
// await this.reply('即将执行重启,以应用更新')
|
// await this.reply('即将执行重启,以应用更新')
|
||||||
setTimeout(() => this.restart(), 2000)
|
setTimeout(() => this.restart(), 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.reply = originalReply
|
||||||
}
|
}
|
||||||
|
|
||||||
restart () {
|
restart() {
|
||||||
new Restart(this.e).restart()
|
new Restart(this.e).restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLog (plugin = '') {
|
async getLog(plugin = '') {
|
||||||
let cm = 'git log -100 --pretty="%h||[%cd] %s" --date=format:"%F %T"'
|
let cm = 'git log -100 --pretty="%h||[%cd] %s" --date=format:"%F %T"'
|
||||||
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}`
|
||||||
|
|
||||||
|
@ -239,7 +253,7 @@ export class update extends plugin {
|
||||||
return common.makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'} 更新日志,共${line}条`)
|
return common.makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'} 更新日志,共${line}条`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateLog () {
|
async updateLog() {
|
||||||
const plugin = this.getPlugin()
|
const plugin = this.getPlugin()
|
||||||
if (plugin === false) return false
|
if (plugin === false) return false
|
||||||
return this.reply(await this.getLog(plugin))
|
return this.reply(await this.getLog(plugin))
|
||||||
|
|
Loading…
Reference in New Issue