From 8a40f105e35b763838c6912f294a57446f12ff90 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 14 Aug 2023 15:34:02 +0200 Subject: [PATCH] [core] Fix: Clean usernames when querying user information Signed-off-by: Knut Ahlers --- pkg/twitch/users.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/twitch/users.go b/pkg/twitch/users.go index 0544469..91f44bf 100644 --- a/pkg/twitch/users.go +++ b/pkg/twitch/users.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" "github.com/pkg/errors" @@ -45,6 +46,8 @@ func (c *Client) GetAuthorizedUser() (userID string, userName string, err error) } func (c *Client) GetDisplayNameForUser(username string) (string, error) { + username = strings.TrimLeft(username, "#@") + cacheKey := []string{"displayNameForUsername", username} if d := c.apiCache.Get(cacheKey); d != nil { return d.(string), nil @@ -124,6 +127,8 @@ func (c *Client) GetFollowDate(from, to string) (time.Time, error) { } func (c *Client) GetIDForUsername(username string) (string, error) { + username = strings.TrimLeft(username, "#@") + cacheKey := []string{"idForUsername", username} if d := c.apiCache.Get(cacheKey); d != nil { return d.(string), nil @@ -155,6 +160,8 @@ func (c *Client) GetIDForUsername(username string) (string, error) { } func (c *Client) GetUserInformation(user string) (*User, error) { + user = strings.TrimLeft(user, "#@") + var ( out User param = "login"