当前位置: 首页>>代码示例>>Golang>>正文


Golang Sp0rkle.ReplyN方法代码示例

本文整理汇总了Golang中github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle.ReplyN方法的典型用法代码示例。如果您正苦于以下问题:Golang Sp0rkle.ReplyN方法的具体用法?Golang Sp0rkle.ReplyN怎么用?Golang Sp0rkle.ReplyN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle的用法示例。


在下文中一共展示了Sp0rkle.ReplyN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cd_calc

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:7,代码来源:handlers.go

示例2: fd_literal

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:26,代码来源:handlers.go

示例3: cd_netmask

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)
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:29,代码来源:handlers.go

示例4: cd_ord

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))
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:8,代码来源:handlers.go

示例5: cd_netmask_cidr

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:9,代码来源:handlers.go

示例6: cd_chr

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)))
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:9,代码来源:handlers.go

示例7: qd_add

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:10,代码来源:handlers.go

示例8: fd_delete

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.")
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:14,代码来源:handlers.go

示例9: dd_privmsg

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))
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:14,代码来源:handlers.go

示例10: qd_delete

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:16,代码来源:handlers.go

示例11: ud_scan

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
		}
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:26,代码来源:handlers.go

示例12: qd_fetch

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)
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:16,代码来源:handlers.go

示例13: cd_privmsg

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])
	}
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:29,代码来源:handlers.go

示例14: qd_lookup

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)
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:17,代码来源:handlers.go

示例15: fd_info

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, " "))
}
开发者ID:b33f,项目名称:sp0rkle,代码行数:45,代码来源:handlers.go


注:本文中的github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle.ReplyN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。