-
Notifications
You must be signed in to change notification settings - Fork 11
Add MessageAwaiter contrib #12
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
Conversation
|
It's great to see your contribution for adding a new plugin! Could you please file an issue to description this plugin in details about what problem is it trying to solve, and why it is a good solution, so that we can review this new feature , refine the design, and finally decide whether to accept it. Looking forward to learn from your post, thanks! |
|
Thanks for the reply! the issue is opened, hope we can have more discussion there. |
huan
left a comment
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.
Thank you very much for the new plugin, it's very valuable.
Please follow my reviews and change your code to use the standard helper functions from the wechaty-plugin-contrib so that we can benefit from the shorter code and a consistent style.
| log, | ||
| } from 'wechaty' | ||
|
|
||
| type MessageAwaiterArgs = { |
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 wechaty-plugin-contrib has standard helper functions/interfaces to deal with those parameters.
Please read the related code and keep this part consistent with other plugins.
+ import * as matchers from '../matcher/mod'
type MessageAwaiterArgs = {
- contactId?: string,
+ contact?: matchers.ContactMatcherOptions,
- roomId?: string,
+ room?: matchers.RoomMatcherOptions,
- regex?: RegExp,
+ text?: matchers.StringMatcherOptions,
timeoutSecond?: number
}| wechaty.waitForMessage = async (args: MessageAwaiterArgs): Promise<Message> => { | ||
| let { contactId, roomId, regex, timeoutSecond } = args | ||
| let waitTime = new Date() | ||
|
|
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.
We can create the matchers helper functions from the options (demonstrated as the following code):
const matchContact = matchers.contactMatcher(args.contact)
const matchRoom = matchers.roomMatcher(args.room)
const matchString = matchers.stringMatcher(args.text)
src/contrib/message-awaiter.ts
Outdated
| return new Promise<Message>((resolve, reject) => { | ||
|
|
||
| let callback = async (message: Message) => { | ||
| let messageFrom = message.from() |
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.
Then we can use the matchers helper functions like this:
if (!matchContact(message.from)) { return }
if (!matchRoom(message.room()) { return }
if (!matchString(message.text()) { return }|
I have switched to use mathcers for message pattern matching, thanks for your detailed directions! |
|
Your updates looks good! Please resolve the conflicting in the PR before we can merge it, thank you very much! |
|
I've merged with newest master brance and fixed the naming, looks good now |
huan
left a comment
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.
LGTM
|
Thank you very much for your contribution! I have invited you to join the Wechaty Contributors team on GitHub, please accept it by following the below message:
And we have a Wechaty Contributors Group on WeChat, please contact @lijiarui to join us. Cheers! |
|
OK, glad to be one of the contributors, cheers! |
|
Congratulations! 🎉 🎉 🎉 You become a wechaty contributor successfully! 👏 👏 👏 Please:
|
No description provided.