func Remind(r *reminders.Reminder, ctx *bot.Context) { delta := r.RemindAt.Sub(time.Now()) if delta < 0 { return } c := make(chan struct{}) running[r.Id] = c go func() { select { case <-time.After(delta): ctx.Privmsg(string(r.Chan), r.Reply()) // TODO(fluffle): Tie this into state tracking properly. ctx.Privmsg(string(r.Target), r.Reply()) // This is used in snooze to reinstate reminders. finished[strings.ToLower(string(r.Target))] = r if pc != nil { if s := pc.GetByNick(string(r.Target)); s.CanPush() { push.Push(s, "Reminder from sp0rkle!", r.Reply()) } } Forget(r.Id, false) case <-c: return } }() }
// tell func tell(ctx *bot.Context) { // s == <target> <stuff> txt := ctx.Text() idx := strings.Index(txt, " ") if idx == -1 { ctx.ReplyN("Tell who what?") return } tell := txt[idx+1:] n, c := ctx.Storable() t := bot.Nick(txt[:idx]) if t.Lower() == strings.ToLower(ctx.Nick) || t.Lower() == "me" { ctx.ReplyN("You're a dick. Oh, wait, that wasn't *quite* it...") return } r := reminders.NewTell(tell, t, n, c) if err := rc.Insert(r); err != nil { ctx.ReplyN("Error saving tell: %v", err) return } if s := pc.GetByNick(txt[:idx]); s.CanPush() { push.Push(s, fmt.Sprintf("%s in %s asked me to tell you:", ctx.Nick, ctx.Target()), tell) } // Any previously-generated list of reminders is now obsolete. delete(listed, ctx.Nick) ctx.ReplyN("%s", r.Acknowledge()) }