Exemplo n.º 1
0
func cd_calc(bot *bot.Sp0rkle, line *base.Line, maths string) {
	if num, err := calc.Calc(maths); err == nil {
		bot.ReplyN(line, "%s = %g", maths, num)
	} else {
		bot.ReplyN(line, "%s error while parsing %s", err, maths)
	}
}
Exemplo n.º 2
0
func fd_literal(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	key := ToKey(line.Args[1], false)
	if count := fd.GetCount(key); count == 0 {
		bot.ReplyN(line, "I don't know anything about '%s'.", key)
		return
	} else if count > 10 && strings.HasPrefix(line.Args[0], "#") {
		bot.ReplyN(line, "I know too much about '%s', ask me privately.", key)
		return
	}

	// Temporarily turn off flood protection cos we could be spamming a bit.
	bot.Conn.Flood = true
	defer func() { bot.Conn.Flood = false }()
	// Passing an anonymous function to For makes it a little hard to abstract
	// away in lib/factoids. Fortunately this is something of a one-off.
	var fact *factoids.Factoid
	f := func() error {
		if fact != nil {
			bot.ReplyN(line, "[%3.0f%%] %s", fact.Chance*100, fact.Value)
		}
		return nil
	}
	if err := fd.Find(bson.M{"key": key}).For(&fact, f); err != nil {
		bot.ReplyN(line, "Something literally went wrong: %s", err)
	}
}
Exemplo n.º 3
0
func cd_netmask(bot *bot.Sp0rkle, line *base.Line, ips, nms string) {
	ip := net.ParseIP(ips)
	nmip := net.ParseIP(nms)
	if ip == nil || nmip == nil {
		bot.ReplyN(line, "either %s or %s couldn't be parsed as an IP", ips, nms)
		return
	}
	// this is a bit of a hack, because using ParseIP to parse
	// something that's actually a v4 netmask doesn't quite work
	nm := net.IPMask(nmip.To4())
	cidr, bits := nm.Size()
	if ip.To4() != nil && nm != nil {
		if bits != 32 {
			bot.ReplyN(line, "%s doesn't look like a valid IPv4 netmask", nms)
			return
		}
	} else {
		// IPv6, hopefully
		nm = net.IPMask(nmip)
		cidr, bits = nm.Size()
		if bits != 128 {
			bot.ReplyN(line, "%s doesn't look like a valid IPv6 netmask", nms)
			return
		}
	}
	btm, top := cd_netmask_range(ip, nm)
	bot.ReplyN(line, "%s/%d is in the range %s-%s and has the netmask %s",
		ip, cidr, btm, top, nmip)
}
Exemplo n.º 4
0
func cd_ord(bot *bot.Sp0rkle, line *base.Line, ord string) {
	r, _ := utf8.DecodeRuneInString(ord)
	if r == utf8.RuneError {
		bot.ReplyN(line, "Couldn't parse a utf8 rune from %s", ord)
		return
	}
	bot.ReplyN(line, "ord(%c) is %d, %U, '%s'", r, r, r, cd_utf8repr(r))
}
Exemplo n.º 5
0
func cd_netmask_cidr(bot *bot.Sp0rkle, line *base.Line, cidr string) {
	if _, nm, err := net.ParseCIDR(cidr); err == nil {
		btm, top := cd_netmask_range(nm.IP, nm.Mask)
		bot.ReplyN(line, "%s is in the range %s-%s and has the netmask %s",
			cidr, btm, top, net.IP(nm.Mask))
	} else {
		bot.ReplyN(line, "error parsing ip/cidr %s: %s", cidr, err)
	}
}
Exemplo n.º 6
0
func cd_chr(bot *bot.Sp0rkle, line *base.Line, chr string) {
	// handles decimal, hex, and octal \o/
	i, err := strconv.ParseInt(chr, 0, 0)
	if err != nil {
		bot.ReplyN(line, "Couldn't parse %s as an integer: %s", chr, err)
		return
	}
	bot.ReplyN(line, "chr(%s) is %c, %U, '%s'", chr, i, i, cd_utf8repr(rune(i)))
}
Exemplo n.º 7
0
func qd_add(bot *bot.Sp0rkle, qd *quoteDriver, line *base.Line) {
	n, c := line.Storable()
	quote := quotes.NewQuote(line.Args[1], n, c)
	quote.QID = qd.NewQID()
	if err := qd.Insert(quote); err == nil {
		bot.ReplyN(line, "Quote added succesfully, id #%d.", quote.QID)
	} else {
		bot.ReplyN(line, "Error adding quote: %s.", err)
	}
}
Exemplo n.º 8
0
func fd_delete(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	// Get fresh state on the last seen factoid.
	ls := fd.Lastseen(line.Args[0], "")
	if fact := fd.GetById(ls); fact != nil {
		if err := fd.Remove(bson.M{"_id": ls}); err == nil {
			bot.ReplyN(line, "I forgot that '%s' was '%s'.",
				fact.Key, fact.Value)
		} else {
			bot.ReplyN(line, "I failed to forget '%s': %s", fact.Key, err)
		}
	} else {
		bot.ReplyN(line, "Whatever that was, I've already forgotten it.")
	}
}
Exemplo n.º 9
0
func dd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
	if !line.Addressed {
		return
	}

	switch {
	case strings.HasPrefix(line.Args[1], "decide "):
		opts := splitDelimitedString(line.Args[1][7:])
		chosen := strings.TrimSpace(opts[util.RNG.Intn(len(opts))])
		bot.ReplyN(line, "%s", chosen)
	case strings.HasPrefix(line.Args[1], "rand "):
		bot.ReplyN(line, "%s", randomFloatAsString(line.Args[1][5:], util.RNG))
	}
}
Exemplo n.º 10
0
func qd_delete(bot *bot.Sp0rkle, qd *quoteDriver, line *base.Line) {
	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
	}
	if quote := qd.GetByQID(qid); quote != nil {
		if err := qd.Remove(bson.M{"_id": quote.Id}); err == nil {
			bot.ReplyN(line, "I forgot quote #%d: %s", qid, quote.Quote)
		} else {
			bot.ReplyN(line, "I failed to forget quote #%d: %s", qid, err)
		}
	} else {
		bot.ReplyN(line, "No quote found for id %d", qid)
	}
}
Exemplo n.º 11
0
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
		}
	}
}
Exemplo n.º 12
0
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)
	}
}
Exemplo n.º 13
0
func cd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
	if !line.Addressed {
		return
	}

	switch {
	case strings.HasPrefix(line.Args[1], "calc "):
		cd_calc(bot, line, line.Args[1][5:])
	case strings.HasPrefix(line.Args[1], "netmask "):
		s := strings.Split(line.Args[1], " ")
		if strings.Index(s[1], "/") != -1 {
			// Assume we have netmask ip/cidr
			cd_netmask_cidr(bot, line, s[1])
		} else if len(s) == 3 {
			// Assume we have netmask ip nm
			cd_netmask(bot, line, s[1], s[2])
		}
	case strings.HasPrefix(line.Args[1], "chr "):
		cd_chr(bot, line, line.Args[1][4:])
	case strings.HasPrefix(line.Args[1], "ord "):
		cd_ord(bot, line, line.Args[1][4:])
	case strings.HasPrefix(line.Args[1], "length "):
		bot.ReplyN(line, "'%s' is %d characters long",
			line.Args[1][7:], len(line.Args[1][7:]))
	case strings.HasPrefix(line.Args[1], "base "):
		s := strings.Split(line.Args[1], " ")
		cd_base(bot, line, s[1], s[2])
	}
}
Exemplo n.º 14
0
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)
}
Exemplo n.º 15
0
func fd_info(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	key := ToKey(line.Args[1], false)
	count := fd.GetCount(key)
	if count == 0 {
		bot.ReplyN(line, "I don't know anything about '%s'.", key)
		return
	}
	msgs := make([]string, 0, 10)
	if key == "" {
		msgs = append(msgs, fmt.Sprintf("In total, I know %d things.", count))
	} else {
		msgs = append(msgs, fmt.Sprintf("I know %d things about '%s'.",
			count, key))
	}
	if created := fd.GetLast("created", key); created != nil {
		c := created.Created
		msgs = append(msgs, "A factoid")
		if key != "" {
			msgs = append(msgs, fmt.Sprintf("for '%s'", key))
		}
		msgs = append(msgs, fmt.Sprintf("was last created on %s by %s,",
			c.Timestamp.Format(time.ANSIC), c.Nick))
	}
	if modified := fd.GetLast("modified", key); modified != nil {
		m := modified.Modified
		msgs = append(msgs, fmt.Sprintf("modified on %s by %s,",
			m.Timestamp.Format(time.ANSIC), m.Nick))
	}
	if accessed := fd.GetLast("accessed", key); accessed != nil {
		a := accessed.Accessed
		msgs = append(msgs, fmt.Sprintf("and accessed on %s by %s.",
			a.Timestamp.Format(time.ANSIC), a.Nick))
	}
	if info := fd.InfoMR(key); info != nil {
		if key == "" {
			msgs = append(msgs, "These factoids have")
		} else {
			msgs = append(msgs, fmt.Sprintf("'%s' has", key))
		}
		msgs = append(msgs, fmt.Sprintf(
			"been modified %d times and accessed %d times.",
			info.Modified, info.Accessed))
	}
	bot.ReplyN(line, "%s", strings.Join(msgs, " "))
}
Exemplo n.º 16
0
func sd_lines_lookup(bot *bot.Sp0rkle, sd *seenDriver, line *base.Line) {
	n := line.Nick
	if idx := strings.Index(line.Args[1], " "); idx != -1 {
		n = strings.TrimSpace(line.Args[1][idx:])
	}
	sn := sd.LinesFor(n, line.Args[0])
	if sn != nil {
		bot.ReplyN(line, "%s has said %d lines in this channel",
			sn.Nick, sn.Lines)
	}
}
Exemplo n.º 17
0
func fd_replace(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	ls := fd.Lastseen(line.Args[0], "")
	if fact := fd.GetById(ls); fact != nil {
		// Store the old factoid value
		old := fact.Value
		// Replace the value with the new one
		fact.Value = strings.TrimSpace(line.Args[1])
		// Update the Modified field
		fact.Modify(line.Storable())
		// And store the new factoid data
		if err := fd.Update(bson.M{"_id": ls}, fact); err == nil {
			bot.ReplyN(line, "'%s' was '%s', now is '%s'.",
				fact.Key, old, fact.Value)
		} else {
			bot.ReplyN(line, "I failed to replace '%s': %s", fact.Key, err)
		}
	} else {
		bot.ReplyN(line, "Whatever that was, I've already forgotten it.")
	}
}
Exemplo n.º 18
0
func fd_search(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	keys := fd.GetKeysMatching(line.Args[1])
	if keys == nil || len(keys) == 0 {
		bot.ReplyN(line, "I couldn't think of anything matching '%s'.",
			line.Args[0])
		return
	}
	// RESULTS.
	count := len(keys)
	if count > 10 {
		res := strings.Join(keys[:10], "', '")
		bot.ReplyN(line,
			"I found %d keys matching '%s', here's the first 10: '%s'.",
			count, line.Args[1], res)
	} else {
		res := strings.Join(keys, "', '")
		bot.ReplyN(line,
			"%s: I found %d keys matching '%s', here they are: '%s'.",
			count, line.Args[1], res)
	}
}
Exemplo n.º 19
0
func nd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
	nd := bot.GetDriver(driverName).(*netDriver)

	idx := strings.Index(line.Args[1], " ")
	if !line.Addressed || idx == -1 {
		return
	}
	svc, query := line.Args[1][:idx], line.Args[1][idx+1:]
	if s, ok := nd.services[svc]; ok {
		bot.ReplyN(line, "%s", s.LookupResult(query))
	}
}
Exemplo n.º 20
0
func fd_add(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	var key, val string
	if strings.Index(line.Args[1], ":=") != -1 {
		kv := strings.SplitN(line.Args[1], ":=", 2)
		key = ToKey(kv[0], false)
		val = strings.TrimSpace(kv[1])
	} else {
		// we use :is to add val = "key is val"
		kv := strings.SplitN(line.Args[1], ":is", 2)
		key = ToKey(kv[0], false)
		val = strings.Join([]string{strings.TrimSpace(kv[0]),
			"is", strings.TrimSpace(kv[1])}, " ")
	}
	n, c := line.Storable()
	fact := factoids.NewFactoid(key, val, n, c)
	if err := fd.Insert(fact); err == nil {
		count := fd.GetCount(key)
		bot.ReplyN(line, "Woo, I now know %d things about '%s'.", count, key)
	} else {
		bot.ReplyN(line, "Error storing factoid: %s.", err)
	}
}
Exemplo n.º 21
0
func cd_base(bot *bot.Sp0rkle, line *base.Line, base, num string) {
	fromto := strings.Split(base, "to")
	if len(fromto) != 2 {
		bot.ReplyN(line, "Specify base as: <from base>to<to base>")
		return
	}
	from, errf := strconv.Atoi(fromto[0])
	to, errt := strconv.Atoi(fromto[1])
	if errf != nil || errt != nil ||
		from < 2 || from > 36 || to < 2 || to > 36 {
		bot.ReplyN(line, "Either %s or %s is a bad base, must be in range 2-36",
			fromto[0], fromto[1])
		return
	}
	i, err := strconv.ParseInt(num, from, 64)
	if err != nil {
		bot.ReplyN(line, "Couldn't parse %s as a base %d integer", num, from)
		return
	}
	bot.ReplyN(line, "%s in base %d is %s in base %d",
		num, from, strconv.FormatInt(i, to), to)
}
Exemplo n.º 22
0
func fd_lookup(bot *bot.Sp0rkle, fd *factoidDriver, 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 = fd.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.Conn.Me.Nick) {
			key = strings.TrimSpace(key[:len(key)-len(bot.Conn.Me.Nick)])
			fact = fd.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
		fd.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 := fd.Update(bson.M{"_id": fact.Id}, fact); err != nil {
			bot.ReplyN(line, "I failed to update '%s' (%s): %s ",
				fact.Key, fact.Id, err)
		}

		// Apply the list of factoid plugins to the factoid value.
		val := fd.ApplyPlugins(fact.Value, line)
		switch fact.Type {
		case factoids.F_ACTION:
			bot.Conn.Action(line.Args[0], val)
		default:
			bot.Conn.Privmsg(line.Args[0], val)
		}
	}
}
Exemplo n.º 23
0
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)
	}
}
Exemplo n.º 24
0
func fd_chance(bot *bot.Sp0rkle, fd *factoidDriver, line *base.Line) {
	str := strings.TrimSpace(line.Args[1])
	var chance float64

	if strings.HasSuffix(str, "%") {
		// Handle 'chance of that is \d+%'
		if i, err := strconv.Atoi(str[:len(str)-1]); err != nil {
			bot.ReplyN(line, "'%s' didn't look like a % chance to me.", str)
			return
		} else {
			chance = float64(i) / 100
		}
	} else {
		// Assume the chance is a floating point number.
		if c, err := strconv.ParseFloat(str, 64); err != nil {
			bot.ReplyN(line, "'%s' didn't look like a chance to me.", str)
			return
		} else {
			chance = c
		}
	}

	// Make sure the chance we've parsed lies in (0.0,1.0]
	if chance > 1.0 || chance <= 0.0 {
		bot.ReplyN(line, "'%s' was outside possible chance ranges.", str)
		return
	}

	// Retrieve last seen ObjectId, replace with ""
	ls := fd.Lastseen(line.Args[0], "")
	// ok, we're good to update the chance.
	if fact := fd.GetById(ls); fact != nil {
		// Store the old chance, update with the new
		old := fact.Chance
		fact.Chance = chance
		// Update the Modified field
		fact.Modify(line.Storable())
		// And store the new factoid data
		if err := fd.Update(bson.M{"_id": ls}, fact); err == nil {
			bot.ReplyN(line, "'%s' was at %.0f%% chance, now is at %.0f%%.",
				fact.Key, old*100, chance*100)
		} else {
			bot.ReplyN(line, "I failed to replace '%s': %s", fact.Key, err)
		}
	} else {
		bot.ReplyN(line, "Whatever that was, I've already forgotten it.")
	}
}
Exemplo n.º 25
0
func sd_seen_lookup(bot *bot.Sp0rkle, sd *seenDriver, line *base.Line) {
	s := strings.Split(line.Args[1], " ")
	if len(s) > 2 {
		// Assume we have "seen <nick> <action>"
		if n := sd.LastSeenDoing(s[1], strings.ToUpper(s[2])); n != nil {
			bot.ReplyN(line, "%s", n)
			return
		}
	}
	// Not specifically asking for that action, or no matching action.
	if n := sd.LastSeen(s[1]); n != nil {
		bot.ReplyN(line, "%s", n)
		return
	}
	// No exact matches for nick found, look for possible partial matches.
	if m := sd.SeenAnyMatching(s[1]); len(m) > 0 {
		if len(m) == 1 {
			if n := sd.LastSeen(m[0]); n != nil {
				bot.ReplyN(line, "1 possible match: %s", n)
			}
		} else if len(m) > 10 {
			bot.ReplyN(line, "%d possible matches, first 10 are: %s.",
				len(m), strings.Join(m[:9], ", "))
		} else {
			bot.ReplyN(line, "%d possible matches: %s.",
				len(m), strings.Join(m, ", "))
		}
		return
	}
	// No partial matches found. Check for people playing silly buggers.
	txt := strings.Join(s[1:], " ")
	for _, w := range wittyComebacks {
		sd.l.Debug("Matching %#v...", w)
		if w.rx.MatchString(txt) {
			bot.ReplyN(line, "%s", w.resp)
			return
		}
	}
	// Ok, probably a genuine query.
	bot.ReplyN(line, "Haven't seen %s before, sorry.", txt)
}
Exemplo n.º 26
0
func ud_cache(bot *bot.Sp0rkle, ud *urlDriver, line *base.Line) {
	var u *urls.Url
	if line.Args[1] == "" {
		// assume we have been given "cache that"
		if u = ud.GetById(ud.lastseen[line.Args[0]]); u == nil {
			bot.ReplyN(line, "I seem to have forgotten what to cache")
			return
		}
		if u.CachedAs != "" {
			bot.ReplyN(line, "That was already cached as %s%s%s at %s",
				bot.Prefix, cachePath, u.CachedAs,
				u.CacheTime.Format(time.RFC1123))
			return
		}
	} else {
		url := strings.TrimSpace(line.Args[1])
		if idx := strings.Index(url, " "); idx != -1 {
			url = url[:idx]
		}
		if !util.LooksURLish(url) {
			bot.ReplyN(line, "'%s' doesn't look URLish", url)
			return
		}
		if u = ud.GetByUrl(url); u == nil {
			n, c := line.Storable()
			u = urls.NewUrl(url, n, c)
		} else if u.CachedAs != "" {
			bot.ReplyN(line, "That was already cached as %s%s%s at %s",
				bot.Prefix, cachePath, u.CachedAs,
				u.CacheTime.Format(time.RFC1123))
			return
		}
	}
	if err := ud.Cache(u); err != nil {
		bot.ReplyN(line, "Failed to store cached url: %s", err)
		return
	}
	bot.ReplyN(line, "%s cached as %s%s%s",
		u.Url, bot.Prefix, cachePath, u.CachedAs)
}
Exemplo n.º 27
0
func ud_shorten(bot *bot.Sp0rkle, ud *urlDriver, line *base.Line) {
	var u *urls.Url
	if line.Args[1] == "" {
		// assume we have been given "shorten that"
		if u = ud.GetById(ud.lastseen[line.Args[0]]); u == nil {
			bot.ReplyN(line, "I seem to have forgotten what to shorten")
			return
		}
		if u.Shortened != "" {
			bot.ReplyN(line, "That was already shortened as %s%s%s",
				bot.Prefix, shortenPath, u.Shortened)
			return
		}
	} else {
		url := strings.TrimSpace(line.Args[1])
		if idx := strings.Index(url, " "); idx != -1 {
			url = url[:idx]
		}
		if !util.LooksURLish(url) {
			bot.ReplyN(line, "'%s' doesn't look URLish", url)
			return
		}
		if u = ud.GetByUrl(url); u == nil {
			n, c := line.Storable()
			u = urls.NewUrl(url, n, c)
		} else if u.Shortened != "" {
			bot.ReplyN(line, "That was already shortened as %s%s%s",
				bot.Prefix, shortenPath, u.Shortened)
			return
		}
	}
	if err := ud.Shorten(u); err != nil {
		bot.ReplyN(line, "Failed to store shortened url: %s", err)
		return
	}
	bot.ReplyN(line, "%s shortened to %s%s%s",
		u.Url, bot.Prefix, shortenPath, u.Shortened)
}
Exemplo n.º 28
0
func ud_find(bot *bot.Sp0rkle, ud *urlDriver, line *base.Line) {
	if u := ud.GetRand(line.Args[1]); u != nil {
		bot.ReplyN(line, "%s", u)
	}
}