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