Skip to content

Commit

Permalink
fix: 🐛 修复friendship事件不上报recvdAPI的问题. close:#155
Browse files Browse the repository at this point in the history
✅ Closes: 155
  • Loading branch information
danni-cool committed Feb 6, 2024
1 parent 51ce80e commit 19b9148
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit 19b9148

Please sign in to comment.