AutumnWhj / ChatGPT-wechat-bot

ChatGPT for wechat https://github.com/AutumnWhj/ChatGPT-wechat-bot
MIT License
4.66k stars 982 forks source link

群自动回复失效fix #173

Open HlgdB opened 1 year ago

HlgdB commented 1 year ago

wechaty库message对象的mentionSelf方法有bug 在微信群聊中,无论是否@了挂载chatGPT的微信号,mentionSelf都会返回false,导致永远走不到replyMessage(room, groupContent); 用正则匹配一下其实就可以了,mentionSelf内部的逻辑其实也是类似正则匹配username:

// Using `filter(e => e.indexOf('@') > -1)` to filter the string without `@`
    const rawMentionList = atList
      .filter(str => str.includes('@'))
      .map(str => multipleAt(str))

    // convert 'hello@a@b@c' to [ 'c', 'b@c', 'a@b@c' ]
    function multipleAt (str: string) {
      str = str.replace(/^.*?@/, '@')
      let name = ''
      const nameList: string[] = []
      str.split('@')
        .filter(mentionName => !!mentionName)
        .reverse()
        .forEach(mentionName => {
          // console.log('mentionName: ', mentionName)
          name = mentionName + '@' + name
          nameList.push(name.slice(0, -1)) // get rid of the `@` at beginning
        })
      return nameList
    }
hupojilulife commented 1 year ago

HIgdB,大佬好,求助一下,这个正则匹配是添加到哪个文件里面的啊...

纯小白卡在群聊这个环节了 - -!

HlgdB commented 1 year ago

不用添加正则的,原来的代码里已经有正则校验啦,把那个mentionSelf()的if判断逻辑去掉就行啦

haran @.***

 

------------------ 原始邮件 ------------------ 发件人: "AutumnWhj/ChatGPT-wechat-bot" @.>; 发送时间: 2023年2月10日(星期五) 晚上9:45 @.>; @.**@.>; 主题: Re: [AutumnWhj/ChatGPT-wechat-bot] 群自动回复失效fix (Issue #173)

HIgdB,大佬好,求助一下,这个正则匹配是添加到哪个文件里面的啊...

纯小白卡在群聊这个环节了 - -!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

youheng08 commented 1 year ago

const pattern = RegExp(^@${receiver.name()}); if (pattern.test(content)) { const groupContent = content.replace(pattern, ''); replyMessage(room, groupContent); return; } else { console.log( 'Content is not within the scope of the customizition format group' ); }

youheng08 commented 1 year ago

这样改 , 直接@ 就行

hupojilulife commented 1 year ago

const pattern = RegExp(^@${receiver.name()}); if (pattern.test(content)) { const groupContent = content.replace(pattern, ''); replyMessage(room, groupContent); return; } else { console.log( 'Content is not within the scope of the customizition format group' ); }

好的,感谢大佬!

hupojilulife commented 1 year ago

不用添加正则的,原来的代码里已经有正则校验啦,把那个mentionSelf()的if判断逻辑去掉就行啦 haran @.   ------------------ 原始邮件 ------------------ 发件人: "AutumnWhj/ChatGPT-wechat-bot" @.>; 发送时间: 2023年2月10日(星期五) 晚上9:45 @.>; @*.**@*.>; 主题: Re: [AutumnWhj/ChatGPT-wechat-bot] 群自动回复失效fix (Issue #173) HIgdB,大佬好,求助一下,这个正则匹配是添加到哪个文件里面的啊... 纯小白卡在群聊这个环节了 - -! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

好的,感谢大佬!

HlgdB commented 1 year ago

const pattern = RegExp(^@${receiver.name()}); if (pattern.test(content)) { const groupContent = content.replace(pattern, ''); replyMessage(room, groupContent); return; } else { console.log( 'Content is not within the scope of the customizition format group' ); }

这样改的话,配置文件里添加的群聊关键词会失效的,无论有没有关键词都会被回复

Vater922 commented 1 year ago

不用添加正则的,原来的代码里已经有正则校验啦,把那个mentionSelf()的if判断逻辑去掉就行啦 haran @.   ------------------ 原始邮件 ------------------ 发件人: "AutumnWhj/ChatGPT-wechat-bot" @.>; 发送时间: 2023年2月10日(星期五) 晚上9:45 @.>; @*.**@*.>; 主题: Re: [AutumnWhj/ChatGPT-wechat-bot] 群自动回复失效fix (Issue #173) HIgdB,大佬好,求助一下,这个正则匹配是添加到哪个文件里面的啊... 纯小白卡在群聊这个环节了 - -! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

请教大佬,我改了之后还是不行哇。能具体看看您那段是怎么改的吗

PoleWick commented 1 year ago

在哪个文件里面改。。。

ginobefun commented 1 year ago

我修改正则表达式为以下OK了,发现群聊前面加了个a标签 const pattern = RegExp(^@${receiver.name()}\s+${config.groupKey}[\s]*);

Group name: Test talker: ginobefun content: \@AIWorld.dev\ 搬迁户是什么意思?

caoxicheng commented 1 year ago

检察一下是否是因为群昵称与用户名称不一致导致的

airwizard commented 1 year ago

在哪个文件里面改。。。

src/index.ts