Skip to content

Commit

Permalink
Get player info
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Feb 8, 2024
1 parent 24ca0a3 commit 908183e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 14 additions & 1 deletion sightstone/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import string
import random
import json
from threading import Thread
import dearpygui.dearpygui as dpg
from sightstone.background_thread import BackgroundThread
Expand Down Expand Up @@ -359,7 +360,19 @@ def init_gui(sightstone_hook: Sightstone):
pass

with dpg.tab(label="Info"):
pass
dpg.add_text("Player Name(name#tag):")
block_width = WIDTH - (WIDTH // 5)
with dpg.group(horizontal=True):
def __search_helper(name: str):
if name.find("#") == -1:
return name + "#" + sightstone_hook.lca_hook.region
else:
return name
dpg.add_input_text(tag="infoSearch", width=block_width)
dpg.add_button(label="Submit", callback=lambda:dpg.set_value("infoOutput", json.dumps(sightstone_hook.get_player_info(__search_helper(dpg.get_value("infoSearch"))), indent=2)))
with dpg.group(horizontal=True):
dpg.add_input_text(tag="infoOutput", multiline=True, width=block_width, height=HEIGHT - (HEIGHT // 3), enabled=False)
dpg.add_button(label="Myself", callback=lambda:dpg.set_value("infoOutput", json.dumps(sightstone_hook.get_player_info(__search_helper(str(sightstone_hook.get_current_user()))), indent=2)))

with dpg.tab(label="Champs"):
pass
Expand Down
12 changes: 11 additions & 1 deletion sightstone/sightstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,22 @@ def get_current_patch(self) -> str:

def get_current_user(self) -> str | None:
"""Get current client user"""
response = self.lca_hook.get(path="lol-summoner/v1/current-summoner/",)
response = self.lca_hook.get(path="lol-summoner/v1/current-summoner/")

if response and self.is_valid_response(response):
return response.json()["gameName"] + "#" + response.json()["tagLine"]
return None

def get_player_info(self, name: str) -> dict:
"""Gets player info, given a name"""
response = self.lca_hook.get(
path=f"lol-summoner/v1/summoners?name={name.replace('#', self.URI_HASHTAG)}"
)

if response != None:
return response.json()
return dict()

def start_queue(self) -> bool:
"""Start queue"""
response = self.lca_hook.post(path="lol-lobby/v2/lobby/matchmaking/search/")
Expand Down

0 comments on commit 908183e

Please sign in to comment.