stefan2200 / TWB

Python based bot for Tribal Wars
GNU General Public License v3.0
99 stars 54 forks source link

Bans and Captcha #41

Open realstrings opened 1 year ago

realstrings commented 1 year ago

Hey, i have been getting few temp bans using this bot, am using only features that were not marked as ban risk.

Also i have been getting a lot of captchas so i figured why not to use 2captcha its cheap as it gets.

here is some code

            if 'data-bot-protect="forced"' in res.text:
                if not self.captcha_solve:
                    self.logger.warning("Bot protection hit! cannot continue")
                    self.reporter.report(0, "TWB_RECAPTCHA", "Stopping bot, press any key once captcha has been solved")
                    input("Press any key...")
                    return self.get_url(url, headers)
                else:
                    self.logger.warning("Bot protection hit! Trying to solve captcha")
                    solver = TwoCaptcha(self.twocaptcha_key)
                    result = solver.hcaptcha(sitekey='b413369f-bb15-4015-bacd-dd180021827c',url=self.endpoint)
                    xsrf = re.search('"csrf":"(.+?)"', res.text)
                    vill_id = re.search('"village":{"id":(.+?),', res.text)
                    request_data = {"response": result['code'],"h": xsrf.group(1)}
                    response = self.web.post(url=self.endpoint+"game.php?village="+vill_id.group(1)+"&screen=botcheck&ajaxaction=verify",headers=headers,data=request_data)
                    print(response.text)
                    if 'true' in response.text:
                        self.logger.warning("Captcha solved, trying last action again")
                        return self.get_url(url, headers)
                    else:
                        self.reporter.report(0, "TWB_RECAPTCHA", "Captcha failed. Stopping bot, press any key once captcha has been solved")
                        input("Press any key after you solved captcha...")
                        return self.get_url(url, headers)

            return res
        except Exception as e:

i sadly cant create pull request as i dont quite understand few things from config and dont have the time to go tru it.

https://pypi.org/project/2captcha-python/

realstrings commented 1 year ago

Bans come from either farming or being on the same session for too long

Legion-81 commented 7 months ago

hmm never had any problems yet with captcha ever using cookie