-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot recognize room event #1116
Conversation
Please add the related unit test for before I could review/merge your PR. The following steps are my suggestion:
|
WECHATY VERSION
Wechaty Doctor
REPRODUCErun 1. Bot invite someone into the group.Log as follows:
Actually the room join system log is 2. People join the group by the qrcode shared by the bot.Log as follows:
Actually the room join system log is CONCLUSIONBase on above information, I will pr then, and I think it happens not only on room join event, so I delete |
UNIT TEST PARTI add a unit test, and the current version cannot pass the unit test, log as follows:
|
Thanks for adding the test cases, but please do not just copy/paste all the code into the discussion because it's not easy to read and more like spam. Before this PR could be merged, there's one more rule you need follow: we should always use strict RegExp condition instead of a loose one because we'd better make sure what's happening inside our system. So please: keep the |
Update as follows:What I said about Reproduce CodeIn order to provide a strict RegExp condition, I test all conditions and found all room-join event doesn't work because wechat changes its room join in the system message and all of the system message are different, and I put all related logs here: I add the following console.log in [room-bot.ts] .on('message', async function(this, message) {
const room = message.room()
const sender = message.from()
const content = message.content()
console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + sender.name() + '>'
+ ':' + message.toStringDigest(),
)
console.log('======console.log the last 4 charCode======')
console.log(content.charCodeAt(content.length - 4))
console.log(content.charCodeAt(content.length - 3))
console.log(content.charCodeAt(content.length - 2))
console.log(content.charCodeAt(content.length - 1))
console.log('===================================') All Related Log1. English version: Bot invite others to the group.eg: You invited 管理员 to the group chat. There are 3 blank(charCode is 32) here. Log as follows: 19:11:58 VERB PuppetWebFirer checkRoomJoin(You invited 管理员 to the group chat. )
19:11:58 SILL PuppetWebFirer fireRoomJoin() "You invited 管理员 to the group chat. " is not a join message
19:11:58 VERB PuppetWebFirer fireRoomLeave(You invited 管理员 to the group chat. )
19:11:58 SILL Message ready()
19:11:58 SILL Room ready()
19:11:58 SILL Room ready()
19:11:58 VERB Room topic()
[桔小秘,桔小秘,李佳芮]<桔小秘,桔小秘,李佳芮>:{SYS}You invited 管理员 to the group chat.
======console.log the last 4 charCode======
<.>charCode is<46>
< >charCode is<32>
< >charCode is<32>
< >charCode is<32>
=================================== 2. English version: Not bot invite others to the group.eg: 管理员 invited 小桔建群助手 to the group chat There no no blank or punctuation here. Log as follows: 19:41:46 VERB PuppetWebFirer checkRoomJoin(管理员 invited 小桔建群助手 to the group chat)
19:41:46 SILL PuppetWebFirer fireRoomJoin() "管理员 invited 小桔建群助手 to the group chat" is not a join message
19:41:46 VERB PuppetWebFirer fireRoomLeave(管理员 invited 小桔建群助手 to the group chat)
19:41:46 SILL Message ready()
19:41:46 SILL Room ready()
19:41:46 SILL Room ready()
19:41:46 VERB Room topic()
[桔小秘,桔小秘,李佳芮]<桔小秘,桔小秘,李佳芮>:{SYS}管理员 invited 小桔建群助手 to the group chat
======console.log the last 4 charCode======
<c>charCode is<99>
<h>charCode is<104>
<a>charCode is<97>
<t>charCode is<116>
=================================== 3. English version: Others join the group by qrcode shared by the bot.eg: "管理员" joined group chat via the QR code you shared. There are 2 blank(charCode is 32) here. Log as follows:
4. English version: Others join the group by qrcode not shared by bot.eg: "宁锐锋" joined the group chat via the QR Code shared by "管理员". There are no blank(charCode is 32) here. Log as follows: 19:18:37 SILL Room ready()
19:18:37 VERB Room topic()
[桔小秘,桔小秘,李佳芮]<桔小秘,桔小秘,李佳芮>:{SYS}"宁锐锋" joined the group chat via the QR Code shared by "管理员".
======console.log the last 4 charCode======
<管>charCode is<29702>
<员>charCode is<21592>
<">charCode is<34>
<.>charCode is<46>
=================================== 5. Chinese version: Bot invite others to the group.eg: 你邀请"管理员"加入了群聊 There are 2 blank(charCode is 32) here. Log as follows:
6. Chinese version: Not bot invite others to the group.eg: "管理员"邀请"宁锐锋"加入了群聊 There no no blank or punctuation here. Log as follows: 19:50:47 VERB PuppetWebFirer checkRoomJoin("管理员"邀请"宁锐锋"加入了群聊)
19:50:47 SILL PuppetWebFirer fireRoomJoin() ""管理员"邀请"宁锐锋"加入了群聊" is not a join message
19:50:47 VERB PuppetWebFirer fireRoomLeave("管理员"邀请"宁锐锋"加入了群聊)
19:50:47 SILL Message ready()
19:50:47 SILL Room ready()
19:50:47 SILL Room ready()
19:50:47 VERB Room topic()
[神奇群]<神奇群>:{SYS}"管理员"邀请"宁锐锋"加入了群聊
======console.log the last 4 charCode======
<入>charCode is<20837>
<了>charCode is<20102>
<群>charCode is<32676>
<聊>charCode is<32842>
=================================== 7. Chinese version: Others join the group by qrcode not shared by bot.eg: "管理员"通过扫描你分享的二维码加入群聊 There are 2 blank(charCode is 32) here. Log as follows:
8. Chinese version: Others join the group by qrcode not shared by bot.eg: " 苏轼"通过扫描"管理员"分享的二维码加入群聊 There are 1 blank(charCode is 32) here, in a very strange position. Log as follows:
|
And, we should think more about the frequency system log changing.... log all of this is really a lot of dirty hard work but is important..... |
It seems strange for me, I run the unit test at my mac(
|
Good job! Could you please replace all the spaces inside the RegExp by |
I didn't replace all spaces, I think we should just replace strange spaces to |
src/puppet-web/firer.ts
Outdated
@@ -54,13 +54,13 @@ const regexConfig = { | |||
|
|||
roomJoinInvite: [ | |||
// There are 3 blank(charCode is 32) here. eg: You invited 管理员 to the group chat. | |||
/^(.+?) invited (.+) to the group chat. $/, | |||
/^(.+?) invited (.+) to the group chat.\s+\s+\s+$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure you understand what you are doing before you change anything... :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{3}
(a space at the beginning) or \s{3}
should work if you want to match exactly three spaces :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hczhcz thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One \s+
is enough.
src/puppet-web/firer.ts
Outdated
@@ -54,13 +54,13 @@ const regexConfig = { | |||
|
|||
roomJoinInvite: [ | |||
// There are 3 blank(charCode is 32) here. eg: You invited 管理员 to the group chat. | |||
/^(.+?) invited (.+) to the group chat.\s+\s+\s+$/, | |||
/^(.+?) invited (.+) to the group chat.\s{3}$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-\s{3}
+\s+
Consider more, if we need strict regExp, we should also collect all room system message which cannot be recognized. So I change the following function return type: async function checkRoomJoin(m: Message): Promise<void>
async function checkRoomLeave(m: Message): Promise<void>
async function checkRoomTopic(m: Message): Promise<void> to async function checkRoomJoin(m: Message): Promise<boolean>
async function checkRoomLeave(m: Message): Promise<boolean>
async function checkRoomTopic(m: Message): Promise<boolean> And throw an error when the system message cannot be recognized. Then we can monitor these exceptions more. const joinResult = await Firer.checkRoomJoin.call(this , m)
const leaveResult = await Firer.checkRoomLeave.call(this , m)
const topicRestul = await Firer.checkRoomTopic.call(this , m)
if (!joinResult && !leaveResult && !topicRestul) {
throw new Error(`PuppetWebEvent, checkRoomSystem message: <${m.content()}> not found`)
} |
But I'm not that sure, whether throw error is better or log.error() is better... For me, it is really important to monitor room status, but for others, maybe they don't want to see throw error... |
Yes, I believe silence the Error is better because not all users care about there is an unrecognizable message in a room.
|
So I change the pr topic... :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The better practice is to create another PR to do another job, instead of adding more and more unrelated modifications into one topic.
src/puppet-web/event.ts
Outdated
const topicRestul = await Firer.checkRoomTopic.call(this , m) | ||
|
||
if (!joinResult && !leaveResult && !topicRestul) { | ||
log.error('PuppetWebEvent', `checkRoomSystem message: <${m.content()}> not found`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not an error
but a warning
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please forgive for my lazy and using one pr.... and I will do a better practice next time. thanks...
But I think here using a silence error is better than a warning, because this is a system error, for the error regExp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be an error
but a warning
at here.
Please get one more approvement from any of the contributors before I could be able to merge this PR. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good!
For the log.error/log.warning, this message indicates that WeChat's behavior changes and the user have to update the library for new regex rules. It would be good to make similar error messages consist.
@hczhcz thanks :) |
Sometimes, when a person joins in the room by the qrcode shared by bot's, the sentence as follows:
So, I change this to make this more compatibility.