Skip to content

Commit

Permalink
Invite friends from group
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Feb 3, 2024
1 parent 1e41509 commit f584322
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
9 changes: 6 additions & 3 deletions sightstone/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def init_gui(sightstone_hook: Sightstone):
dpg.add_button(
label="Delete Lobby", callback=sightstone_hook.delete_lobby)
dpg.add_button(
label="Reveal Lobby",
label="Lobby Reveal",
indent=INDENT_BUTTONS_GROUP_4,
callback=lambda:sightstone_hook.search_lobby(dpg.get_value("revealWebsite")))
dpg.add_combo(tag="revealWebsite", width=139, items=sightstone_hook.AVAILABLE_WEBSITES, default_value=sightstone_hook.AVAILABLE_WEBSITES[0])
Expand All @@ -94,6 +94,11 @@ def init_gui(sightstone_hook: Sightstone):

with dpg.group(horizontal=True):
dpg.add_checkbox(label="Auto Accept", callback=sightstone_hook.toggle_accept_listener)
dpg.add_button(
label="Invite from group",
indent=INDENT_BUTTONS_GROUP_4,
callback=lambda:sightstone_hook.invite_friends_from_group(dpg.get_value("friendGroups")))
dpg.add_combo(tag="friendGroups", width=104)

dpg.add_separator()
with dpg.group(horizontal=True):
Expand Down Expand Up @@ -243,8 +248,6 @@ def init_gui(sightstone_hook: Sightstone):
query=sightstone_hook.transform_participants_into_query(set(["lipe#69420", "MISSING KERIA ON#000", "naive#444", "wolfs child#EUW"]))))
dpg.add_button(label="get group",
callback=sightstone_hook.get_groups)
dpg.add_combo(tag="friendGroups")
dpg.add_tooltip("friendGroups",label="ola")

dpg.add_button(label="QUEUE", callback=sightstone_hook.get_queues)
dpg.add_button(label="muselfg", callback=lambda:sightstone_hook.search_myself(SC.OP_GG))
Expand Down
2 changes: 1 addition & 1 deletion sightstone/lca_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def riot_get(self, path: str) -> Response | None:
except Exception as e:
print(f"ERROR IN RIOT_GET: {e}")

def post(self, path: str, data: dict | None = None, json: dict | None = None) -> Response | None:
def post(self, path: str, data: dict | None = None, json: dict | list[dict] | None = None) -> Response | None:
"""Post into LCA"""
if not self.connected:
return None
Expand Down
29 changes: 28 additions & 1 deletion sightstone/sightstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def get_queues(self) -> list[dict]:
return response.json()
return list()

def get_friends(self) -> dict:
"""Get friends"""
response = self.lca_hook.get(path="lol-chat/v1/friends")

if response:
return response.json()
return dict()

def get_groups(self) -> list[dict]:
"""Get's all friend's group"""
response = self.lca_hook.get(path="lol-chat/v1/friend-groups/")
Expand Down Expand Up @@ -84,6 +92,25 @@ def dodge_lobby(self) -> bool:

return self.is_valid_response(response)

def invite_to_lobby(self, summoner_id: str) -> bool:
"""Invite to lobby a summoner id"""
# Have to use a custom POST request because this endpoint only accepts vectors
response = self.lca_hook.post(
"lol-lobby/v2/lobby/invitations/",
json=[{"toSummonerId": summoner_id}])

return self.is_valid_response(response)

def invite_friends_from_group(self, group: str) -> None:
"""Invite all friends from specific group"""
friends = self.get_friends()
if len(friends) == 0:
return

for friend in friends:
if friend["groupName"] == group:
self.invite_to_lobby(friend["summonerId"])

def toggle_accept_listener(self):
"""Toggles the auto accept thread"""
# Start thread if first time
Expand Down Expand Up @@ -236,7 +263,7 @@ def custom_game_json(self, game_mode: str, team_size: int, map_code: int) -> dic

def is_valid_response(self, response: requests.Response | None) -> bool:
"""Checks if the response is valid"""
return not (response is None or response.status_code in (204, 500))
return not (response is None or response.status_code in (204, 400, 401, 402, 500))

def __str__(self) -> str:
all_callable_funcs = [x for x in dir(self) if callable(getattr(self, x)) and not x.startswith("__")]
Expand Down

0 comments on commit f584322

Please sign in to comment.