change subage api

This commit is contained in:
lyx0 2021-10-17 18:24:39 +02:00
parent ee5796e802
commit ada20061a7
2 changed files with 21 additions and 10 deletions

View file

@ -17,23 +17,28 @@ type subageApiResponse struct {
SubageHidden bool `json:"hidden"` SubageHidden bool `json:"hidden"`
Subscribed bool `json:"subscribed"` Subscribed bool `json:"subscribed"`
FollowedAt string `json:"followedAt"` FollowedAt string `json:"followedAt"`
Cumulative Cumulative `json:"cumulative"` Cumulative cumulative `json:"cumulative"`
Streak SubStreak `json:"streak"` Streak subStreak `json:"streak"`
Error string `json:"error"` Error string `json:"error"`
} }
type Cumulative struct { type cumulative struct {
Months int `json:"months"` Months int `json:"months"`
} }
type SubStreak struct { type subStreak struct {
Months int `json:"months"` Months int `json:"months"`
} }
func Subage(username string, streamer string) string { var (
resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/subage/%s/%s", username, streamer)) subageBaseUrl = "https://api.ivr.fi/twitch/subage"
)
func Subage(username string, streamer string) (string, error) {
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", subageBaseUrl, username, streamer))
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return "Something went wrong FeelsBadMan", err
} }
defer resp.Body.Close() defer resp.Body.Close()
@ -50,16 +55,16 @@ func Subage(username string, streamer string) string {
if responseObject.Error != "" { if responseObject.Error != "" {
reply := fmt.Sprintf(responseObject.Error + " FeelsBadMan") reply := fmt.Sprintf(responseObject.Error + " FeelsBadMan")
// client.Say(channel, fmt.Sprintf(responseObject.Error+" FeelsBadMan")) // client.Say(channel, fmt.Sprintf(responseObject.Error+" FeelsBadMan"))
return reply return reply, nil
} }
if responseObject.SubageHidden { if responseObject.SubageHidden {
reply := fmt.Sprintf(username + " has their subscription status hidden. FeelsBadMan") reply := fmt.Sprintf(username + " has their subscription status hidden. FeelsBadMan")
return reply return reply, nil
} else { } else {
months := fmt.Sprint(responseObject.Cumulative.Months) months := fmt.Sprint(responseObject.Cumulative.Months)
reply := fmt.Sprintf(username + " has been subscribed to " + streamer + " for " + months + " months.") reply := fmt.Sprintf(username + " has been subscribed to " + streamer + " for " + months + " months.")
return reply return reply, nil
} }
} }

View file

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