mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add weather command
This commit is contained in:
parent
ca1034a79e
commit
89b2d480e7
31
pkg/commands/weather.go
Normal file
31
pkg/commands/weather.go
Normal 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))
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue