diff --git a/pkg/api/aiden/weather.go b/pkg/api/aiden/weather.go new file mode 100644 index 0000000..e631471 --- /dev/null +++ b/pkg/api/aiden/weather.go @@ -0,0 +1,26 @@ +package aiden + +import ( + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +func Weather(location string) string { + resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/misc/weather/%s", location)) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan" + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Error(err) + return "Something went wrong FeelsBadMan" + } + return string(body) +} diff --git a/pkg/api/ivr.go b/pkg/api/ivr.go deleted file mode 100644 index 036188c..0000000 --- a/pkg/api/ivr.go +++ /dev/null @@ -1,65 +0,0 @@ -package api - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - log "github.com/sirupsen/logrus" -) - -type subageApiResponse struct { - User string `json:"user"` - UserID string `json:"userId"` - Channel string `json:"channel"` - ChannelId string `json:"channelid"` - SubageHidden bool `json:"hidden"` - Subscribed bool `json:"subscribed"` - FollowedAt string `json:"followedAt"` - Cumulative Cumulative `json:"cumulative"` - Streak SubStreak `json:"streak"` - Error string `json:"error"` -} - -type Cumulative struct { - Months int `json:"months"` -} - -type SubStreak struct { - Months int `json:"months"` -} - -func IvrSubage(username string, streamer string) string { - resp, err := http.Get(fmt.Sprintf("https://api.ivr.fi/twitch/subage/%s/%s", username, streamer)) - if err != nil { - log.Error(err) - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - } - - var responseObject subageApiResponse - json.Unmarshal(body, &responseObject) - - // User or channel was not found - if responseObject.Error != "" { - reply := fmt.Sprintf(responseObject.Error + " FeelsBadMan") - // client.Say(channel, fmt.Sprintf(responseObject.Error+" FeelsBadMan")) - return reply - } - - if responseObject.SubageHidden { - - reply := fmt.Sprintf(username + " has their subscription status hidden. FeelsBadMan") - return reply - } else { - months := fmt.Sprint(responseObject.Cumulative.Months) - reply := fmt.Sprintf(username + " has been subscribed to " + streamer + " for " + months + " months.") - return reply - } -} diff --git a/pkg/commands/weather.go b/pkg/commands/weather.go index 5c1a160..9d2755d 100644 --- a/pkg/commands/weather.go +++ b/pkg/commands/weather.go @@ -1,31 +1,12 @@ package commands import ( - "fmt" - "io/ioutil" - "net/http" - "github.com/gempir/go-twitch-irc/v2" - log "github.com/sirupsen/logrus" + "github.com/lyx0/nourybot/pkg/api/aiden" ) func Weather(channel string, location string, client *twitch.Client) { - resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/misc/weather/%s", location)) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - return - } - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - client.Say(channel, "Something went wrong FeelsBadMan") - log.Error(err) - return - } - - client.Say(channel, string(body)) + reply := aiden.Weather(location) + client.Say(channel, reply) }