11import asyncio
22from random import randint
33
4+ import __init__ # For IDLE
45from Basic .fly import fly
56from Help_functions .bot_functions import fighting , get_battle_id , location , random_sleep
67from login import double_click , get_content
@@ -13,41 +14,38 @@ async def auto_fight(server, battle_id="", side="attacker", wep="0", food="", gi
1314 for _ in range (int (restores )):
1415 restores_left -= 1
1516 try :
16- try :
17- int (battle_id ) # user gave valid id
18- except :
19- battle_id = await get_battle_id (server , battle_id ,first_run = True )
17+ if not battle_id .isdigit ():
18+ battle_id = await get_battle_id (server , battle_id )
2019 print (f'{ URL } battle.html?id={ battle_id } side: { side } ' )
21- if battle_id :
22- tree = await get_content (URL , login_first = True )
23- check = tree .xpath ('//*[@id="taskButtonWork"]//@href' ) # checking if you can work
24- A = randint (1 , 4 )
25- if check and A == 2 : # Don't work as soon as you can (suspicious)
26- current_loc = await location (server )
27- await double_click (server )
28- await fly (server , current_loc )
29- apiBattles = await get_content (f"{ URL } apiBattles.html?battleId={ battle_id } " )
30- if 8 in (apiBattles ['attackerScore' ], apiBattles ['defenderScore' ]):
31- print ("Battle has finished, i will search for another one" )
32- battle_id = await get_battle_id (server , battle_id )
33-
34- tree = await get_content (f'{ URL } battle.html?id={ battle_id } ' )
35- fight_ability = tree .xpath ("//*[@id='newFightView']//div[3]//div[3]//div//text()[1]" )
36- if any ("You can't fight in this battle from your current location." in s for s in fight_ability ):
37- print ("You can't fight in this battle from your current location." )
38- return
39- await fighting (server , battle_id , side , wep )
40- if food :
41- await get_content (f"{ URL } eat.html" , data = {'quality' : food })
42- if gift :
43- await get_content (f"{ URL } gift.html" , data = {'quality' : gift })
44- if food or gift :
45- await fighting (server , battle_id , side , wep )
46- await random_sleep (restores_left )
47-
48- else :
20+ if not battle_id :
4921 print ("Can't fight in any battle. i will check again after the next restore" )
5022 await random_sleep (restores_left )
23+ continue
24+ tree = await get_content (URL , login_first = True )
25+ check = tree .xpath ('//*[@id="taskButtonWork"]//@href' ) # checking if you can work
26+ A = randint (1 , 4 )
27+ if check and A == 2 : # Don't work as soon as you can (suspicious)
28+ current_loc = await location (server )
29+ await double_click (server )
30+ await fly (server , current_loc )
31+ apiBattles = await get_content (f"{ URL } apiBattles.html?battleId={ battle_id } " )
32+ if 8 in (apiBattles ['attackerScore' ], apiBattles ['defenderScore' ]):
33+ print ("Battle has finished, i will search for another one" )
34+ battle_id = await get_battle_id (server , battle_id )
35+
36+ tree = await get_content (f'{ URL } battle.html?id={ battle_id } ' )
37+ fight_ability = tree .xpath ("//*[@id='newFightView']//div[3]//div[3]//div//text()[1]" )
38+ if any ("You can't fight in this battle from your current location." in s for s in fight_ability ):
39+ print ("You can't fight in this battle from your current location." )
40+ return
41+ await fighting (server , battle_id , side , wep )
42+ if food :
43+ await get_content (f"{ URL } eat.html" , data = {'quality' : food })
44+ if gift :
45+ await get_content (f"{ URL } gift.html" , data = {'quality' : gift })
46+ if food or gift :
47+ await fighting (server , battle_id , side , wep )
48+ await random_sleep (restores_left )
5149
5250 except Exception as error :
5351 print ("error:" , error )
0 commit comments