Skip to content

Conversation

@ssine
Copy link
Contributor

@ssine ssine commented Jun 21, 2020

No description provided.

@CLAassistant
Copy link

CLAassistant commented Jun 21, 2020

CLA assistant check
All committers have signed the CLA.

@huan
Copy link
Member

huan commented Jun 21, 2020

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!

@ssine
Copy link
Contributor Author

ssine commented Jun 21, 2020

Thanks for the reply! the issue is opened, hope we can have more discussion there.

Copy link
Member

@huan huan left a 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 = {
Copy link
Member

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()

Copy link
Member

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)

return new Promise<Message>((resolve, reject) => {

let callback = async (message: Message) => {
let messageFrom = message.from()
Copy link
Member

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 }

@ssine
Copy link
Contributor Author

ssine commented Jun 23, 2020

I have switched to use mathcers for message pattern matching, thanks for your detailed directions!

@huan
Copy link
Member

huan commented Jun 23, 2020

Your updates looks good!

Please resolve the conflicting in the PR before we can merge it, thank you very much!

@ssine
Copy link
Contributor Author

ssine commented Jun 23, 2020

I've merged with newest master brance and fixed the naming, looks good now

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@huan huan merged commit 372ba78 into wechaty:master Jun 23, 2020
@huan
Copy link
Member

huan commented Jun 23, 2020

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:

You've invited sine to Wechaty! They'll be receiving an email shortly. They can also visit https://github.com/wechaty to accept the invitation.

And we have a Wechaty Contributors Group on WeChat, please contact @lijiarui to join us.

Cheers!

@ssine
Copy link
Contributor Author

ssine commented Jun 23, 2020

OK, glad to be one of the contributors, cheers!

@lijiarui
Copy link
Member

Congratulations! 🎉 🎉 🎉

You become a wechaty contributor successfully! 👏 👏 👏

Please:

  • Add my wechat: ruirui_0914 and send me this pr link. I will invite you into Wechaty Contributor Room
  • Update your profile here: Contributor List, then other contributors will know you better!
  • Join wechaty org by clicking https://github.com/wechaty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants