Example #1
0
func recordKick(line *base.Line) {
	n, c := line.Storable()
	kn := base.Nick(line.Args[1])
	// seenNickFromLine doesn't work with the hacks for KICKING and KICKED
	// First, handle KICKING
	kr := sc.LastSeenDoing(line.Nick, "KICKING")
	if kr == nil {
		kr = seen.SawNick(n, c, "KICKING", line.Args[2])
	} else {
		kr.Nick, kr.Chan = n, c
		kr.Timestamp, kr.Text = time.Now(), line.Args[2]
	}
	kr.OtherNick = kn
	_, err := sc.Upsert(kr.Id(), kr)
	if err != nil {
		bot.Reply(line, "Failed to store seen data: %v", err)
	}
	// Now, handle KICKED
	ke := sc.LastSeenDoing(line.Args[1], "KICKED")
	if ke == nil {
		ke = seen.SawNick(kn, c, "KICKED", line.Args[2])
	} else {
		ke.Nick, ke.Chan = kn, c
		ke.Timestamp, ke.Text = time.Now(), line.Args[2]
	}
	ke.OtherNick = n
	_, err = sc.Upsert(ke.Id(), ke)
	if err != nil {
		bot.Reply(line, "Failed to store seen data: %v", err)
	}
}
Example #2
0
func urlScan(line *base.Line) {
	words := strings.Split(line.Args[1], " ")
	n, c := line.Storable()
	for _, w := range words {
		if util.LooksURLish(w) {
			if u := uc.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 = Encode(w)
			}
			if err := uc.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.HttpHost(), shortenPath, u.Shortened)
			}
			lastseen[line.Args[0]] = u.Id
		}
	}
}
Example #3
0
func recordPrivmsg(line *base.Line) {
	sn := seenNickFromLine(line)
	sn.Text = line.Args[1]
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		bot.Reply(line, "Failed to store seen data: %v", err)
	}
}
Example #4
0
func topten(line *base.Line) {
	top := sc.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, ", "))
}
Example #5
0
func recordLines(line *base.Line) {
	sn := sc.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)
		}
	}
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		bot.Reply(line, "Failed to store seen data: %v", err)
	}
}
Example #6
0
func recordJoin(line *base.Line) {
	sn := seenNickFromLine(line)
	if len(line.Args) > 1 {
		// If we have a PART message
		sn.Text = line.Args[1]
	}
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		bot.Reply(line, "Failed to store seen data: %v", err)
	}
}
Example #7
0
func fetch(line *base.Line) {
	if 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 := qc.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)
	}
}
Example #8
0
func lookup(line *base.Line) {
	// Only perform extra prefix removal if we weren't addressed directly
	key := ToKey(line.Args[1], !line.Addressed)
	var fact *factoids.Factoid

	if fact = fc.GetPseudoRand(key); fact == nil && line.Cmd == "ACTION" {
		// Support sp0rkle's habit of stripping off it's own nick
		// but only for actions, not privmsgs.
		if strings.HasSuffix(key, bot.Nick()) {
			key = strings.TrimSpace(key[:len(key)-len(bot.Nick())])
			fact = fc.GetPseudoRand(key)
		}
	}
	if fact == nil {
		return
	}
	// Chance is used to limit the rate of factoid replies for things
	// people say a lot, like smilies, or 'lol', or 'i love the peen'.
	chance := fact.Chance
	if key == "" {
		// This is doing a "random" lookup, triggered by someone typing in
		// something entirely composed of the chars stripped by ToKey().
		// To avoid making this too spammy, forcibly limit the chance to 40%.
		chance = 0.4
	}
	if rand.Float64() < chance {
		// Store this as the last seen factoid
		LastSeen(line.Args[0], fact.Id)
		// Update the Accessed field
		// TODO(fluffle): fd should take care of updating Accessed internally
		fact.Access(line.Storable())
		// And store the new factoid data
		if err := fc.Update(bson.M{"_id": fact.Id}, fact); err != nil {
			bot.ReplyN(line, "I failed to update '%s' (%s): %s ",
				fact.Key, fact.Id, err)
		}
		keys := map[string]bool{key: true}
		val := recurse(fact.Value, keys)
		switch fact.Type {
		case factoids.F_ACTION:
			bot.Do(line, "%s", val)
		default:
			bot.Reply(line, "%s", val)
		}
	}
}
Example #9
0
func lookup(line *base.Line) {
	if RateLimit(line.Nick) {
		return
	}
	quote := qc.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 := qc.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)
}
Example #10
0
func smoke(line *base.Line) {
	if !smokeRx.MatchString(line.Args[1]) {
		return
	}
	sn := sc.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.Nick, sn.Chan = n, c
		sn.Timestamp = time.Now()
	} else {
		sn = seen.SawNick(n, c, "SMOKE", "")
	}
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		bot.Reply(line, "Failed to store smoke data: %v", err)
	}
}
Example #11
0
func recordKarma(line *base.Line) {
	// Karma can look like some.text.string++ or (text with spaces)--
	// and there could be multiple occurrences of it in a string.
	nick, _ := line.Storable()
	for _, kt := range karmaThings(line.Args[1]) {
		k := kc.KarmaFor(kt.thing)
		if k == nil {
			k = karma.New(kt.thing)
		}
		if kt.plus {
			k.Plus(nick)
		} else {
			k.Minus(nick)
		}
		if _, err := kc.Upsert(k.Id(), k); err != nil {
			bot.Reply(line, "Failed to insert Karma: %s", err)
		}
	}
}
Example #12
0
// remind list
func list(line *base.Line) {
	r := rc.RemindersFor(line.Nick)
	c := len(r)
	if c == 0 {
		bot.ReplyN(line, "You have no reminders set.")
		return
	}
	if c > 5 && line.Args[0][0] == '#' {
		bot.ReplyN(line, "You've got lots of reminders, ask me privately.")
		return
	}
	// Save an ordered list of ObjectIds for easy reminder deletion
	bot.ReplyN(line, "You have %d reminders set:", c)
	list := make([]bson.ObjectId, c)
	for i := range r {
		bot.Reply(line, "%d: %s", i+1, r[i].List(line.Nick))
		list[i] = r[i].Id
	}
	listed[line.Nick] = list
}
Example #13
0
func tellCheck(line *base.Line) {
	nick := line.Nick
	if line.Cmd == "NICK" {
		// We want the destination nick, not the source.
		nick = line.Args[0]
	}
	r := rc.TellsFor(nick)
	for i := range r {
		if line.Cmd == "NICK" {
			bot.Privmsg(string(r[i].Chan), nick+": "+r[i].Reply())
			bot.Reply(line, "%s", r[i].Reply())
		} else {
			bot.Privmsg(line.Nick, r[i].Reply())
			bot.ReplyN(line, "%s", r[i].Reply())
		}
		rc.RemoveId(r[i].Id)
	}
	if len(r) > 0 {
		delete(listed, line.Nick)
	}
}