M main.go => main.go +4 -0
@@ 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)
M mux.go => mux.go +2 -0
@@ 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)
}
M x/mux/misc.go => x/mux/misc.go +14 -0
@@ 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()