ChatGPT-wechat-bot
ChatGPT-wechat-bot copied to clipboard
群自动回复失效fix
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
}
HIgdB,大佬好,求助一下,这个正则匹配是添加到哪个文件里面的啊...
纯小白卡在群聊这个环节了 - -!
不用添加正则的,原来的代码里已经有正则校验啦,把那个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: @.***>
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'
);
}
这样改 , 直接@ 就行
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' ); }
好的,感谢大佬!
不用添加正则的,原来的代码里已经有正则校验啦,把那个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: @.***>
好的,感谢大佬!
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' ); }
这样改的话,配置文件里添加的群聊关键词会失效的,无论有没有关键词都会被回复
不用添加正则的,原来的代码里已经有正则校验啦,把那个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: @.***>
请教大佬,我改了之后还是不行哇。能具体看看您那段是怎么改的吗
在哪个文件里面改。。。
我修改正则表达式为以下OK了,发现群聊前面加了个a标签
const pattern = RegExp(
^@${receiver.name()}\s+${config.groupKey}[\s]*);
Group name: Test talker: ginobefun content: <a target="_blank" href="/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl=http%3A%2F%2F%40AIWorld.dev&skey=%40crypt_869f98bd_810089d62f219fe2f5a32cfcd0019afb&deviceid=e558803801144649&pass_ticket=undefined&opcode=2&scene=1&username=@657969f283632beb27793f2ada0d01b937b0dbc4a1d4c6b45b9e45d9844aa54d">@AIWorld.dev</a> 搬迁户是什么意思?
检察一下是否是因为群昵称与用户名称不一致导致的
在哪个文件里面改。。。
src/index.ts