From 1953254934f0cf582819a7e965a63c73670a0c81 Mon Sep 17 00:00:00 2001 From: gempir Date: Wed, 11 Mar 2020 18:53:14 +0100 Subject: [PATCH] username regex now catches all exisiting twitch usernames and is no longer case sensitive --- api/logrequest.go | 6 +++--- helix/user.go | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api/logrequest.go b/api/logrequest.go index e94b8c0..3ee2eb2 100644 --- a/api/logrequest.go +++ b/api/logrequest.go @@ -36,7 +36,7 @@ type logTime struct { } var ( - pathRegex = regexp.MustCompile(`\/(channel|channelid)\/([a-zA-Z0-9]+)(?:\/(user|userid)\/([a-zA-Z0-9]+))?(?:(?:\/(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?)|(?:\/(range|random)))?`) + pathRegex = regexp.MustCompile(`\/(channel|channelid)\/(\w+)(?:\/(user|userid)\/(\w+))?(?:(?:\/(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?)|(?:\/(range|random)))?`) ) func (s *Server) newLogRequestFromURL(r *http.Request) (logRequest, error) { @@ -153,10 +153,10 @@ func (s *Server) fillIds(request logRequest) (logRequest, error) { } if request.channelid == "" { - request.channelid = ids[request.channel].ID + request.channelid = ids[strings.ToLower(request.channel)].ID } if request.userid == "" { - request.userid = ids[request.user].ID + request.userid = ids[strings.ToLower(request.user)].ID } return request, nil diff --git a/helix/user.go b/helix/user.go index 66536d0..e514346 100644 --- a/helix/user.go +++ b/helix/user.go @@ -2,6 +2,7 @@ package helix import ( "net/http" + "strings" helixClient "github.com/nicklaw5/helix" log "github.com/sirupsen/logrus" @@ -110,8 +111,8 @@ func (c *Client) GetUsersByUsernames(usernames []string) (map[string]UserData, e var filteredUsernames []string for _, username := range usernames { - if _, ok := userCacheByUsername[username]; !ok { - filteredUsernames = append(filteredUsernames, username) + if _, ok := userCacheByUsername[strings.ToLower(username)]; !ok { + filteredUsernames = append(filteredUsernames, strings.ToLower(username)) } } @@ -146,7 +147,7 @@ func (c *Client) GetUsersByUsernames(usernames []string) (map[string]UserData, e result := make(map[string]UserData) for _, username := range usernames { - result[username] = *userCacheByUsername[username] + result[strings.ToLower(username)] = *userCacheByUsername[strings.ToLower(username)] } return result, nil