From 9a6906dfa5afe8f53e3276d8c0740b8bbc35237d Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Tue, 30 Apr 2019 15:07:15 +0000 Subject: [PATCH] add uptime command --- main.go | 4 ++++ mux.go | 2 ++ x/mux/misc.go | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/main.go b/main.go index 637b0f4fb74e076a22dffee5ca99c6a720adb519..4ee68fa9addc299c91c66ca33e38c2c8572c60c2 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "syscall" + "time" "github.com/bwmarrin/discordgo" "bitbucket.org/henesy/glenda/x/mux" sc "strconv" @@ -75,6 +76,9 @@ func main() { log.Printf("error opening connection to Discord, %s\n", err) os.Exit(1) } + + // Init boot vars + mux.StartTime = time.Now() // Init Mux daemons go mux.Config.Init(Session) diff --git a/mux.go b/mux.go index f22afdc654d313fa4761804d4b4a627bafa3fc0d..12e148fb474d24c1b40fece5b946002e29610fda 100644 --- a/mux.go +++ b/mux.go @@ -55,4 +55,6 @@ func init() { Router.Route("whiskey", ":tumbler_glass:", Router.Whiskey) Router.Route("wine", ":wine_glass:", Router.Wine) + + Router.Route("uptime", "Current bot uptime", Router.Uptime) } diff --git a/x/mux/misc.go b/x/mux/misc.go index ed92dcfd98283bcd7854a8505a45747f876a8bd6..0c46f5a6fe0010a91d5c7a6d1681da68eb5866ed 100644 --- a/x/mux/misc.go +++ b/x/mux/misc.go @@ -14,6 +14,9 @@ var MuxChan chan string // Chan for communicating with Dump var dumpChan chan string +// Stores the time that the bot started this boot +var StartTime time.Time + // Multiplex internal channels, initialized once func CommMux() { @@ -58,6 +61,17 @@ func dump() string { return resp } +// Return the current uptime +func (m *Mux) Uptime(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { + resp := "" + + resp += time.Now().Sub(StartTime).String() + + ds.ChannelMessageSend(dm.ChannelID, resp) + + return +} + // Dump config to file func (m *Mux) Dump(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { resp := dump()