func tellCheck(ctx *bot.Context) { nick := ctx.Nick if ctx.Cmd == client.NICK { // We want the destination nick, not the source. nick = ctx.Target() } r := rc.TellsFor(nick) for i := range r { if ctx.Cmd == client.NICK { if r[i].Chan != "" { ctx.Privmsg(string(r[i].Chan), nick+": "+r[i].Reply()) } ctx.Reply("%s", r[i].Reply()) } else { ctx.Privmsg(ctx.Nick, r[i].Reply()) if r[i].Chan != "" { ctx.ReplyN("%s", r[i].Reply()) } } rc.RemoveId(r[i].Id) } if len(r) > 0 { delete(listed, ctx.Nick) } }
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 } }() }
// Factoid literal: 'literal key' => info about factoid func literal(ctx *bot.Context) { key := ToKey(ctx.Text(), false) if count := fc.GetCount(key); count == 0 { ctx.ReplyN("I don't know anything about '%s'.", key) return } else if count > 10 && ctx.Public() { ctx.ReplyN("I know too much about '%s', ask me privately.", key) return } if facts := fc.GetAll(key); facts != nil { for _, fact := range facts { // Use Privmsg directly here so that the results aren't output // via the plugin system and contain the literal data. ctx.Privmsg(ctx.Target(), fmt.Sprintf( "[%3.0f%%] %s", fact.Chance*100, fact.Value)) } } else { ctx.ReplyN("Something literally went wrong :-(") } }
// pushEnable generates a URL to start the OAuth dance for a nick. // Once the user visits this URL and approves the access, they // get redirected back to /oauth/auth, which is handled by // authTokenRedirect below. There, we complete the OAuth dance // and redirect to /oauth/devices (chooseDevice) which lists // the user's devices and accepts a POST to choose a target // device for push notifications. Once this is done, we push // a confirmation notification to the chosen device with a 6 // digit pin and require that they msg that to us via IRC. func pushEnable(ctx *bot.Context) { if s := pc.GetByNick(ctx.Nick); s != nil { if s.HasAlias(ctx.Nick) { ctx.ReplyN("Your nick is already used as an alias for %s.", s.Nick) return } if s.CanPush() { ctx.ReplyN("Pushes already enabled.") return } ctx.Privmsg(ctx.Nick, "Hmm. Deleting partially-complete state...") pc.DelState(s) } s, err := pc.NewState(ctx.Nick) if err != nil { ctx.ReplyN("Error creating push state: %v", err) return } // Privmsg the URL so randoms don't click it. ctx.Privmsg(ctx.Nick, "Hi! Visit the following URL while logged into "+ "the account you want to use to push to your device.") ctx.Privmsg(ctx.Nick, push.AuthCodeURL(s)) }