diff --git a/pkg/api/ivr/profilepicture.go b/pkg/api/ivr/profilepicture.go new file mode 100644 index 0000000..5494996 --- /dev/null +++ b/pkg/api/ivr/profilepicture.go @@ -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 + } +} diff --git a/pkg/commands/profilepicture.go b/pkg/commands/profilepicture.go new file mode 100644 index 0000000..e52f412 --- /dev/null +++ b/pkg/commands/profilepicture.go @@ -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) +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 1a87d90..c902abd 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -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]")