node-telegram-bot-api
node-telegram-bot-api copied to clipboard
Changed example commands regex
- [ ] All tests pass (Didn't run it since I am not change the lib source)
- [x] I have run
npm run doc
Description
Changed the examples and README.md since lots of people wrote codes with copying the example, which might cause the bot to match URL or other things.
Generally, the only thing that should consider as a command is a string start with special character (in this case "/") Therefore, the following should be considering as a command
/echo 123
/help
but not these
I found a file under /bin, which is /bin/echo What is is file for in Linux?
http://help.google.com/
Using the original example will resulting as
References
Nope
You probably also want to add the regex terminator to some of these examples i.e. $
@kamikazechaser I did consider that, but since there might be something like /command@botname
, and regex will be ^\/command(@.*|$)
.
I don't think complexing the example is a good idea then.
Therefore, I was not adding that to the PR, or should I?
/command@botname
This is usually in groups. Yeah I think you should add it for uniformity.
This regex is still wrong, becuase @.* is any character include espace and other text that not match.
/test@mytest_bot
and /test@mytest_bot hello test
is match.
This weekend I will review it
@danielperez9430
Well, I will simply ignore the argument for the commands that doesn't require args.
but for something like /echo
, I did use ^\/echo(?:@.*?)? (.+)
, or you prefer ^\/echo(?:@.*?)?( .*|$)
?
Yeah I think you should add it for uniformity.
Btw I meant the regex terminator here, not adding @botname
to the regex. Otherwise the PR is okay after that change.