bb/bot/commands/time.go
Ryan Cavicchioni c59c95c47a
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
Refactor commands to use the router
2022-09-06 00:02:24 -05:00

35 lines
586 B
Go

package commands
import (
"fmt"
"time"
"git.kill0.net/chill9/beepboop/bot"
log "github.com/sirupsen/logrus"
)
func TimeCommand(cmd *bot.Command, args []string) error {
var (
t time.Time
tz string
)
now := time.Now()
if len(args) == 1 {
tz = args[0]
loc, err := time.LoadLocation(tz)
if err != nil {
log.Warnf("failed to load location: %s", err)
cmd.Session.ChannelMessageSend(cmd.Message.ChannelID, err.Error())
return nil
}
t = now.In(loc)
} else {
t = now
}
cmd.Session.ChannelMessageSend(cmd.Message.ChannelID, fmt.Sprint(t))
return nil
}