add userid command

This commit is contained in:
lyx0 2021-10-18 20:33:51 +02:00
parent e7e7bc2793
commit dab9ff05aa
3 changed files with 66 additions and 0 deletions

39
pkg/api/ivr/userid.go Normal file
View file

@ -0,0 +1,39 @@
package ivr
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
// https://api.ivr.fi
type uidApiResponse struct {
Id string `json:"id"`
Error string `json:"error"`
}
func Userid(username string) string {
resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/resolve/%s", username))
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
var responseObject uidApiResponse
json.Unmarshal(body, &responseObject)
// User not found
if responseObject.Error != "" {
return fmt.Sprintf(responseObject.Error + " FeelsBadMan")
} else {
return fmt.Sprintf(responseObject.Id)
}
}

11
pkg/commands/userid.go Normal file
View file

@ -0,0 +1,11 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func Userid(channel string, target string, client *twitch.Client) {
reply := ivr.Userid(target)
client.Say(channel, reply)
}

View file

@ -220,6 +220,22 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
commands.Uptime(message.Channel, cmdParams[1], twitchClient)
return
}
case "uid":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()userid [username]")
return
} else {
commands.Userid(message.Channel, cmdParams[1], twitchClient)
return
}
case "userid":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()userid [username]")
return
} else {
commands.Userid(message.Channel, cmdParams[1], twitchClient)
return
}
case "weather":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()weather [location]")