-
Notifications
You must be signed in to change notification settings - Fork 0
/
league.py
90 lines (79 loc) · 3 KB
/
league.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
import time
import logging
from lcu_driver.connection import Connection
import threading
from utils import MyConnector, my_exit, get_skin_name
import random
import easygui
logger = logging.getLogger("lol-autolockin")
connector = MyConnector()
choose_new = False
menu_item = None
icon = None
def randomize():
global choose_new
if menu_item.text == "Randomize":
choose_new = True
def set_items(item, menu):
global menu_item, icon
menu_item = item
icon = menu
def start(icon):
icon.visible = True
t = threading.Thread(target=connector.start)
t.start()
@connector.ready
async def connect(connection: Connection):
global choose_new
print("Connected to LCU API")
while True:
try:
req_type = "/lol-champ-select/v1/session"
req = await connection.request("get", req_type)
data = await req.json()
if "errorCode" in data:
menu_item._text = menu_item._wrap("Not in champ select")
menu_item._enabled = menu_item._wrap(False)
icon.update_menu()
time.sleep(5)
continue
req_type = "/lol-champ-select/v1/skin-selector-info"
req = await connection.request("get", req_type)
data = await req.json()
if data["selectedChampionId"] == 0:
menu_item._text = menu_item._wrap("No champ selected")
menu_item._enabled = menu_item._wrap(False)
icon.update_menu()
time.sleep(2)
continue
champ_id = data["selectedChampionId"]
menu_item._text = menu_item._wrap("Randomize")
menu_item._enabled = menu_item._wrap(True)
icon.update_menu()
if choose_new:
choose_new = False
list_skins = []
skin_names = []
req_type = "/lol-champ-select/v1/skin-carousel-skins"
req = await connection.request("get", req_type)
data = await req.json()
for skin in data:
if skin["unlocked"] and not skin["disabled"]:
list_skins.append(skin["id"])
skin_names.append(skin["name"])
selected = random.choice(list_skins)
pos = list_skins.index(selected)
req_type = "/lol-champ-select/v1/session/my-selection"
req_data = {"selectedSkinId": selected}
req = await connection.request("patch", req_type, data=req_data)
data = await req.json()
print("Available", list_skins, skin_names, "Chosen", selected)
easygui.msgbox("Skin selected: " get_skin_name(selected, skin_names, list_skins, champ_id),
"LoL random skin selector")
time.sleep(1)
except Exception as e:
print(e)
my_exit(icon)
@connector.close
async def disconnect(_):
print("Disconnected from League, exiting...")