Beispiel #1
0
func urlScan(ctx *bot.Context) {
	words := strings.Split(ctx.Text(), " ")
	n, c := ctx.Storable()
	for _, w := range words {
		if util.LooksURLish(w) {
			if u := uc.GetByUrl(w); u != nil {
				if u.Nick != bot.Nick(ctx.Nick) &&
					time.Since(u.Timestamp) > 2*time.Hour {
					ctx.Reply("that URL first mentioned by %s %s ago",
						u.Nick, util.TimeSince(u.Timestamp))
				}
				continue
			}
			u := urls.NewUrl(w, n, c)
			if len(w) > autoShortenLimit && ctx.Public() {
				u.Shortened = Encode(w)
			}
			if err := uc.Insert(u); err != nil {
				ctx.ReplyN("Couldn't insert url '%s': %s", w, err)
				continue
			}
			if u.Shortened != "" {
				ctx.Reply("%s's URL shortened as %s%s%s",
					ctx.Nick, bot.HttpHost(), shortenPath, u.Shortened)
			}
			lastseen[ctx.Target()] = u.Id
		}
	}
}
Beispiel #2
0
func recordPrivmsg(ctx *bot.Context) {
	if !ctx.Public() {
		return
	}
	sn := seenNickFromLine(ctx)
	sn.Text = ctx.Text()
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		ctx.Reply("Failed to store seen data: %v", err)
	}
}
Beispiel #3
0
func recordMarkov(ctx *bot.Context) {
	whom := strings.ToLower(ctx.Nick)
	if !ctx.Addressed && ctx.Public() && shouldMarkov(whom) {
		// Only markov lines that are public, not addressed to us,
		// and from markov-enabled nicks
		switch ctx.Cmd {
		case client.PRIVMSG:
			mc.AddSentence(ctx.Text(), "user:"******"user:"+whom)
		}
	}
}
Beispiel #4
0
func learn(ctx *bot.Context) {
	s := strings.SplitN(ctx.Text(), " ", 2)
	if len(s) != 2 {
		ctx.ReplyN("I can't learn from you, you're an idiot.")
		return
	}

	// Prepending "tag:" prevents people from learning as "user:foo".
	mc.AddSentence(s[1], "tag:"+s[0])
	if ctx.Public() {
		// Allow large-scale learning via privmsg by not replying there.
		ctx.ReplyN("Ta. You're a fount of knowledge, you are.")
	}
}
Beispiel #5
0
// remind list
func list(ctx *bot.Context) {
	r := rc.RemindersFor(ctx.Nick)
	c := len(r)
	if c == 0 {
		ctx.ReplyN("You have no reminders set.")
		return
	}
	if c > 5 && ctx.Public() {
		ctx.ReplyN("You've got lots of reminders, ask me privately.")
		return
	}
	// Save an ordered list of ObjectIds for easy reminder deletion
	ctx.ReplyN("You have %d reminders set:", c)
	list := make([]bson.ObjectId, c)
	for i := range r {
		ctx.Reply("%d: %s", i+1, r[i].List(ctx.Nick))
		list[i] = r[i].Id
	}
	listed[ctx.Nick] = list
}
Beispiel #6
0
// 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 :-(")
	}
}