forked from jfd02/TFT-OCR-BOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_queue.py
129 lines (108 loc) · 4.14 KB
/
auto_queue.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""
Handles getting into a game
"""
from time import sleep
import json
from requests.auth import HTTPBasicAuth
import requests
import urllib3
import settings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def create_lobby(client_info: tuple) -> bool:
"""Creates a lobby"""
payload: dict[str, int] = {"queueId": 1090} # Ranked TFT is 1100
payload: dict[str, int] = json.dumps(payload)
try:
status = requests.post(client_info[1] + "/lol-lobby/v2/lobby/", payload,
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
if status.status_code == 200:
print(" Creating lobby")
return True
return False
except ConnectionError:
return False
def start_queue(client_info: tuple) -> bool:
"""Starts queue"""
try:
status = requests.post(client_info[1] + "/lol-lobby/v2/lobby/matchmaking/search",
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
if status.status_code == 204:
print(" Starting queue")
return True
return False
except ConnectionError:
return False
def check_queue(client_info: tuple) -> bool:
"""Checks queue to see if we are searching"""
try:
status = requests.get(client_info[1] + "/lol-lobby/v2/lobby/matchmaking/search-state",
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
return status.json()['searchState'] == 'Searching'
except ConnectionError:
return False
def check_game_status(client_info: tuple) -> bool:
"""Checks to see if we are in a game"""
try:
status = requests.get(client_info[1] + "/lol-gameflow/v1/session",
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
return status.json()["phase"] == "InProgress"
except ConnectionError:
return False
def accept_queue(client_info: tuple) -> bool:
"""Accepts the queue"""
requests.post(client_info[1] + "/lol-matchmaking/v1/ready-check/accept",
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
def change_arena_skin(client_info: tuple) -> bool:
"""Changes arena skin to default, other arena skins have different coordinates"""
try:
status = requests.delete(client_info[1] + "/lol-cosmetics/v1/selection/tft-map-skin",
auth=HTTPBasicAuth('riot', client_info[0]), timeout=10, verify=False)
if status.status_code == 204:
print(" Changed arena skin to default")
return True
return False
except ConnectionError:
return False
def get_client() -> tuple:
"""Gets data about the client such as port and auth token"""
print("\n\n[Auto Queue]")
file_path = settings.LEAGUE_CLIENT_PATH + "\\lockfile"
got_lock_file = False
while not got_lock_file:
try:
with open(file_path, "r", encoding="utf-8") as data:
data: list[str] = data.read().split(':')
app_port: str = data[2]
remoting_auth_token: str = data[3]
server_url: str = f"https://127.0.0.1:{app_port}"
got_lock_file = True
except IOError:
print(" Client not open! Trying again in 10 seconds.")
sleep(10)
print(" Client found")
return (remoting_auth_token, server_url)
def queue() -> None:
"""Function that handles getting into a game"""
client_info: tuple = get_client()
while not create_lobby(client_info):
sleep(3)
change_arena_skin(client_info)
sleep(3)
while not check_queue(client_info):
sleep(5)
create_lobby(client_info)
sleep(3)
start_queue(client_info)
sleep(1)
in_queue = True
time = 0
while in_queue:
if time % 60 == 0:
create_lobby(client_info)
sleep(5)
start_queue(client_info)
accept_queue(client_info)
if check_game_status(client_info):
in_queue = False
sleep(1)
time += 1