• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang callback.Registry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
}
开发者ID:kballard,项目名称:voidbot,代码行数:34,代码来源:sed.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:31,代码来源:reaction.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:12,代码来源:vine.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:13,代码来源:alpha.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:14,代码来源:appdotnet.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:49,代码来源:dogecoin.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:15,代码来源:tweet.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:16,代码来源:youtube.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:16,代码来源:vimeo.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:18,代码来源:stocks.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:20,代码来源:flickr.go


示例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
}
开发者ID:kballard,项目名称:voidbot,代码行数:42,代码来源:urls.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang httprpc.CallJson函数代码示例发布时间:2022-05-23
下一篇:
Golang cascadia.MustCompile函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap