本文整理匯總了Golang中github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle.GetDriver方法的典型用法代碼示例。如果您正苦於以下問題:Golang Sp0rkle.GetDriver方法的具體用法?Golang Sp0rkle.GetDriver怎麽用?Golang Sp0rkle.GetDriver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/sp0rkle/sp0rkle/bot.Sp0rkle
的用法示例。
在下文中一共展示了Sp0rkle.GetDriver方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: qd_privmsg
func qd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
qd := bot.GetDriver(driverName).(*quoteDriver)
if !line.Addressed {
return
}
nl := line.Copy()
switch {
// Quote add: qadd | quote add | add quote
case util.StripAnyPrefix(&nl.Args[1], []string{"quote add ", "qadd ", "add quote "}):
qd_add(bot, qd, nl)
// Quote delete: qdel | quote del | del quote #?QID
case util.StripAnyPrefix(&nl.Args[1], []string{"quote del ", "qdel ", "del quote "}):
// Strip optional # before qid
if nl.Args[1][0] == '#' {
nl.Args[1] = nl.Args[1][1:]
}
qd_delete(bot, qd, nl)
// Quote lookup: quote #QID
case util.StripAnyPrefix(&nl.Args[1], []string{"quote #"}):
qd_fetch(bot, qd, nl)
// Quote lookup: quote | quote regex
case strings.ToLower(nl.Args[1]) == "quote":
nl.Args[1] = ""
fallthrough
// This needs to come after the other cases as it will strip just "quote "
case util.StripAnyPrefix(&nl.Args[1], []string{"quote "}):
qd_lookup(bot, qd, nl)
}
}
示例2: ud_privmsg
func ud_privmsg(bot *bot.Sp0rkle, line *base.Line) {
ud := bot.GetDriver(driverName).(*urlDriver)
// If we're not being addressed directly, short-circuit to scan.
if !line.Addressed {
ud_scan(bot, ud, line)
return
}
nl := line.Copy()
switch {
case util.StripAnyPrefix(&nl.Args[1],
[]string{"url find ", "urlfind ", "url search ", "urlsearch "}):
ud_find(bot, ud, nl)
case util.HasAnyPrefix(nl.Args[1], []string{"random url", "randurl"}):
nl.Args[1] = ""
ud_find(bot, ud, nl)
case util.StripAnyPrefix(&nl.Args[1],
[]string{"shorten that", "shorten"}):
ud_shorten(bot, ud, nl)
case util.StripAnyPrefix(&nl.Args[1],
[]string{"cache that", "save that", "cache ", "save "}):
ud_cache(bot, ud, nl)
default:
ud_scan(bot, ud, line)
}
}
示例3: 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)
}
}
示例4: 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)
}
}
示例5: sd_record_nick
func sd_record_nick(bot *bot.Sp0rkle, line *base.Line) {
sd := bot.GetDriver(driverName).(*seenDriver)
sn := sd.SeenNickFromLine(line)
sn.Chan = ""
sn.Text = line.Args[0]
_, err := sd.Upsert(sn.Index(), sn)
if err != nil {
// We don't have anyone to reply to in this case, so log instead.
sd.l.Warn("Failed to store seen data: %v", err)
}
}
示例6: 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))
}
}
示例7: 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)
}
}
示例8: sd_privmsg
func sd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
if !line.Addressed {
return
}
sd := bot.GetDriver(driverName).(*seenDriver)
switch {
case strings.HasPrefix(line.Args[1], "seen "):
sd_seen_lookup(bot, sd, line)
case strings.HasPrefix(line.Args[1], "lines"):
sd_lines_lookup(bot, sd, line)
case util.HasAnyPrefix(line.Args[1], []string{"topten", "top10"}):
sd_topten(bot, sd, line)
}
}
示例9: fd_privmsg
func fd_privmsg(bot *bot.Sp0rkle, line *base.Line) {
fd := bot.GetDriver(driverName).(*factoidDriver)
// If we're not being addressed directly, short-circuit to lookup.
if !line.Addressed {
fd_lookup(bot, fd, line)
return
}
nl := line.Copy()
// Test for various possible courses of action.
switch {
// Factoid add: 'key := value' or 'key :is value'
case util.ContainsAny(nl.Args[1], []string{":=", ":is"}):
fd_add(bot, fd, nl)
// Factoid delete: 'forget|delete that' => deletes fd.lastseen[chan]
case util.HasAnyPrefix(nl.Args[1], []string{"forget that", "delete that"}):
fd_delete(bot, fd, nl)
// Factoid replace: 'replace that with' => updates fd.lastseen[chan]
case util.StripAnyPrefix(&nl.Args[1], []string{"replace that with "}):
fd_replace(bot, fd, nl)
// Factoid chance: 'chance of that is' => sets chance of fd.lastseen[chan]
case util.StripAnyPrefix(&nl.Args[1], []string{"chance of that is "}):
fd_chance(bot, fd, nl)
// Factoid literal: 'literal key' => info about factoid
case util.StripAnyPrefix(&nl.Args[1], []string{"literal "}):
fd_literal(bot, fd, nl)
// Factoid search: 'fact search regexp' => list of possible key matches
case util.StripAnyPrefix(&nl.Args[1], []string{"fact search "}):
fd_search(bot, fd, nl)
// Factoid info: 'fact info key' => some information about key
case util.StripAnyPrefix(&nl.Args[1], []string{"fact info "}):
fd_info(bot, fd, nl)
// If we get to here, none of the other FD command possibilities
// have matched, so try a lookup...
default:
fd_lookup(bot, fd, nl)
}
}
示例10: sd_smoke
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)
}
}
示例11: sd_record_lines
func sd_record_lines(bot *bot.Sp0rkle, line *base.Line) {
sd := bot.GetDriver(driverName).(*seenDriver)
sn := sd.LinesFor(line.Nick, line.Args[0])
if sn == nil {
n, c := line.Storable()
sn = seen.SawNick(n, c, "LINES", "")
}
sn.Lines++
for _, n := range milestones {
if sn.Lines == n {
bot.Reply(line, "%s has said %d lines in this channel and"+
"should now shut the fuck up and do something useful",
line.Nick, sn.Lines)
}
}
_, err := sd.Upsert(sn.Index(), sn)
if err != nil {
bot.Reply(line, "Failed to store seen data: %v", err)
}
}
示例12: fd_action
func fd_action(bot *bot.Sp0rkle, line *base.Line) {
fd := bot.GetDriver(driverName).(*factoidDriver)
// Actions just trigger a lookup.
fd_lookup(bot, fd, line)
}