add profilepicture command

This commit is contained in:
lyx0 2021-10-18 18:47:38 +02:00
parent 590e7b866d
commit e7e7bc2793
3 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,44 @@
package ivr
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
log "github.com/sirupsen/logrus"
)
// https://api.ivr.fi
type pfpApiResponse struct {
Logo string `json:"logo"`
Error string `json:"error"`
}
var (
baseUrl = "https://api.ivr.fi/twitch/resolve"
)
func ProfilePicture(username string) (string, error) {
resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, username))
if err != nil {
log.Error(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error(err)
}
var responseObject pfpApiResponse
json.Unmarshal(body, &responseObject)
// User not found
if responseObject.Error != "" {
return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil
} else {
return fmt.Sprintf(responseObject.Logo), nil
}
}

View file

@ -0,0 +1,18 @@
package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func ProfilePicture(channel string, target string, client *twitch.Client) {
reply, err := ivr.ProfilePicture(target)
if err != nil {
client.Say(channel, fmt.Sprint(err))
return
}
client.Say(channel, reply)
}

View file

@ -154,6 +154,20 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
case "pingme":
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
return
case "profilepicture":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()profilepicture [user]")
return
}
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
return
case "pfp":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()pfp [user]")
return
}
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
return
case "pyramid":
if msgLen != 3 {
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")