diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 51eedf9..dbd55f8 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -206,10 +206,10 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { reply, _ = commands.Xkcd() case "uid": - reply = ivr.IDByUsername(cmdParams[1]) + reply = ivr.IDByUsernameReply(cmdParams[1]) case "userid": - reply = ivr.IDByUsername(cmdParams[1]) + reply = ivr.IDByUsernameReply(cmdParams[1]) case "commands": reply = app.ListChannelCommands(message.Channel) diff --git a/pkg/ivr/user.go b/pkg/ivr/user.go index 3036b54..26a56fe 100644 --- a/pkg/ivr/user.go +++ b/pkg/ivr/user.go @@ -10,7 +10,7 @@ type ivrIDByUsernameResponse struct { ID string `json:"id"` } -func IDByUsername(username string) string { +func IDByUsernameReply(username string) string { baseUrl := "https://api.ivr.fi/v2/twitch/user?login=" resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, username)) @@ -26,3 +26,19 @@ func IDByUsername(username string) string { reply := fmt.Sprintf("%s=%s", username, responseList[0].ID) return reply } + +func IDByUsername(username string) string { + baseUrl := "https://api.ivr.fi/v2/twitch/user?login=" + + resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, username)) + if err != nil { + return "xd" + } + + defer resp.Body.Close() + + responseList := make([]ivrIDByUsernameResponse, 0) + _ = json.NewDecoder(resp.Body).Decode(&responseList) + + return responseList[0].ID +}