mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
clean up weather command
This commit is contained in:
parent
73299f776c
commit
274a34cf7d
|
@ -203,16 +203,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Xkcd
|
// ()weather <location>
|
||||||
case "rxkcd":
|
|
||||||
commands.RandomXkcd(target, app.TwitchClient)
|
|
||||||
return
|
|
||||||
case "randomxkcd":
|
|
||||||
commands.RandomXkcd(target, app.TwitchClient)
|
|
||||||
return
|
|
||||||
case "xkcd":
|
|
||||||
commands.Xkcd(target, app.TwitchClient)
|
|
||||||
return
|
|
||||||
case "weather":
|
case "weather":
|
||||||
if msgLen < 2 {
|
if msgLen < 2 {
|
||||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||||
|
@ -222,6 +213,19 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
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
|
// 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)
|
app.EditCommandCategory(cmdParams[2], cmdParams[3], message)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,15 @@ import (
|
||||||
"go.uber.org/zap"
|
"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) {
|
func Weather(target, location string, tc *twitch.Client) {
|
||||||
sugar := zap.NewExample().Sugar()
|
sugar := zap.NewExample().Sugar()
|
||||||
defer sugar.Sync()
|
defer sugar.Sync()
|
||||||
|
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sugar.Error("Error loading .env file")
|
sugar.Error("Error loading OpenWeatherMap API key from .env file")
|
||||||
}
|
}
|
||||||
owmKey := os.Getenv("OWM_KEY")
|
owmKey := os.Getenv("OWM_KEY")
|
||||||
|
|
||||||
|
@ -27,11 +29,23 @@ func Weather(target, location string, tc *twitch.Client) {
|
||||||
}
|
}
|
||||||
w.CurrentByName(location)
|
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 {
|
if w.GeoPos.Longitude == 0 && w.GeoPos.Latitude == 0 {
|
||||||
reply := "Location not found FeelsBadMan"
|
reply := "Location not found FeelsBadMan"
|
||||||
common.Send(target, reply, tc)
|
common.Send(target, reply, tc)
|
||||||
} else {
|
} 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)
|
common.Send(target, reply, tc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue