From fa85461bc880fa1b4c83211071c6e6ceb0a6f063 Mon Sep 17 00:00:00 2001 From: Nico-Mayer Date: Sun, 7 Jul 2024 17:07:54 +0200 Subject: [PATCH 1/2] Bugfix, added GetChampionByKey func, to get around the odd naming of riot data dragon field, this should fix the GetChampion func for spectator. --- datadragon/data_dragon.go | 14 ++++++++++++++ riot/lol/model.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/datadragon/data_dragon.go b/datadragon/data_dragon.go index 64ddccd..415659c 100644 --- a/datadragon/data_dragon.go +++ b/datadragon/data_dragon.go @@ -142,6 +142,20 @@ func (c *Client) GetChampionByID(id string) (ChampionDataExtended, error) { return champion, nil } +// GetChampion returns information about the champion with the given name +func (c *Client) GetChampionByKey(key string) (ChampionDataExtended, error) { + champions, err := c.GetChampions() + if err != nil { + return ChampionDataExtended{}, err + } + for _, champion := range champions { + if champion.Key == key { + return c.GetChampionByID(champion.ID) + } + } + return ChampionDataExtended{}, api.ErrNotFound +} + // GetChampion returns information about the champion with the given name func (c *Client) GetChampion(name string) (ChampionDataExtended, error) { champions, err := c.GetChampions() diff --git a/riot/lol/model.go b/riot/lol/model.go index 47d1783..c8635c4 100644 --- a/riot/lol/model.go +++ b/riot/lol/model.go @@ -608,7 +608,7 @@ type CurrentGameParticipant struct { // GetChampion returns the champion played by this participant func (p *CurrentGameParticipant) GetChampion(client *datadragon.Client) (datadragon.ChampionDataExtended, error) { - return client.GetChampionByID(strconv.Itoa(p.ChampionID)) + return client.GetChampionByKey(strconv.Itoa(p.ChampionID)) } // GetSpell1 returns the first summoner spell of this participant From 7e0e1298c5676bcea6a77e034c8d3aaee1bcd03a Mon Sep 17 00:00:00 2001 From: Nico-Mayer Date: Sun, 7 Jul 2024 17:08:40 +0200 Subject: [PATCH 2/2] comment fix --- datadragon/data_dragon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadragon/data_dragon.go b/datadragon/data_dragon.go index 415659c..7b2c8ec 100644 --- a/datadragon/data_dragon.go +++ b/datadragon/data_dragon.go @@ -142,7 +142,7 @@ func (c *Client) GetChampionByID(id string) (ChampionDataExtended, error) { return champion, nil } -// GetChampion returns information about the champion with the given name +// GetChampion returns information about the champion with the given key func (c *Client) GetChampionByKey(key string) (ChampionDataExtended, error) { champions, err := c.GetChampions() if err != nil {