本文整理匯總了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)
}
}
示例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)
}
}
示例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)
}
示例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))
}
示例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)
}
}
示例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)))
}
示例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)
}
}
示例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.")
}
}
示例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))
}
}
示例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)
}
}
示例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
}
}
}
示例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)
}
}
示例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])
}
}
示例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)
}
示例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, " "))
}