hldh214 / lok_bot

Yet another League of Kingdoms farming bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Persistancy against errors

mikhi-nde opened this issue · comments

Hi all.
thank you dev-team of this app. it is a good base and well written code.

i want you to know that i implemented on local

  1. a nodes/mines gathering feature. that start a watch tower search, wait the report mail and then go the field for gathering
  2. a troops training feature. that try to train highest(tier) available infantry troop. with a limit.

i will make a pull request after tests. if you want.

////////////////////////

i want also to know if the base code, your code is persistent to errors like the "network errors", "not online error" and any OtherException?

Thanks again.

лучше реализуй бота, который будет делать поиск монстров по заданным координатам. это очень полезно будет. и так же авто охоту на мобов каких я укажу. ну и так же по ресурсам как ты и написал.

a nodes/mines gathering feature.

I'm also working on the feature😄, rather than the watch tower search, I have an idea to traverse through all coordinate on the continent and then filter out everything we want(mine/goblin/...), what do you guys thinking?

a troops training feature.

It will be a nice to have feature, but in my opinion, I would make it optional, since not everyone need troops while farming.

i want also to know if the base code, your code is persistent to errors like the "network errors", "not online error" and any OtherException?

Actually I don't quite understand what you mean, basically all Exception defined in exceptions.py were catched in client.py, and it's just to make the code more readable.

I'm also working on the feature😄, rather than the watch tower search, I have an idea to traverse through all coordinate on the continent and then filter out everything we want(mine/goblin/...), what do you guys thinking?

Yes. i may be good because you will have an overview of the map and you will be able to filter and choose what you want.
however, i don't how you will traverse through all coordinate, but i think it will be like a brute force, right?
if so, it may be easily detected as bot. right?
how do you go through all coordinate?

It will be a nice to have feature, but in my opinion, I would make it optional, since not everyone need troops while farming.

ok. you're right. may be i will expose an argument/option to disable or configure these features. training, monster slaying, ...

Actually I don't quite understand what you mean, basically all Exception defined in exceptions.py were catched in client.py, and it's just to make the code more readable.

i mean some exceptions may stop a thread or the whole bot.

  1. like one trying to claim a done research failed. and never claimed it again. may be the academy thread stopped???
    DEBUG | lokbot.client:post:73 - {"url": "kingdom/task/claim", "data": {"position": 5}, "elapsed": 0.514274, "res": {"result": false, "err": {"code": "not_online"}}}

  2. and this one was because of network faillure for a few hours (i was out). and the bot stopped.
    httpx.ConnectError: [Errno -2] Name or service not known

Do you know a good way to globally catch exceptions and recover from this kind of failure???

Another request:
The bot does all research, production and battle.
I think it may have a limited research to do. only those that improve resource production and gathering.
What do you think about that?

Thanks again for the great job. :)

but i think it will be like a brute force, right?
if so, it may be easily detected as bot. right?

Yes, it is brute force, but we can have some priority strategy to do brute force.
As we know, the crystal mine only respawn on high-level lands, so we can sort lands by their level first, then calculate the distance between the land and our castle, and choose only nearest lands to search/traverse.

Do you know a good way to globally catch exceptions and recover from this kind of failure???

Those exceptions you mentioned, in my opinion, should not be recovered, but should be thrown, because it cannot be recovered since these exceptions are fatal(how can you recover from a network failure :P).

I think it may have a limited research to do. only those that improve resource production and gathering.

Currently all research code are defined here:

RESEARCH_CODE_MAP = {

And if you want to skip some category(for example: battle), you can modify code here, make a little if-condition to skip when the category_name is the one you don't like.

lok_bot/lokbot/farmer.py

Lines 462 to 464 in 3a064ba

for category_name, each_category in RESEARCH_CODE_MAP.items():
logger.info(f'start researching category: {category_name}')
for research_name, research_code in each_category.items():

As we know, the crystal mine only respawn on high-level lands, so we can sort lands by their level first, then calculate the distance between the land and our castle, and choose only nearest lands to search/traverse.

ok. you are right.
may be combining the time of respawn (hourly) and land filtering will reduce the probability of bot detection.

Those exceptions you mentioned, in my opinion, should not be recovered, but should be thrown, because it cannot be recovered since these exceptions are fatal(how can you recover from a network failure :P).

What i think is that a bot should always recover.
Can you think on how to integrate a retry mechanism like in this link?
How to handle a connection error gracefully in requests

And if you want to skip some category(for example: battle), you can modify code here, make a little if-condition to skip when the category_name is the one you don't like.

ok. i just didn't want to touch you code. i wanted to add code/features without touching yours. to reduce conflicts when merging with you future releases.

Best regards.

a bot should always recover.

It's not always true IMHO, maybe the network failure example I made above is not appropriate, instead, we already have this retry mechanism powered by https://github.com/jd/tenacity:

lok_bot/lokbot/client.py

Lines 31 to 36 in 3a064ba

@tenacity.retry(
stop=tenacity.stop_after_attempt(4),
wait=tenacity.wait_random_exponential(multiplier=1, max=60),
retry=tenacity.retry_if_exception_type(httpx.HTTPError), # general http error
reraise=True
)

Let me use another example: NoAuthException, which I thought no way to recover from it, and same for NeedCaptchaException or not_online you mentioned above.

we already have this retry mechanism powered by https://github.com/jd/tenacity

oh yeah. right. i will look at tenacity, where and which params value were used.

Let me use another example: NoAuthException, which I thought no way to recover from it, and same for NeedCaptchaException or not_online you mentioned above.

yes you are right for the NoAuthException. I did not look at the captcha yet.
but i think the not online error is random and relaunch or restart after a few minutes (not seconds) may work. right?

but i think the not online error is random and relaunch or restart after a few minutes (not seconds) may work. right?

In fact, there is an issue #7 discuss about it, currently there is no perfect solution to this issue, so I made this fatal-level exception

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.