From 3b395f0bc2c95c8851920d964208f02f31833577 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Mon, 15 Aug 2022 15:12:59 +0200 Subject: [PATCH] check if the location was found before replying --- pkg/commands/weather.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/commands/weather.go b/pkg/commands/weather.go index dc8de9d..bb88c15 100644 --- a/pkg/commands/weather.go +++ b/pkg/commands/weather.go @@ -14,6 +14,7 @@ import ( 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") @@ -25,9 +26,12 @@ func Weather(target, location string, tc *twitch.Client) { sugar.Error(err) } w.CurrentByName(location) - // fmt.Println(w) - sugar.Infow("Weather", - "location", w) - 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) + + 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) + common.Send(target, reply, tc) + } }