func sd_record_kick(bot *bot.Sp0rkle, line *base.Line) { sd := bot.GetDriver(driverName).(*seenDriver) n, c := line.Storable() kn := db.StorableNick{Nick: line.Args[1]} // SeenNickFromLine doesn't work with the hacks for KICKING and KICKED // First, handle KICKING kr := sd.LastSeenDoing(line.Nick, "KICKING") if kr == nil { kr = seen.SawNick(n, c, "KICKING", line.Args[2]) } else { kr.StorableNick, kr.StorableChan = n, c kr.Timestamp, kr.Text = time.Now(), line.Args[2] } kr.OtherNick = kn _, err := sd.Upsert(kr.Index(), kr) if err != nil { bot.Reply(line, "Failed to store seen data: %v", err) } // Now, handle KICKED ke := sd.LastSeenDoing(line.Args[1], "KICKED") if ke == nil { ke = seen.SawNick(kn, c, "KICKED", line.Args[2]) } else { ke.StorableNick, ke.StorableChan = kn, c ke.Timestamp, ke.Text = time.Now(), line.Args[2] } ke.OtherNick = n _, err = sd.Upsert(ke.Index(), ke) if err != nil { bot.Reply(line, "Failed to store seen data: %v", err) } }
func ud_scan(bot *bot.Sp0rkle, ud *urlDriver, line *base.Line) { words := strings.Split(line.Args[1], " ") n, c := line.Storable() for _, w := range words { if util.LooksURLish(w) { if u := ud.GetByUrl(w); u != nil { bot.Reply(line, "%s first mentioned by %s at %s", w, u.Nick, u.Timestamp.Format(time.RFC1123)) continue } u := urls.NewUrl(w, n, c) if len(w) > autoShortenLimit { u.Shortened = ud.Encode(w) } if err := ud.Insert(u); err != nil { bot.ReplyN(line, "Couldn't insert url '%s': %s", w, err) continue } if u.Shortened != "" { bot.Reply(line, "%s's URL shortened as %s%s%s", line.Nick, bot.Prefix, shortenPath, u.Shortened) } ud.lastseen[line.Args[0]] = u.Id } } }
func sd_topten(bot *bot.Sp0rkle, sd *seenDriver, line *base.Line) { top := sd.TopTen(line.Args[0]) s := make([]string, 0, 10) for i, n := range top { s = append(s, fmt.Sprintf("#%d: %s - %d", i+1, n.Nick, n.Lines)) } bot.Reply(line, "%s", strings.Join(s, ", ")) }
func sd_record_pm(bot *bot.Sp0rkle, line *base.Line) { sd := bot.GetDriver(driverName).(*seenDriver) sn := sd.SeenNickFromLine(line) sn.Text = line.Args[1] _, err := sd.Upsert(sn.Index(), sn) if err != nil { bot.Reply(line, "Failed to store seen data: %v", err) } }
func sd_record_lines(bot *bot.Sp0rkle, line *base.Line) { sd := bot.GetDriver(driverName).(*seenDriver) sn := sd.LinesFor(line.Nick, line.Args[0]) if sn == nil { n, c := line.Storable() sn = seen.SawNick(n, c, "LINES", "") } sn.Lines++ for _, n := range milestones { if sn.Lines == n { bot.Reply(line, "%s has said %d lines in this channel and"+ "should now shut the f**k up and do something useful", line.Nick, sn.Lines) } } _, err := sd.Upsert(sn.Index(), sn) if err != nil { bot.Reply(line, "Failed to store seen data: %v", err) } }
func sd_record_chan(bot *bot.Sp0rkle, line *base.Line) { sd := bot.GetDriver(driverName).(*seenDriver) sn := sd.SeenNickFromLine(line) if len(line.Args) > 1 { // If we have a PART message sn.Text = line.Args[1] } _, err := sd.Upsert(sn.Index(), sn) if err != nil { bot.Reply(line, "Failed to store seen data: %v", err) } }
func qd_fetch(bot *bot.Sp0rkle, qd *quoteDriver, line *base.Line) { if qd.rateLimit(line.Nick) { return } qid, err := strconv.Atoi(line.Args[1]) if err != nil { bot.ReplyN(line, "'%s' doesn't look like a quote id.", line.Args[1]) return } quote := qd.GetByQID(qid) if quote != nil { bot.Reply(line, "#%d: %s", quote.QID, quote.Quote) } else { bot.ReplyN(line, "No quote found for id %d", qid) } }
func qd_lookup(bot *bot.Sp0rkle, qd *quoteDriver, line *base.Line) { if qd.rateLimit(line.Nick) { return } quote := qd.GetPseudoRand(line.Args[1]) if quote == nil { bot.ReplyN(line, "No quotes matching '%s' found.", line.Args[1]) return } // TODO(fluffle): qd should take care of updating Accessed internally quote.Accessed++ if err := qd.Update(bson.M{"_id": quote.Id}, quote); err != nil { bot.ReplyN(line, "I failed to update quote #%d: %s", quote.QID, err) } bot.Reply(line, "#%d: %s", quote.QID, quote.Quote) }
func sd_smoke(bot *bot.Sp0rkle, line *base.Line) { if !smokeRx.MatchString(line.Args[1]) { return } sd := bot.GetDriver(driverName).(*seenDriver) sn := sd.LastSeenDoing(line.Nick, "SMOKE") n, c := line.Storable() if sn != nil { bot.ReplyN(line, "You last went for a smoke %s ago...", util.TimeSince(sn.Timestamp)) sn.StorableNick, sn.StorableChan = n, c sn.Timestamp = time.Now() } else { sn = seen.SawNick(n, c, "SMOKE", "") } if _, err := sd.Upsert(sn.Index(), sn); err != nil { bot.Reply(line, "Failed to store smoke data: %v", err) } }