From 56f6d5a1806187443f19c3e8176fd0cedda9b028 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Wed, 12 Jun 2024 10:47:19 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ apps/add.ts | 4 +-- apps/disFriPoke.ts | 8 +++--- apps/disPri.ts | 4 +-- apps/example2.ts | 4 +-- apps/friend.ts | 4 +-- apps/invite.ts | 4 +-- apps/newcomer.ts | 6 ++--- apps/outNotice.ts | 4 +-- apps/quit.ts | 4 +-- apps/restart.ts | 4 +-- apps/sendLog.ts | 4 +-- apps/status.ts | 4 +-- apps/update.ts | 64 +++++++++++++++++++++++----------------------- 14 files changed, 62 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index c5ad393..da2b70d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Miao-Yunzai V4 插件开发示例 +该插件并不会频繁更新,只是开发用例,功能可自行选择 + ## 使用教程 - 安装源码 diff --git a/apps/add.ts b/apps/add.ts index 8169cc3..0226bc8 100644 --- a/apps/add.ts +++ b/apps/add.ts @@ -6,12 +6,12 @@ import { promisify } from 'util' import fetch from 'node-fetch' import moment from 'moment' import { ConfigController as cfg } from 'yunzai/config' -import { plugin } from 'yunzai/core' +import { Plugin } from 'yunzai/core' import { makeForwardMsg } from 'yunzai/core' const textArr = {} -export class add extends plugin { +export class add extends Plugin { /** * diff --git a/apps/disFriPoke.ts b/apps/disFriPoke.ts index 537a96d..859f312 100644 --- a/apps/disFriPoke.ts +++ b/apps/disFriPoke.ts @@ -1,14 +1,16 @@ 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() { - super({ + /** name: '禁止私聊', dsc: '对私聊禁用做处理当开启私聊禁用时只接收cookie以及抽卡链接', + */ + super({ event: 'notice.friend.poke' }) this.priority = 0 diff --git a/apps/disPri.ts b/apps/disPri.ts index 6a25eb8..c4de567 100644 --- a/apps/disPri.ts +++ b/apps/disPri.ts @@ -1,10 +1,10 @@ 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 { /** * */ diff --git a/apps/example2.ts b/apps/example2.ts index ad4e0b4..2866b1c 100644 --- a/apps/example2.ts +++ b/apps/example2.ts @@ -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 () { /** name: '复读', diff --git a/apps/friend.ts b/apps/friend.ts index 3d0d476..19f7da2 100644 --- a/apps/friend.ts +++ b/apps/friend.ts @@ -1,11 +1,11 @@ import { ConfigController as cfg } from 'yunzai/config' 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 { /** * */ diff --git a/apps/invite.ts b/apps/invite.ts index 2c7fb57..e2c7f77 100644 --- a/apps/invite.ts +++ b/apps/invite.ts @@ -1,10 +1,10 @@ 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 { /** * */ diff --git a/apps/newcomer.ts b/apps/newcomer.ts index d6b5d3a..09f7285 100644 --- a/apps/newcomer.ts +++ b/apps/newcomer.ts @@ -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({ event: 'notice.group.increase', - priority: 5000 + priority: 5000, }) } diff --git a/apps/outNotice.ts b/apps/outNotice.ts index 47a97ae..b0c1420 100644 --- a/apps/outNotice.ts +++ b/apps/outNotice.ts @@ -1,5 +1,5 @@ -import { plugin } from 'yunzai/core' -export class outNotice extends plugin { +import { Plugin } from 'yunzai/core' +export class outNotice extends Plugin { tips = '退群了' constructor() { /** diff --git a/apps/quit.ts b/apps/quit.ts index c6972f3..4c5c470 100644 --- a/apps/quit.ts +++ b/apps/quit.ts @@ -1,9 +1,9 @@ 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 { /** * */ diff --git a/apps/restart.ts b/apps/restart.ts index 03cb9f4..74f4c94 100644 --- a/apps/restart.ts +++ b/apps/restart.ts @@ -1,4 +1,4 @@ -import { plugin } from 'yunzai/core' +import { Plugin } from 'yunzai/core' import fetch from 'node-fetch' import net from 'net' 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' /** diff --git a/apps/sendLog.ts b/apps/sendLog.ts index 9a4859d..59334be 100644 --- a/apps/sendLog.ts +++ b/apps/sendLog.ts @@ -1,4 +1,4 @@ -import { plugin } from 'yunzai/core' +import { Plugin } from 'yunzai/core' import {makeForwardMsg} from 'yunzai/core' import fs from "node:fs" import lodash from "lodash" @@ -7,7 +7,7 @@ import moment from "moment" /** * */ -export class sendLog extends plugin { +export class sendLog extends Plugin { lineNum = 100 maxNum = 1000 errFile = "logs/error.log" diff --git a/apps/status.ts b/apps/status.ts index 3588d74..7d37cf0 100644 --- a/apps/status.ts +++ b/apps/status.ts @@ -1,11 +1,11 @@ import { ConfigController as cfg } from 'yunzai/config' 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: '其他功能', dsc: '#状态', diff --git a/apps/update.ts b/apps/update.ts index 07c788b..80cea7c 100644 --- a/apps/update.ts +++ b/apps/update.ts @@ -1,4 +1,4 @@ -import { makeForwardMsg, plugin } from 'yunzai/core' +import { makeForwardMsg, Plugin } from 'yunzai/core' import lodash from 'lodash' import fs from 'node:fs' import { Restart } from './restart.js' @@ -9,7 +9,7 @@ import { BOT_NAME } from 'yunzai/config' let uping = false -export class update extends plugin { +export class update extends Plugin { typeName = BOT_NAME messages = [] @@ -47,17 +47,17 @@ export class update extends plugin { if (/详细|详情|面板|面版/.test(this.e.msg)) return false /** 获取插件 */ - let plugin = this.getPlugin() - if (plugin === false) return false + let Plugin = this.getPlugin() + if (Plugin === false) return false /** 执行更新 */ - if (plugin === '') { + if (Plugin === '') { await this.runUpdate('') await sleep(1000) - plugin = this.getPlugin('miao-plugin') - await this.runUpdate(plugin) + Plugin = this.getPlugin('miao-Plugin') + await this.runUpdate(Plugin) } else { - await this.runUpdate(plugin) + await this.runUpdate(Plugin) } /** 是否需要重启 */ @@ -67,16 +67,16 @@ export class update extends plugin { } } - getPlugin(plugin = '') { - if (!plugin) { - plugin = this.e.msg.replace(/#(强制)?更新(日志)?/, '') - if (!plugin) return '' + getPlugin(Plugin = '') { + if (!Plugin) { + Plugin = this.e.msg.replace(/#(强制)?更新(日志)?/, '') + if (!Plugin) return '' } - if (!fs.existsSync(`plugins/${plugin}/.git`)) return false + if (!fs.existsSync(`Plugins/${Plugin}/.git`)) return false - this.typeName = plugin - return plugin + this.typeName = Plugin + return Plugin } async execSync(cmd) { @@ -87,7 +87,7 @@ export class update extends plugin { }) } - async runUpdate(plugin = '') { + async runUpdate(Plugin = '') { this.isNowUp = false let cm = 'git pull --no-rebase' @@ -97,9 +97,9 @@ export class update extends plugin { type = '强制更新' 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}`) @@ -114,31 +114,31 @@ export class update extends plugin { return false } - const time = await this.getTime(plugin) + const time = await this.getTime(Plugin) if (/Already up|已经是最新/g.test(ret.stdout)) { await this.reply(`${this.typeName} 已是最新\n最后更新时间:${time}`) } else { await this.reply(`${this.typeName} 更新成功\n更新时间:${time}`) this.isUp = true - await this.reply(await this.getLog(plugin)) + await this.reply(await this.getLog(Plugin)) } logger.mark(`${this.e.logFnc} 最后更新时间:${time}`) return true } - async getcommitId(plugin = '') { + async getcommitId(Plugin = '') { 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' }) 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}` + if (Plugin) cm = `cd "Plugins/${Plugin}" && ${cm}` let time = '' try { @@ -179,7 +179,7 @@ export class update extends plugin { } async updateAll() { - const dirs = fs.readdirSync('./plugins/') + const dirs = fs.readdirSync('./Plugins/') const originalReply = this.reply @@ -216,9 +216,9 @@ export class update extends plugin { 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}` + if (Plugin) cm = `cd "Plugins/${Plugin}" && ${cm}` let logAll try { @@ -247,7 +247,7 @@ export class update extends plugin { let end = '' try { 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 = end.match(/remote\..*\.url=.+/g).join('\n\n').replace(/remote\..*\.url=/g, '').replace(/\/\/([^@]+)@/, '//') } catch (error) { @@ -255,12 +255,12 @@ export class update extends plugin { 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() { - const plugin = this.getPlugin() - if (plugin === false) return false - return this.reply(await this.getLog(plugin)) + const Plugin = this.getPlugin() + if (Plugin === false) return false + return this.reply(await this.getLog(Plugin)) } }