seperate uid lookup for replys and for internal usage

This commit is contained in:
lyx0 2023-12-20 02:18:57 +01:00
parent 20b598ee3b
commit cabb0d2783
2 changed files with 19 additions and 3 deletions

View file

@ -206,10 +206,10 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
reply, _ = commands.Xkcd() reply, _ = commands.Xkcd()
case "uid": case "uid":
reply = ivr.IDByUsername(cmdParams[1]) reply = ivr.IDByUsernameReply(cmdParams[1])
case "userid": case "userid":
reply = ivr.IDByUsername(cmdParams[1]) reply = ivr.IDByUsernameReply(cmdParams[1])
case "commands": case "commands":
reply = app.ListChannelCommands(message.Channel) reply = app.ListChannelCommands(message.Channel)

View file

@ -10,7 +10,7 @@ type ivrIDByUsernameResponse struct {
ID string `json:"id"` ID string `json:"id"`
} }
func IDByUsername(username string) string { func IDByUsernameReply(username string) string {
baseUrl := "https://api.ivr.fi/v2/twitch/user?login=" baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, username)) 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) reply := fmt.Sprintf("%s=%s", username, responseList[0].ID)
return reply 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
}