clean up weather command

This commit is contained in:
lyx0 2022-08-15 17:38:10 +02:00
parent 73299f776c
commit 274a34cf7d
2 changed files with 30 additions and 13 deletions

View file

@ -203,16 +203,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
return
}
// Xkcd
case "rxkcd":
commands.RandomXkcd(target, app.TwitchClient)
return
case "randomxkcd":
commands.RandomXkcd(target, app.TwitchClient)
return
case "xkcd":
commands.Xkcd(target, app.TwitchClient)
return
// ()weather <location>
case "weather":
if msgLen < 2 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
@ -222,6 +213,19 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
return
}
// Xkcd
// Random Xkcd
case "rxkcd":
commands.RandomXkcd(target, app.TwitchClient)
return
case "randomxkcd":
commands.RandomXkcd(target, app.TwitchClient)
return
// Latest Xkcd
case "xkcd":
commands.Xkcd(target, app.TwitchClient)
return
// Commands with permission level or database from here on
//#################
@ -323,7 +327,6 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
app.EditCommandCategory(cmdParams[2], cmdParams[3], message)
return
} else {
return
}

View file

@ -11,13 +11,15 @@ import (
"go.uber.org/zap"
)
// Weather queries the OpenWeatherMap Api for the given location and sends the
// current weather response to the target twitch chat.
func Weather(target, location string, tc *twitch.Client) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
err := godotenv.Load()
if err != nil {
sugar.Error("Error loading .env file")
sugar.Error("Error loading OpenWeatherMap API key from .env file")
}
owmKey := os.Getenv("OWM_KEY")
@ -27,11 +29,23 @@ func Weather(target, location string, tc *twitch.Client) {
}
w.CurrentByName(location)
// Longitude and Latitude are returned as 0 when the supplied location couldn't be
// assigned to a OpenWeatherMap location.
if w.GeoPos.Longitude == 0 && w.GeoPos.Latitude == 0 {
reply := "Location not found FeelsBadMan"
common.Send(target, reply, tc)
} else {
reply := fmt.Sprintf("Weather for %s, %s: Feels like: %v°C. Currently %v°C with a high of %v°C and a low of %v°C, humidity: %v%%, wind: %vm/s.", w.Name, w.Sys.Country, w.Main.FeelsLike, w.Main.Temp, w.Main.TempMax, w.Main.TempMin, w.Main.Humidity, w.Wind.Speed)
// Weather for Vilnius, LT: Feels like: 29.67°C. Currently 29.49°C with a high of 29.84°C and a low of 29.49°C, humidity: 45%, wind: 6.17m/s.
reply := fmt.Sprintf("Weather for %s, %s: Feels like: %v°C. Currently %v°C with a high of %v°C and a low of %v°C, humidity: %v%%, wind: %vm/s.",
w.Name,
w.Sys.Country,
w.Main.FeelsLike,
w.Main.Temp,
w.Main.TempMax,
w.Main.TempMin,
w.Main.Humidity,
w.Wind.Speed,
)
common.Send(target, reply, tc)
}
}