forked from kcred31/Meowth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.py
75 lines (65 loc) · 2.09 KB
/
launcher.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
import sys
import os
import time
import subprocess
import argparse
#Launcher for Meowthv2
def parse_cli_args():
parser = argparse.ArgumentParser(
description="Meowth Launcher - Pokemon Go Bot for Discord")
parser.add_argument(
"--auto-restart", "-r",
help="Auto-Restarts Meowth in case of a crash.", action="store_true")
parser.add_argument(
"--debug", "-d",
help=("Prevents output being sent to Discord DM, "
"as restarting could occur often."),
action="store_true")
return parser.parse_args()
def run_meowth(autorestart):
interpreter = sys.executable
if interpreter is None:
raise RuntimeError("Python could not be found")
cmd = [interpreter, "-m", "meowth", "launcher"]
retries = 0
while True:
if args.debug:
cmd.append("debug")
try:
code = subprocess.call(cmd)
except KeyboardInterrupt:
code = 0
break
else:
if code == 0:
break
elif code == 26:
#standard restart
retries = 0
print("")
print("Restarting Meowth")
print("")
continue
else:
if not autorestart:
break
retries += 1
wait_time = min([retries^2, 60])
print("")
print("Meowth experienced a crash.")
print("")
for i in range(wait_time, 0, -1):
sys.stdout.write("\r")
sys.stdout.write(
"Restarting Meowth from crash in {:0d}".format(i))
sys.stdout.flush()
time.sleep(1)
print("Meowth has closed. Exit code: {exit_code}".format(exit_code=code))
args = parse_cli_args()
if __name__ == '__main__':
abspath = os.path.abspath(__file__)
dirname = os.path.dirname(abspath)
os.chdir(dirname)
print("Launching Meowth...")
run_meowth(autorestart=args.auto_restart)