yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.3k stars 1.5k forks source link

Changed example commands regex #1006

Open seadog007 opened 1 year ago

seadog007 commented 1 year ago

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

截圖 2022-09-15 上午1 19 42

References

Nope

kamikazechaser commented 1 year ago

You probably also want to add the regex terminator to some of these examples i.e. $

seadog007 commented 1 year ago

@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?

kamikazechaser commented 1 year ago

/command@botname

This is usually in groups. Yeah I think you should add it for uniformity.

danielperez9430 commented 1 year ago

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

seadog007 commented 1 year ago

@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(?:@.*?)?( .*|$) ?

kamikazechaser commented 1 year ago

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.