本文整理匯總了Golang中github.com/kballard/gocallback/callback.Registry類的典型用法代碼示例。如果您正苦於以下問題:Golang Registry類的具體用法?Golang Registry怎麽用?Golang Registry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Registry類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
channels = make(map[string]map[string]Line)
reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
if line.Src.Nick == "" {
return
}
if matches := sedRegex.FindStringSubmatch(text); matches != nil {
processMatches(conn, line, dst, matches)
} else {
lines := channels[dst]
if lines == nil {
lines = make(map[string]Line)
channels[dst] = lines
}
lines[line.Src.Nick] = Line{Msg: text, Action: false}
}
})
reg.AddCallback("ACTION", func(conn *irc.Conn, line irc.Line, dst, text string, isPrivate bool) {
if line.Src.Nick == "" || isPrivate {
return
}
if matches := sedRegex.FindStringSubmatch(text); matches != nil {
processMatches(conn, line, dst, matches)
} else {
lines := channels[dst]
if lines == nil {
lines = make(map[string]Line)
channels[dst] = lines
}
lines[line.Src.Nick] = Line{Msg: text, Action: true}
}
})
return nil
}
示例2: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
reply := dst
if dst == conn.Me().Nick {
reply = line.Src.Nick
}
if reply == "" {
// what, the server sent us a privmsg?
return
}
// allow voidbot to be addressed directly, and modify the response
prefix := ""
isDirected := false
if strings.HasPrefix(text, fmt.Sprintf("%s: ", conn.Me().Nick)) {
text = text[len(conn.Me().Nick)+2:]
prefix = line.Src.Nick + ": "
isDirected = true
}
// implement super awesome reaction logic here
if strings.ToLower(text) == "herp" {
plugin.Conn(conn).Notice(reply, prefix+utils.MatchCase("derp", text))
} else if strings.ToLower(text) == "is me1000 drunk?" || (line.Src.Nick == "Me1000" && strings.ToLower(text) == "am i drunk?") {
plugin.Conn(conn).Notice(reply, prefix+randResponse([]string{"yes", "always"}))
} else if isDirected && strings.ToLower(text) == "botsnack" {
plugin.Conn(conn).Notice(reply, prefix+randResponse([]string{"yum", "nom nom", "om nom nom"}))
} else if isDirected && text == "<3" {
plugin.Conn(conn).Notice(reply, prefix+"<3")
}
})
return nil
}
示例3: setupVine
func setupVine(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Scheme == "http" || url.Scheme == "https" {
if url.Host == "vine.co" || url.Host == "www.vine.co" {
if url.Fragment != "noquote" {
go processVineURL(plugin.Conn(conn), line, dst, url)
}
}
}
})
return nil
}
示例4: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd, arg, reply string, isPrivate bool) {
if cmd == "alpha" {
arg = strings.TrimSpace(arg)
if arg == "" {
plugin.Conn(conn).Notice(reply, "!alpha requires an argument")
} else {
go runQuery(plugin.Conn(conn), arg, reply)
}
}
})
return nil
}
示例5: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Scheme == "http" || url.Scheme == "https" {
if url.Host == "alpha.app.net" {
comps := strings.Split(strings.TrimLeft(url.Path, "/"), "/")
if len(comps) > 2 && comps[1] == "post" {
id := comps[2]
go fetchADNPost(plugin.Conn(conn), line, dst, id)
}
}
}
})
return nil
}
示例6: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd string, arg string, reply string, isPrivate bool) {
if cmd == "dogecoin" && !isPrivate {
arg = strings.ToLower(strings.TrimSpace(arg))
if arg == "" {
msg := "dogecoin is: "
if enabled {
msg += "ON"
} else {
msg += "OFF"
}
plugin.Conn(conn).Notice(reply, msg)
} else if arg == "on" || arg == "off" {
if line.Src.Nick == "Me1000" {
plugin.Conn(conn).Notice(reply, "no")
} else if arg == "on" {
enabled = true
plugin.Conn(conn).Notice(reply, "dogecoin enabled")
} else if arg == "off" {
enabled = false
plugin.Conn(conn).Notice(reply, "dogecoin disabled")
}
} else {
plugin.Conn(conn).Notice(reply, "derp?")
}
}
})
reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
if enabled {
derptext := utils.ReplaceAllFold(text, "bitcoin", "dogecoin")
if derptext != "" {
plugin.Conn(conn).Notice(dst, derptext)
return
}
if subs := btcRegex.FindStringSubmatch(text); subs != nil {
// we found a construct like "0.01 BTC"
if val, err := strconv.ParseFloat(subs[1], 64); err == nil {
const kUpperLimit = 1000
exchangeRate := float64(rand.Intn(kUpperLimit*100)) / 100.0
val *= exchangeRate
val = math.Floor(val*100.0) / 100.0
msg := fmt.Sprintf("%s: that's almost $%.2f!", line.Src.Nick, val)
plugin.Conn(conn).Notice(dst, msg)
}
}
}
})
return nil
}
示例7: setupTweet
func setupTweet(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Scheme == "http" || url.Scheme == "https" {
if url.Host == "twitter.com" || url.Host == "www.twitter.com" {
if url.Fragment != "noquote" {
username, tweet_id := parseTwitterURL(url)
if username != "" && tweet_id != "" {
go processTweetURL(plugin.Conn(conn), line, dst, username, tweet_id)
}
}
}
}
})
return nil
}
示例8: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Scheme == "http" || url.Scheme == "https" {
if url.Host == "youtube.com" || url.Host == "www.youtube.com" {
if url.Path == "/watch" {
if key, ok := url.Query()["v"]; ok && key != nil {
go handleYoutubeVideo(plugin.Conn(conn), line, dst, key[0], url.Fragment)
}
}
} else if url.Host == "youtu.be" {
go handleYoutubeVideo(plugin.Conn(conn), line, dst, strings.TrimLeft(url.Path, "/"), url.Fragment)
}
}
})
return nil
}
示例9: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Scheme == "http" || url.Scheme == "https" {
if url.Host == "vimeo.com" || url.Host == "www.vimeo.com" {
path := url.Path
if strings.HasPrefix(path, "/") {
path = path[1:]
}
if len(path) > 0 && strings.IndexFunc(path, func(r rune) bool { return !unicode.IsDigit(r) }) == -1 {
go handleVimeo(plugin.Conn(conn), line, dst, path)
}
}
}
})
return nil
}
示例10: setup
func setup(reg *callback.Registry, config map[string]interface{}) error {
reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
if matches := stockRegex.FindAllString(text, -1); matches != nil {
for i, match := range matches {
matches[i] = match[1:] // trim off the $
}
if dst == conn.Me().Nick {
dst = line.Src.Nick
}
if dst == "" {
// wtf?
return
}
go queryStocks(matches, plugin.Conn(conn), dst)
}
})
return nil
}
示例11: setupFlickr
func setupFlickr(reg *callback.Registry, config map[string]interface{}) error {
if key, ok := config["api_key"].(string); ok {
api_key = key
} else {
// can't do much without an API key
return nil
}
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
if url.Host == "flickr.com" || url.Host == "www.flickr.com" {
if photo_id, set_id, ok := parseFlickrURL(url); ok {
if photo_id != "" {
go processFlickrPhoto(plugin.Conn(conn), line, dst, photo_id)
} else {
go processFlickrSet(plugin.Conn(conn), line, dst, set_id)
}
}
}
})
return nil
}
示例12: setupURLs
func setupURLs(reg *callback.Registry, config map[string]interface{}) error {
var err error
historyDB, err = database.Open("sqlite3", "./history.db")
if err != nil {
return err
}
sqls := []string{
"CREATE TABLE IF NOT EXISTS seen (id integer not null primary key, url text not null, nick text, src text not null, dst text not null, timestamp datetime not null)",
"CREATE INDEX IF NOT EXISTS url_idx ON seen (url, dst)",
}
for _, sqlstr := range sqls {
_, err = historyDB.Exec(sqlstr)
if err != nil {
return err
}
}
reg.AddCallback("PRIVMSG", func(conn *irc.Conn, line irc.Line, dst, text string) {
matches := URLRegex.FindAllStringSubmatch(text, -1)
if matches != nil {
for _, submatches := range matches {
urlStr := submatches[1]
if u, err := url.Parse(urlStr); err == nil && u.Host != "" {
reg.Dispatch("URL", conn, line, dst, u)
}
}
}
})
reg.AddCallback("URL", func(conn *irc.Conn, line irc.Line, dst string, url *url.URL) {
handleURL(conn, historyDB, line, dst, url)
})
reg.AddCallback("COMMAND", func(conn *irc.Conn, line irc.Line, cmd, arg, dst string, isPrivate bool) {
if cmd == "urls" {
handleCommand(conn, historyDB, line, arg, dst, isPrivate)
}
})
return nil
}