node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

Changed example commands regex

Open seadog007 opened this issue 1 year ago • 6 comments

  • [ ] 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 截圖 2022-09-15 上午1 19 42

References

Nope

seadog007 avatar Sep 14 '22 17:09 seadog007

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

kamikazechaser avatar Sep 14 '22 19:09 kamikazechaser

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

seadog007 avatar Sep 14 '22 19:09 seadog007

/command@botname

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

kamikazechaser avatar Sep 14 '22 19:09 kamikazechaser

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 avatar Sep 23 '22 09:09 danielperez9430

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

seadog007 avatar Sep 23 '22 09:09 seadog007

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.

kamikazechaser avatar Sep 23 '22 10:09 kamikazechaser