add weather command

This commit is contained in:
lyx0 2021-10-14 22:40:20 +02:00
parent ca1034a79e
commit 89b2d480e7
2 changed files with 38 additions and 0 deletions

31
pkg/commands/weather.go Normal file
View file

@ -0,0 +1,31 @@
package commands
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/gempir/go-twitch-irc/v2"
log "github.com/sirupsen/logrus"
)
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))
}

View file

@ -68,5 +68,12 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
commands.EightBall(message, twitchClient)
return
case "weather":
if msgLen == 1 {
twitchClient.Say(message.Channel, "Usage: ()weather [location]")
} else {
commands.Weather(message.Channel, message.Message[9:len(message.Message)], twitchClient)
}
}
}