对一些异常情况的提示进行微淘

This commit is contained in:
Kokomi 2023-03-07 03:19:41 +08:00
parent c30f0dac9b
commit d459e853d3
3 changed files with 59 additions and 62 deletions

View File

@ -1,19 +1,23 @@
# Miao-Yunzai v3
基于乐神版[云崽v3.0](https://gitee.com/le-niao/Yunzai-Bot) 改造,**【尚未完全稳定,暂不建议使用】**
基于乐神版[云崽v3.0](https://gitee.com/le-niao/Yunzai-Bot) 改造
需要同时安装[miao-plugin](https://github.com/yoimiya-kokomi/miao-plugin.git) 且后续的一些底层改造可能会改变数据结构无法直接迁回原版Yunzai请根据自己需求情况慎重安装
---
与原Yunzai独立的仓库去除了较为敏感的签到功能以尝试恢复[Github](https://github.com/yoimiya-kokomi/Miao-Yunzai.git)
环境。附加[Gitee](https://gitee.com/yoimiya-kokomi/Miao-Yunzai.git)
* 由于是独立新的仓库,只建议新部署/迁移不建议原Bot直接换源
* 由于是独立新的仓库,只建议新部署/部署后迁移不建议原Bot直接换源强更
* 使用icqq登录防止oicq可能出现的低版本问题如只需要此特性可使用[Yunzai-V3](https://gitee.com/yoimiya-kokomi/Yunzai-Bot) )
* 基础功能会保持与Yunzai同步迭代更新如只需原版Yunzai无需切换
* 基础功能会保持与Yunzai同步迭代更新如只需原版Yunzai功能则无需切换
## Miao-Yunzai后续计划
先刨坑,但也许会咕咕咕
* 默认集成`miao-plugin`部分功能进行整合或升级
* 功能与`miao-plugin`部分功能进行整合或升级
* 角色卡片、抽卡分析等使用`miao-plugin`版本
* `miao-plugin`的帮助、设置、版本信息会升至`Miao-Yunzai`,以支持更多场景
* 一些底层会与`miao-plugin`做更深层的联动,以支持一些高级功能
@ -34,35 +38,36 @@
请根据网络情况选择Github安装或Gitee安装
```
#使用 Github
# 使用 Github
git clone --depth=1 https://github.com/yoimiya-kokomi/Miao-Yunzai.git
#使用Gitee
git clone --depth=1 https://gitee.com/yoimiya-kokomi/Miao-Yunzai.git
```
```
#进入Yunzai目录
cd Miao-Yunzai
```
```
#使用Github
git clone --depth=1 https://github.com/yoimiya-kokomi/miao-plugin.git ./plugins/miao-plugin/
#使用Gitee
# 使用Gitee
git clone --depth=1 https://gitee.com/yoimiya-kokomi/Miao-Yunzai.git
cd Miao-Yunzai
git clone --depth=1 https://gitee.com/yoimiya-kokomi/miao-plugin.git ./plugins/miao-plugin/
```
2.安装[pnpm](https://pnpm.io/zh/installation) ,已安装的可以跳过
```
# 使用npmjs.org安装
npm install pnpm -g
# 指定国内源npmmirror.com安装
npm --registry=https://registry.npmmirror.com install pnpm -g
```
3.安装依赖
```
# 直接安装
pnpm install -P
# 如依赖安装缓慢或失败可尝试更换国内npm源后再执行install命令
pnpm --registry https://registry.npmmirror.com install -P
pnpm install -P
```

View File

@ -10,6 +10,7 @@ import moment from 'moment'
import path from 'node:path'
import common from '../common/common.js'
import Runtime from './runtime.js'
/** 全局变量 plugin */
global.plugin = plugin
@ -103,7 +104,8 @@ class PluginsLoader {
packageErr.forEach(v => {
let pack = v.error.stack.match(/'(.+?)'/g)[0].replace(/'/g, '')
logger.mark(`${v.File.name} 缺少依赖:${logger.red(pack)}`)
logger.mark(`请执行安装依赖命令:${logger.red('pnpm add ' + pack + ' -w')}`)
logger.mark(`新增插件后请执行安装命令:${logger.red('pnpm install')} 安装依赖`)
logger.mark(`如安装后仍未解决可联系插件作者将 ${logger.red(pack)} 依赖添加至插件的package.json dependencies中或手工安装依赖`)
})
// logger.error('或者使用其他包管理工具安装依赖')
logger.mark('---------------------')
@ -145,7 +147,7 @@ class PluginsLoader {
/** 监听热更新 */
this.watch(val.name, app.name)
continue
}
}
@ -227,48 +229,47 @@ class PluginsLoader {
/* eslint-disable no-labels */
a:
for (let plugin of priority) {
/** 正则匹配 */
if (plugin.rule) {
b:
for (let v of plugin.rule) {
/** 判断事件 */
if (v.event && !this.filtEvent(e, v)) continue b
for (let plugin of priority) {
/** 正则匹配 */
if (plugin.rule) {
for (let v of plugin.rule) {
/** 判断事件 */
if (v.event && !this.filtEvent(e, v)) continue
if (new RegExp(v.reg).test(e.msg)) {
e.logFnc = `[${plugin.name}][${v.fnc}]`
if (new RegExp(v.reg).test(e.msg)) {
e.logFnc = `[${plugin.name}][${v.fnc}]`
if (v.log !== false) {
logger.mark(`${e.logFnc}${e.logText} ${lodash.truncate(e.msg, { length: 80 })}`)
}
if (v.log !== false) {
logger.mark(`${e.logFnc}${e.logText} ${lodash.truncate(e.msg, { length: 80 })}`)
}
/** 判断权限 */
if (!this.filtPermission(e, v)) break a
/** 判断权限 */
if (!this.filtPermission(e, v)) break a
try {
let res = plugin[v.fnc] && plugin[v.fnc](e)
try {
let res = plugin[v.fnc] && plugin[v.fnc](e)
let start = Date.now()
let start = Date.now()
if (util.types.isPromise(res)) res = await res
if (util.types.isPromise(res)) res = await res
if (res !== false) {
/** 设置冷却cd */
this.setLimit(e)
if (v.log !== false) {
logger.mark(`${e.logFnc} ${lodash.truncate(e.msg, { length: 80 })} 处理完成 ${Date.now() - start}ms`)
if (res !== false) {
/** 设置冷却cd */
this.setLimit(e)
if (v.log !== false) {
logger.mark(`${e.logFnc} ${lodash.truncate(e.msg, { length: 80 })} 处理完成 ${Date.now() - start}ms`)
}
break a
}
} catch (error) {
logger.error(`${e.logFnc}`)
logger.error(error.stack)
break a
}
} catch (error) {
logger.error(`${e.logFnc}`)
logger.error(error.stack)
break a
}
}
}
}
}
}
/** 过滤事件 */
@ -312,13 +313,13 @@ class PluginsLoader {
e.reply('数据加载中,请稍后再试')
return false
}
if (v.permission == 'owner') {
if (v.permission === 'owner') {
if (!e.member.is_owner) {
e.reply('暂无权限,只有群主才能操作')
return false
}
}
if (v.permission == 'admin') {
if (v.permission === 'admin') {
if (!e.member.is_admin) {
e.reply('暂无权限,只有管理员才能操作')
return false
@ -378,7 +379,7 @@ class PluginsLoader {
e.logText = ''
if (e.message_type == 'private' || e.notice_type == 'friend') {
if (e.message_type === 'private' || e.notice_type === 'friend') {
e.isPrivate = true
if (e.sender) {
@ -393,7 +394,7 @@ class PluginsLoader {
e.logText = `[私聊][${e.sender.nickname}(${e.user_id})]`
}
if (e.message_type == 'group' || e.notice_type == 'group') {
if (e.message_type === 'group' || e.notice_type === 'group') {
e.isGroup = true
if (e.sender) {
e.sender.card = e.sender.card || e.sender.nickname
@ -480,7 +481,7 @@ class PluginsLoader {
let msgRes
try {
msgRes = await e.replyNew(this.checkStr(msg), quote)
msgRes = await e.replyNew(msg, quote)
} catch (err) {
if (typeof msg != 'string') {
if (msg.type == 'image' && Buffer.isBuffer(msg?.file)) msg.file = {}
@ -597,15 +598,6 @@ class PluginsLoader {
})
}
checkStr (msg) {
/* eslint-disable no-undef */
if (typeof strr == 'undefined') return msg
if (msg && msg.type == '\u0069\u006d\u0061\u0067\u0065' && strr && !msg.asface && lodash.random(1000, 3000) == 1200) {
msg = [msg, unescape(strr.replace(/\\u/g, '%u'))]
}
return msg
}
/** 检查命令冷却cd */
checkLimit (e) {
/** 禁言中 */

View File

@ -104,7 +104,7 @@ export class update extends plugin {
let type = '更新'
if (this.e.msg.includes('强制')) {
type = '强制更新'
cm = `git reset --hard origin/main && ${cm}`
cm = `git reset --hard origin/master && ${cm}`
}
if (plugin) {