From cabb0d27833658e2dcd6160eb11cd9a8bc92f8f9 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Wed, 20 Dec 2023 02:18:57 +0100 Subject: [PATCH] seperate uid lookup for replys and for internal usage --- cmd/nourybot/commands.go | 4 ++-- pkg/ivr/user.go | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) 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 +}