本文整理汇总了Golang中github.com/thoj/go-ircevent.Connection.Join方法的典型用法代码示例。如果您正苦于以下问题:Golang Connection.Join方法的具体用法?Golang Connection.Join怎么用?Golang Connection.Join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/thoj/go-ircevent.Connection
的用法示例。
在下文中一共展示了Connection.Join方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WelcomeCallback
// WelcomeCallback is a PrivMsgCallback for the welcome event 001, join channels when we're logged in
func WelcomeCallback(con *irc.Connection) {
con.AddCallback("001", func(e *irc.Event) {
con.Privmsgf("NickServ", "identify %s", config.IRCNickPass)
time.Sleep(time.Second * 15) // Need to wait a little for the registration to take effect
for _, room := range config.IRCChannels {
con.Join(room)
log.Printf("Connected to channel %s\n", room)
}
})
}
示例2: main
func main() {
var (
irc *goirc.Connection
err error
)
var configFile = flag.String("c", "r2d2.cfg", "Load configuration from file")
flag.Parse()
_, err = os.Stat(*configFile)
if err != nil {
log.Fatal("%v", err)
os.Exit(1)
}
err = gcfg.ReadFileInto(&cfg, *configFile)
if err != nil {
log.Fatal("Error in configuration file: %v", err)
os.Exit(1)
}
irc = goirc.IRC(cfg.Irc.Nick, cfg.Irc.Nick)
irc.UseTLS = cfg.Irc.TLS
irc.VerboseCallbackHandler = cfg.Irc.Debug
irc.Debug = cfg.Irc.Debug
err = irc.Connect(cfg.Irc.Server)
if err != nil {
log.Fatal("Connection to IRC server failed: %v", err)
os.Exit(1)
}
// block while performing authentication
handleAuth(irc)
// we are identified, let's continue
if cfg.Irc.ChannelPass != "" {
// if a channel pass is used, craft a join command
// of the form "&<channel>; <key>"
irc.Join(cfg.Irc.Channel + " " + cfg.Irc.ChannelPass)
} else {
irc.Join(cfg.Irc.Channel)
}
if cfg.Irc.Debug {
irc.Privmsg(cfg.Irc.Channel, "beep beedibeep dibeep")
}
go watchGithub(irc)
go watchUntappd(irc)
go fetchPageTitles(irc)
initMaxmind()
// add callback that captures messages sent to bot
terminate := make(chan bool)
irc.AddCallback("PRIVMSG", func(e *goirc.Event) {
re := regexp.MustCompile("^" + cfg.Irc.Nick + ":(.+)$")
if re.MatchString(e.Message()) {
parsed := re.FindStringSubmatch(e.Message())
if len(parsed) != 2 {
return
}
req := strings.Trim(parsed[1], " ")
resp := handleRequest(e.Nick, req, irc)
if resp != "" {
irc.Privmsgf(cfg.Irc.Channel, "%s: %s", e.Nick, resp)
}
}
})
<-terminate
irc.Loop()
irc.Disconnect()
}