Skip to content
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

Custom parser implementation- draft #38

Closed
wants to merge 5 commits into from
Closed

Custom parser implementation- draft #38

wants to merge 5 commits into from

Conversation

ayjayt
Copy link
Contributor

@ayjayt ayjayt commented Feb 15, 2019

Re Issue #36

This is a little bit harder/more awkward, maybe unreasonable. Definitely looking for feedback. I pretty much needed this so I made it but...

I didn't want to reimplement the commander entirely XD

I am not as confident that this is acceptable but it can't hurt to offer.

@@ -11,6 +11,8 @@ type CommandDefinition struct {
Example string
AuthorizationRequired bool
AuthorizedUsers []string
AuthorizationFunc func(request Request) bool
CustomParser func(text string) (*proper.Properties, bool)
Copy link
Owner

Choose a reason for hiding this comment

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

I am not so sure this should be defined here.

It feels to me like you want to be able to use a different implementation than the github.com/shomali11/commander, but the problem is the way it is defined here https://github.com/shomali11/slacker/blob/master/command.go#L19

Seems to me that the best approach is to allow func NewBotCommand(... to accept one more parameter which happens to be an interface with the same methods of the commander library.

This way you can provide your new implementation as a ClientOption in https://github.com/shomali11/slacker/blob/master/slacker.go#L35

Would there ever be a case where you would need different parsers for different commands? I feel like one would be consistent with whatever parser they use throughout the bot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. The commander parser provides many functions to the slacker library- more than I expected. I was hoping to find a simple way to override the parser in a sane way. I managed to satisfy the need for the application, but the solution isn't elegant and the time-cost of one is too high for me at the moment :-( Your command is a small study for me...

This is what I ended up using, FYI:

issueRegex = regexp.MustCompile(`^\s*(?:<@(\S+)>)?\s*new\s+"([^"\\]*(?:\\.[^"\\]*)*)"\s+"([^"\\]*(?:\\.[^"\\]*)*)"\s+"([^"\\]*(?:\\.[^"\\]*)*)"\s*$`) // to allow quotation-deliminated arguments
escapeRegex = regexp.MustCompile(`\\(.)`) // to find and remove escaped characters

Copy link
Owner

Choose a reason for hiding this comment

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

If I understand correctly, you want the regex to support matching sentences within quotations?

If that is the case, we might focus on improving https://github.com/shomali11/commander/blob/master/commander.go#L14

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revisit this over the next week or two, likely

@shomali11
Copy link
Owner

I will close this until you revisit it

@shomali11 shomali11 closed this Jun 8, 2019
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.

None yet

2 participants