update: 修改

This commit is contained in:
ningmengchongshui 2024-06-12 10:47:19 +08:00
parent 89ce9bbca2
commit 56f6d5a180
14 changed files with 62 additions and 58 deletions

View File

@ -2,6 +2,8 @@
Miao-Yunzai V4 插件开发示例 Miao-Yunzai V4 插件开发示例
该插件并不会频繁更新,只是开发用例,功能可自行选择
## 使用教程 ## 使用教程
- 安装源码 - 安装源码

View File

@ -6,12 +6,12 @@ import { promisify } from 'util'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import moment from 'moment' import moment from 'moment'
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
import { makeForwardMsg } from 'yunzai/core' import { makeForwardMsg } from 'yunzai/core'
const textArr = {} const textArr = {}
export class add extends plugin { export class add extends Plugin {
/** /**
* *

View File

@ -1,14 +1,16 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class disFriPoke extends plugin { export class disFriPoke extends Plugin {
constructor() { constructor() {
super({ /**
name: '禁止私聊', name: '禁止私聊',
dsc: '对私聊禁用做处理当开启私聊禁用时只接收cookie以及抽卡链接', dsc: '对私聊禁用做处理当开启私聊禁用时只接收cookie以及抽卡链接',
*/
super({
event: 'notice.friend.poke' event: 'notice.friend.poke'
}) })
this.priority = 0 this.priority = 0

View File

@ -1,10 +1,10 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class disPri extends plugin { export class disPri extends Plugin {
/** /**
* *
*/ */

View File

@ -1,8 +1,8 @@
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class example2 extends plugin { export class example2 extends Plugin {
constructor () { constructor () {
/** /**
name: '复读', name: '复读',

View File

@ -1,11 +1,11 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { sleep } from 'yunzai/utils' import { sleep } from 'yunzai/utils'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class friend extends plugin { export class friend extends Plugin {
/** /**
* *
*/ */

View File

@ -1,10 +1,10 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class invite extends plugin { export class invite extends Plugin {
/** /**
* *
*/ */

View File

@ -1,8 +1,8 @@
import { plugin, segment } from 'yunzai/core' import { Plugin, segment } from 'yunzai/core'
/** /**
* *
*/ */
export class newcomer extends plugin { export class newcomer extends Plugin {
/** /**
* *
*/ */
@ -13,7 +13,7 @@ export class newcomer extends plugin {
*/ */
super({ super({
event: 'notice.group.increase', event: 'notice.group.increase',
priority: 5000 priority: 5000,
}) })
} }

View File

@ -1,5 +1,5 @@
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
export class outNotice extends plugin { export class outNotice extends Plugin {
tips = '退群了' tips = '退群了'
constructor() { constructor() {
/** /**

View File

@ -1,9 +1,9 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class quit extends plugin { export class quit extends Plugin {
/** /**
* *
*/ */

View File

@ -1,4 +1,4 @@
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import net from 'net' import net from 'net'
import fs from 'fs' import fs from 'fs'
@ -22,7 +22,7 @@ const isPortTaken = async (port) => {
/** /**
* *
*/ */
export class Restart extends plugin { export class Restart extends Plugin {
key = 'Yz:restart' key = 'Yz:restart'
/** /**

View File

@ -1,4 +1,4 @@
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
import {makeForwardMsg} from 'yunzai/core' import {makeForwardMsg} from 'yunzai/core'
import fs from "node:fs" import fs from "node:fs"
import lodash from "lodash" import lodash from "lodash"
@ -7,7 +7,7 @@ import moment from "moment"
/** /**
* *
*/ */
export class sendLog extends plugin { export class sendLog extends Plugin {
lineNum = 100 lineNum = 100
maxNum = 1000 maxNum = 1000
errFile = "logs/error.log" errFile = "logs/error.log"

View File

@ -1,11 +1,11 @@
import { ConfigController as cfg } from 'yunzai/config' import { ConfigController as cfg } from 'yunzai/config'
import moment from 'moment' import moment from 'moment'
import { plugin } from 'yunzai/core' import { Plugin } from 'yunzai/core'
/** /**
* *
*/ */
export class status extends plugin { export class status extends Plugin {
/** /**
name: '其他功能', name: '其他功能',
dsc: '#状态', dsc: '#状态',

View File

@ -1,4 +1,4 @@
import { makeForwardMsg, plugin } from 'yunzai/core' import { makeForwardMsg, Plugin } from 'yunzai/core'
import lodash from 'lodash' import lodash from 'lodash'
import fs from 'node:fs' import fs from 'node:fs'
import { Restart } from './restart.js' import { Restart } from './restart.js'
@ -9,7 +9,7 @@ import { BOT_NAME } from 'yunzai/config'
let uping = false let uping = false
export class update extends plugin { export class update extends Plugin {
typeName = BOT_NAME typeName = BOT_NAME
messages = [] messages = []
@ -47,17 +47,17 @@ export class update extends plugin {
if (/详细|详情|面板|面版/.test(this.e.msg)) return false if (/详细|详情|面板|面版/.test(this.e.msg)) return false
/** 获取插件 */ /** 获取插件 */
let plugin = this.getPlugin() let Plugin = this.getPlugin()
if (plugin === false) return false if (Plugin === false) return false
/** 执行更新 */ /** 执行更新 */
if (plugin === '') { if (Plugin === '') {
await this.runUpdate('') await this.runUpdate('')
await sleep(1000) await sleep(1000)
plugin = this.getPlugin('miao-plugin') Plugin = this.getPlugin('miao-Plugin')
await this.runUpdate(plugin) await this.runUpdate(Plugin)
} else { } else {
await this.runUpdate(plugin) await this.runUpdate(Plugin)
} }
/** 是否需要重启 */ /** 是否需要重启 */
@ -67,16 +67,16 @@ 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 ''
} }
if (!fs.existsSync(`plugins/${plugin}/.git`)) return false if (!fs.existsSync(`Plugins/${Plugin}/.git`)) return false
this.typeName = plugin this.typeName = Plugin
return plugin return Plugin
} }
async execSync(cmd) { async execSync(cmd) {
@ -87,7 +87,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'
@ -97,9 +97,9 @@ export class update extends plugin {
type = '强制更新' type = '强制更新'
cm = `git reset --hard && git pull --rebase --allow-unrelated-histories` cm = `git reset --hard && git pull --rebase --allow-unrelated-histories`
} }
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}` if (Plugin) cm = `cd "Plugins/${Plugin}" && ${cm}`
this.oldCommitId = await this.getcommitId(plugin) this.oldCommitId = await this.getcommitId(Plugin)
logger.mark(`${this.e.logFnc} 开始${type}${this.typeName}`) logger.mark(`${this.e.logFnc} 开始${type}${this.typeName}`)
@ -114,31 +114,31 @@ export class update extends plugin {
return false return false
} }
const time = await this.getTime(plugin) const time = await this.getTime(Plugin)
if (/Already up|已经是最新/g.test(ret.stdout)) { if (/Already up|已经是最新/g.test(ret.stdout)) {
await this.reply(`${this.typeName} 已是最新\n最后更新时间${time}`) await this.reply(`${this.typeName} 已是最新\n最后更新时间${time}`)
} else { } else {
await this.reply(`${this.typeName} 更新成功\n更新时间${time}`) await this.reply(`${this.typeName} 更新成功\n更新时间${time}`)
this.isUp = true this.isUp = true
await this.reply(await this.getLog(plugin)) await this.reply(await this.getLog(Plugin))
} }
logger.mark(`${this.e.logFnc} 最后更新时间:${time}`) logger.mark(`${this.e.logFnc} 最后更新时间:${time}`)
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}`
const commitId = await execSync(cm, { encoding: 'utf-8' }) const commitId = await execSync(cm, { encoding: 'utf-8' })
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}`
let time = '' let time = ''
try { try {
@ -179,7 +179,7 @@ export class update extends plugin {
} }
async updateAll() { async updateAll() {
const dirs = fs.readdirSync('./plugins/') const dirs = fs.readdirSync('./Plugins/')
const originalReply = this.reply const originalReply = this.reply
@ -216,9 +216,9 @@ export class update extends plugin {
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}`
let logAll let logAll
try { try {
@ -247,7 +247,7 @@ export class update extends plugin {
let end = '' let end = ''
try { try {
cm = 'git config -l' cm = 'git config -l'
if (plugin) cm = `cd "plugins/${plugin}" && ${cm}` if (Plugin) cm = `cd "Plugins/${Plugin}" && ${cm}`
end = await execSync(cm, { encoding: 'utf-8' }) end = await execSync(cm, { encoding: 'utf-8' })
end = end.match(/remote\..*\.url=.+/g).join('\n\n').replace(/remote\..*\.url=/g, '').replace(/\/\/([^@]+)@/, '//') end = end.match(/remote\..*\.url=.+/g).join('\n\n').replace(/remote\..*\.url=/g, '').replace(/\/\/([^@]+)@/, '//')
} catch (error) { } catch (error) {
@ -255,12 +255,12 @@ export class update extends plugin {
await this.reply(error.toString()) await this.reply(error.toString())
} }
return makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'} 更新日志,共${line}`) return 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))
} }
} }