From b7786642b3bdfe0b56c5119c2c02141f02f50758 Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Mon, 7 May 2018 00:37:20 +0000 Subject: [PATCH] added functioning remindme --- TODO | 1 - mux.go | 2 +- x/mux/remind.go | 16 +++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 42695d87ac3bc2f5e31b212f9d96f3e182c67caf..2bee68189fb4e7aa15b501a869bd910aa04183ad 100644 --- a/TODO +++ b/TODO @@ -7,7 +7,6 @@ Features * various cat-v fetches (harmful, page search [get lucky]) * Auto-propaganda processing for images (Black and White -> (9)-ify) * g!status -- display status/uptime info -* g!remindme [time] text -- set a reminder for a given time (should work across bot reboots) -- Problems diff --git a/mux.go b/mux.go index d7d2e63b6e275a702eaf8c561bc42dbd02cb4a81..2be3f65483190b14ce714e606fa95da1dd6d809d 100644 --- a/mux.go +++ b/mux.go @@ -44,5 +44,5 @@ func init() { Router.Route("whiskey", ":tumbler_glass:", Router.Whiskey) - Router.Route("remindme", "Set a reminder for a given time interval ([int][hmsdny] [reminder]).", Router.RemindMe) + Router.Route("remindme", "Set a reminder for a given time interval ([int][hmsd] [reminder]).", Router.RemindMe) } diff --git a/x/mux/remind.go b/x/mux/remind.go index 96f8c8c8290027e53c40fa9ba068db5e1bbb4de4..d5b993672ceb3d97ae9a1c86298cae9bfd158934 100644 --- a/x/mux/remind.go +++ b/x/mux/remind.go @@ -5,6 +5,7 @@ import ( "time" sc "strconv" "container/list" + "fmt" ) @@ -40,7 +41,7 @@ func Reminders() { r, _ := e.Value.(Reminder) if time.Now().After(r.NotifyAfter) { // If we have passed the time of desired notification - r.Session.ChannelMessageSend(r.ChannelID, r.Reason) + r.Session.ChannelMessageSend(r.ChannelID, r.User.Mention() + " -- " + r.Reason) rems.Remove(e) } } @@ -57,7 +58,7 @@ func (m *Mux) RemindMe(ds *discordgo.Session, dm *discordgo.Message, ctx *Contex // remindme 20m dothing if len(ctx.Fields) >= 3 { var rem Reminder - periodLong := ctx.Fields[len(ctx.Fields)-2] + periodLong := ctx.Fields[1] reasonLong := ctx.Fields[2 : len(ctx.Fields)] rem.User = *dm.Author rem.ChannelID = dm.ChannelID @@ -71,12 +72,17 @@ func (m *Mux) RemindMe(ds *discordgo.Session, dm *discordgo.Message, ctx *Contex rem.Reason = reason interval := periodLong[len(periodLong)-1] - period, err := sc.Atoi(periodLong[:len(periodLong)-2]) + period, err := sc.Atoi(periodLong[:len(periodLong)-1]) if err != nil { resp += "Invalid period value." goto SEND } + fmt.Println(interval) + fmt.Println(period) + fmt.Println(reason) + fmt.Println(time.Now) + var dur time.Duration switch interval { case 's': @@ -85,6 +91,8 @@ func (m *Mux) RemindMe(ds *discordgo.Session, dm *discordgo.Message, ctx *Contex dur = time.Minute case 'h': dur = time.Hour + case 'd': + dur = time.Hour * time.Duration(24) default: resp += "Invalid interval specifier." goto SEND @@ -92,6 +100,8 @@ func (m *Mux) RemindMe(ds *discordgo.Session, dm *discordgo.Message, ctx *Contex rem.NotifyAfter = time.Now().Add(time.Duration(period) * dur) + fmt.Println(rem) + RemChan <- rem } else {