Merge remote-tracking branch 'origin/time'
Anthony DeDominic adedomin@gmail.com
Mon, 22 Nov 2021 09:41:39 -0500
4 files changed,
44 insertions(+),
5 deletions(-)
M
go.mod
→
go.mod
@@ -7,6 +7,7 @@ github.com/dgraph-io/badger/v3 v3.2103.2
github.com/dustin/go-humanize v1.0.0 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 gopkg.in/irc.v3 v3.1.4 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) -require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b +require github.com/zsefvlol/timezonemapper v1.0.0
M
go.sum
→
go.sum
@@ -77,6 +77,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/zsefvlol/timezonemapper v1.0.0 h1:HXqkOzf01gXYh2nDQcDSROikFgMaximnhE8BY9SyF6E= +github.com/zsefvlol/timezonemapper v1.0.0/go.mod h1:cVUCOLEmc/VvOMusEhpd2G/UBtadL26ZVz2syODXDoQ= go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
A
plugins/time/time.go
@@ -0,0 +1,21 @@
+package time + +import ( + "fmt" + "time" + + "github.com/zsefvlol/timezonemapper" +) + +func getTimezone(lonlat [2]float64) string { + tz := timezonemapper.LatLngToTimezoneString(lonlat[1], lonlat[0]) + return tz +} + +func GetTime(lonlat [2]float64, label string) (string, error) { + loc, _ := time.LoadLocation(getTimezone(lonlat)) + now := time.Now().In(loc) + pretty := now.Format("2006-02-01 03:04 PM") + out := fmt.Sprintf("\x02%s\x02: %s", label, pretty) + return out, nil +}
M
plugins/weather.go
→
plugins/weather.go
@@ -4,6 +4,7 @@ import (
"strings" "git.icyphox.sh/paprika/plugins/location" + "git.icyphox.sh/paprika/plugins/time" "git.icyphox.sh/paprika/plugins/weather" "github.com/dgraph-io/badger/v3" "gopkg.in/irc.v3"@@ -19,6 +20,8 @@ func (Weather) Triggers() []string {
return []string{ ".w", ".weather", + ".t", + ".time", } }@@ -75,9 +78,21 @@ return "Error getting location info. Try again.", nil
} coordinates := li.Features[0].Geometry.Coordinates label := li.Features[0].Properties.Geocoding.Label - info, err := weather.GetWeather(coordinates, label) - if err != nil { - return "Error getting weather data", err + + switch trigger { + case ".t", ".time": + time, err := time.GetTime(coordinates, label) + if err != nil { + return "Error getting time data", err + } + return time, nil + case ".w", ".weather": + + info, err := weather.GetWeather(coordinates, label) + if err != nil { + return "Error getting weather data", err + } + return info, nil } - return info, nil + return "", nil }