本文整理匯總了Golang中github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle類的典型用法代碼示例。如果您正苦於以下問題:Golang Sp0rkle類的具體用法?Golang Sp0rkle怎麽用?Golang Sp0rkle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Sp0rkle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sd_record_kick
func sd_record_kick(bot *bot.Sp0rkle, line *base.Line) {
sd := bot.GetDriver(driverName).(*seenDriver)
n, c := line.Storable()
kn := db.StorableNick{Nick: line.Args[1]}
// SeenNickFromLine doesn't work with the hacks for KICKING and KICKED
// First, handle KICKING
kr := sd.LastSeenDoing(line.Nick, "KICKING")
if kr == nil {
kr = seen.SawNick(n, c, "KICKING", line.Args[2])
} else {
kr.StorableNick, kr.StorableChan = n, c
kr.Timestamp, kr.Text = time.Now(), line.Args[2]
}
kr.OtherNick = kn
_, err := sd.Upsert(kr.Index(), kr)
if err != nil {
bot.Reply(line, "Failed to store seen data: %v", err)
}
// Now, handle KICKED
ke := sd.LastSeenDoing(line.Args[1], "KICKED")
if ke == nil {
ke = seen.SawNick(kn, c, "KICKED", line.Args[2])
} else {
ke.StorableNick, ke.StorableChan = kn, c
ke.Timestamp, ke.Text = time.Now(), line.Args[2]
}
ke.OtherNick = n
_, err = sd.Upsert(ke.Index(), ke)
if err != nil {
bot.Reply(line, "Failed to store seen data: %v", err)
}
}
示例2: 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)
}
示例3: 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)
}
}
示例4: 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
}
}
}
示例5: 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)
}
}
示例6: 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))
}
示例7: 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)
}
}
示例8: 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)))
}
示例9: sd_record_pm
func sd_record_pm(bot *bot.Sp0rkle, line *base.Line) {
sd := bot.GetDriver(driverName).(*seenDriver)
sn := sd.SeenNickFromLine(line)
sn.Text = line.Args[1]
_, err := sd.Upsert(sn.Index(), sn)
if err != nil {
bot.Reply(line, "Failed to store seen data: %v", err)
}
}
示例10: 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)
}
}
示例11: nd_privmsg
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))
}
}
示例12: sd_record_chan
func sd_record_chan(bot *bot.Sp0rkle, line *base.Line) {
sd := bot.GetDriver(driverName).(*seenDriver)
sn := sd.SeenNickFromLine(line)
if len(line.Args) > 1 {
// If we have a PART message
sn.Text = line.Args[1]
}
_, err := sd.Upsert(sn.Index(), sn)
if err != nil {
bot.Reply(line, "Failed to store seen data: %v", err)
}
}
示例13: 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))
}
}
示例14: 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.")
}
}
示例15: 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])
}
}