-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
60 lines (49 loc) · 1.97 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import subprocess
import time
import pyautogui
import datetime
def print_with_timestamp(*args, **kwargs):
current_time = datetime.datetime.now()
timestamp = current_time.strftime('%H:%M:%S %m/%d/%y')
message = f"{timestamp} - {' '.join(map(str, args))}\n"
print(message, end='')
with open('log.txt', 'a') as log_file:
log_file.write(message)
def quit_game(process_name):
try:
subprocess.run(['taskkill', '/im', process_name, '/f'], check=True)
except subprocess.CalledProcessError as e:
print_with_timestamp(f"Failed to terminate {process_name}. Error: {e}")
def launch_steam_game(game_id):
command = f"steam://run/{game_id}"
try:
subprocess.run(["cmd", "/c", "start", command], check=True)
print_with_timestamp("Game is launching...")
time.sleep(5)
click_button("departbutton.png")
except subprocess.CalledProcessError as e:
print_with_timestamp(f"Failed to launch the game. Error: {e}")
def click_button(image_path):
try:
button_location = pyautogui.locateCenterOnScreen(image_path, confidence=0.9)
if button_location is not None:
pyautogui.click(button_location)
print_with_timestamp("Departed ships successfully.")
time.sleep(3)
quit_game("sm_sdl_steam.exe")
print_with_timestamp("Quitting game.")
else:
print_with_timestamp("Your ships are not ready to be departed.")
time.sleep(5)
quit_game("sm_sdl_steam.exe")
print_with_timestamp("Quitting game.")
except pyautogui.ImageNotFoundException:
print_with_timestamp("Could not locate the depart button on screen.")
quit_game("sm_sdl_steam.exe")
print_with_timestamp("Quitting game.")
game_id = "2445660"
delay = int(input("What delay would you like between departure attempts? (Minutes): "))
delay *= 60
while True:
is_game_running = launch_steam_game(game_id)
time.sleep(delay)