Adding captcha to my onion address

Need to block bots from accessing my onion address.
How to add captcha to Tor?
I’m willing to code it myself in c++ so just tell me which file in the tor source code I should play with to find out some clue about how to do it.

Please refer to the Onion Services DoS guidelines.
From the above article:

It is possible to implement Captchas directly at your webserver with Nginx and OpenResty using Lua to generate and verify the captcha images. This implementation isn’t easy to configure.

Captchas are to be implemented on the front-end of your onion service and you don’t really need to modify Tor.