Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Fix cirular error #156

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
shamefully-hoist=true
auto-install-peers=true
strict-peer-dependencies=true
strict-peer-dependencies=true
enable-pre-post-scripts=true
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(推荐)

Expand Down
7 changes: 4 additions & 3 deletions src/service/friendship.js
Original file line number Diff line number Diff line change
@@ -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')
/**
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/service/msgSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/utils/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down