Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from Nitamet/lol-14
Browse files Browse the repository at this point in the history
Update app to support the actual LoL version & add skill priority
  • Loading branch information
Nitamet authored Mar 16, 2024
2 parents 5e38e2f + 0e671e9 commit 329cb44
Show file tree
Hide file tree
Showing 27 changed files with 645 additions and 71 deletions.
32 changes: 30 additions & 2 deletions backend/lcu/lcu.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ func (c *Client) CurrentSummoner() Summoner {

var summoner Summoner

resp, _ := c.get("lol-summoner/v1/current-summoner")
resp, err := c.get("lol-summoner/v1/current-summoner")
if err != nil {
log.Panic(err)
}

defer closeBody(resp)

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Panic(err)
Expand All @@ -253,6 +259,8 @@ func (c *Client) IsInLobby() bool {
return false
}

defer closeBody(resp)

return resp.StatusCode == 200
}

Expand All @@ -263,6 +271,8 @@ func (c *Client) GetCurrentGameMode() (string, string) {
return gameModeNone, gameModeNone
}

defer closeBody(resp)

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Panic(err)
Expand Down Expand Up @@ -294,6 +304,8 @@ func (c *Client) GetCurrentChampion() (int, bool) {
log.Panic(err)
}

defer closeBody(resp)

if resp.StatusCode != 200 {
return -1, false
}
Expand All @@ -317,11 +329,12 @@ func (c *Client) GetAssignedRole() (string, bool) {
log.Println("Getting assigned role")

resp, err := c.get("lol-lobby-team-builder/champ-select/v1/session")

if err != nil {
log.Panic(err)
}

defer closeBody(resp)

if resp.StatusCode != 200 {
log.Println("Can't get assigned role, got status code " + strconv.Itoa(resp.StatusCode))

Expand Down Expand Up @@ -387,6 +400,8 @@ func (c *Client) ApplySummonerSpells(firstSpellId int, secondSpellId int) {
log.Panic(err)
}

defer closeBody(resp)

if resp.StatusCode != 204 {
log.Panicf("Error while applying summoner spells, got status code %d", resp.StatusCode)
}
Expand Down Expand Up @@ -438,6 +453,8 @@ func (c *Client) ApplyItemSet(itemSet ItemSet) {
log.Panic()
}

defer closeBody(resp)

if resp.StatusCode != 201 {
log.Panicf("Error while applying item set, got status code %d", resp.StatusCode)
}
Expand Down Expand Up @@ -465,6 +482,8 @@ func (c *Client) ApplyRunes(runes RunePage) {
log.Panic(err)
}

defer closeBody(resp)

if resp.StatusCode != 200 {
log.Panicf("Error while applying runes, got status code %d", resp.StatusCode)
}
Expand Down Expand Up @@ -497,9 +516,18 @@ func (c *Client) deleteCurrentRunePage() {
log.Panic(err)
}

defer closeBody(resp)

if resp.StatusCode != 204 {
log.Printf("Error while deleting current rune page, got status code %d", resp.StatusCode)
}

log.Println("Deleted current rune page")
}

func closeBody(resp *http.Response) {
err := resp.Body.Close()
if err != nil {
log.Panic(err)
}
}
Loading

0 comments on commit 329cb44

Please sign in to comment.