diff --git a/.npmrc b/.npmrc index cc3ea88..945c927 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,4 @@ shamefully-hoist=true auto-install-peers=true -strict-peer-dependencies=true \ No newline at end of file +strict-peer-dependencies=true +enable-pre-post-scripts=true \ No newline at end of file diff --git a/README.md b/README.md index 72387bd..cebdebc 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,6 @@ curl --location 'http://localhost:3001/webhook/msg/v2' \ > [!IMPORTANT] > 包管理器迁移已至 pnpm,安装依赖请使用它,以支持一些不定时的临时包修补(patches)和加速依赖安装 -> -> 值得一提的是,运行程序请使用 `npm start`, pnpm 不会执行 prestart 的钩子 [pnpm 与 npm run的不同之处](https://pnpm.io/zh/cli/run#%E4%B8%8E-npm-run%E7%9A%84%E4%B8%8D%E5%90%8C%E4%B9%8B%E5%A4%84) ## ⛰️ 部署 Deploy(推荐) diff --git a/src/service/friendship.js b/src/service/friendship.js index 5c07c5d..634797f 100644 --- a/src/service/friendship.js +++ b/src/service/friendship.js @@ -1,5 +1,6 @@ const Utils = require('../utils/index') -const Service = require('./index') +const { handleResSendMsg } = require('./msgSender') +const { sendMsg2RecvdApi } = require('./msgUploader') const { FriendshipMsg } = require('../utils/msg.js') const { MSG_TYPE_ENUM } = require('../config/const') /** @@ -17,14 +18,14 @@ const onRecvdFriendship = async (friendship, botInstance) => { // 收到好友邀请 case Friendship.Type.Receive: try { - const res = await Service.sendMsg2RecvdApi( + const res = await sendMsg2RecvdApi( new FriendshipMsg({ name: friendship.contact().name(), hello: friendship.hello() }) ) - await Service.handleResSendMsg({ + await handleResSendMsg({ res, type: MSG_TYPE_ENUM.CUSTOM_FRIENDSHIP, friendship diff --git a/src/service/msgSender.js b/src/service/msgSender.js index 09f6a3e..8231a30 100644 --- a/src/service/msgSender.js +++ b/src/service/msgSender.js @@ -566,7 +566,7 @@ const handleResSendMsg = async ({ res, type, friendship, msgInstance }) => { if (success === true && data !== undefined) { await Utils.sleep(1000) //@ts-expect-errors 重载不是很好使,手动判断 - recvdApiReplyHandler(data, friendship.contact(), to) + recvdApiReplyHandler(data, { msgInstance: friendship.contact(), to }) } break diff --git a/src/utils/log.js b/src/utils/log.js index 1e46b3b..44c6dff 100644 --- a/src/utils/log.js +++ b/src/utils/log.js @@ -61,6 +61,20 @@ if (!process.env.homeEnvCfg) { ].some(Boolean) } + /** + * 希望排除一些错误 + * @param {any[]} args + * @returns {boolean} + */ + const blackListConditionError = (args) => { + const arg0 = args?.[0] + + return [ + // form-data 提示的DepracationWarning,会被认为是错误提issue + '[https://github.com/node-fetch/node-fetch/issues/1167]' + ].some((str) => arg0.includes(str)) + } + console.log = function (...args) { try { if (args?.[1] instanceof Error) { @@ -91,6 +105,8 @@ if (!process.env.homeEnvCfg) { console.error = function (...args) { try { + if (blackListConditionError(args)) return + if (!whiteListConditionLog(args)) { logger.error(...args) // 将输出写入 Log4js 配置的文件 } else {