55import requests
66import keyboard # Import the keyboard module
77from src import mirror
8- from src .core import reconnect , md_setup
9- from src .common import error_screenshot , match_image
8+ from src .core import pre_md_setup , reconnect
9+ from src .common import error_screenshot , element_exist
1010
1111connection_event = threading .Event ()
12+
13+ with open ("config/status_selection.txt" , "r" ) as f :
14+ status = [i .strip ().lower () for i in f .readlines ()]
1215
1316def update ():
1417 r = requests .get ("https://api.github.com/repos/Samsterr/SirSquirrelAssistant/releases/latest" )
15- tag = "1.0.5.0"
18+ tag = "1.0.5.0.2 "
1619 r_tag = r .json ()["tag_name" ]
1720 if r_tag != tag :
1821 print ("A New Version is Available! Downloading it to your current folder" )
@@ -27,42 +30,52 @@ def exit_program():
2730 os ._exit (0 )
2831
2932# Start a background thread to listen for 'Ctrl+Q'
30- def exit_listener ():
33+ def start_exit_listener ():
3134 keyboard .add_hotkey ('ctrl+q' , exit_program ) # Register hotkey Ctrl+Q to exit
3235 # Keep the listener active without blocking the main thread
3336 while True :
3437 keyboard .wait ('ctrl+q' ) # Block until Ctrl+Q is pressed
3538
3639def connection_listener ():
40+ reconnect ()
41+
42+ def connection_check ():
3743 while True :
38- if match_image ( "pictures/general/connection.png" ):
44+ while ( element_exist ( "pictures/general/connection.png" ) ):
3945 connection_event .clear ()
4046 connection_event .set ()
4147
42- def mirror_dungeon (run_count , logger ):
43- with open ("config/status_selection.txt" , "r" ) as f :
44- status = [i .strip ().lower () for i in f .readlines ()]
48+ def mirror_dungeon_run (num_runs , logger ):
4549 try :
46- num_runs = 0
47- status_list = (status * ((run_count // len (status )) + 1 ))[:run_count ]
48- logger .info ("Starting" )
49- for i in range (run_count ):
50- logger .info ("Run {}" .format (num_runs + 1 ))
50+ run_count = 0
51+ win_count = 0
52+ lose_count = 0
53+ status_list = (status * ((num_runs // len (status )) + 1 ))[:num_runs ]
54+ logger .info ("Starting Run" )
55+ for i in range (num_runs ):
56+ logger .info ("Run {}" .format (run_count + 1 ))
57+ pre_md_setup ()
5158 logger .info ("Current Team: " + status_list [i ])
52- run_complete = False
53- md_setup ()
59+ run_complete = 0
5460 MD = mirror .Mirror (status_list [i ])
55- MD .setup ()
56- while (not run_complete ):
61+ MD .setup_mirror ()
62+ while (run_complete != 1 ):
5763 if connection_event .is_set ():
58- run_complete = MD .mirror_loop ()
59- if match_image ("pictures/general/server_error.png" ):
64+ win_flag , run_complete = MD .mirror_loop ()
65+ if element_exist ("pictures/general/server_error.png" ):
6066 connection_event .clear ()
6167 logger .debug ("Disconnected, Pausing" )
62- reconnect ()
68+ connection_listener_thread = threading .Thread (target = connection_listener )
69+ connection_listener_thread .start ()
70+ connection_listener_thread .join ()
6371 logger .debug ("Reconnected, Resuming" )
64- connection_event .set ()
65- num_runs += 1
72+ connection_event .set ()
73+ if win_flag == 1 :
74+ win_count += 1
75+ else :
76+ lose_count += 1
77+ run_count += 1
78+ logger .info ('Won Runs {}, Lost Runs {}' .format (win_count , lose_count ))
6679 except Exception as e :
6780 error_screenshot ()
6881 logger .exception (e )
@@ -82,13 +95,13 @@ def main():
8295 args = parser .parse_args ()
8396
8497 connection_event .set ()
85- exit_listener_thread = threading .Thread (target = exit_listener , daemon = True )
98+ exit_listener_thread = threading .Thread (target = start_exit_listener , daemon = True )
8699 exit_listener_thread .start ()
87100
88- connection_thread = threading .Thread (target = connection_listener , daemon = True )
101+ connection_thread = threading .Thread (target = connection_check )
89102 connection_thread .start ()
90103
91- mirror_dungeon (args .RunCount , logger )
104+ mirror_dungeon_run (args .RunCount , logger )
92105
93106if __name__ == "__main__" :
94107 main ()
0 commit comments