本文整理匯總了Golang中github.com/fluffle/goirc/client.Conn.AddHandler方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.AddHandler方法的具體用法?Golang Conn.AddHandler怎麽用?Golang Conn.AddHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/goirc/client.Conn
的用法示例。
在下文中一共展示了Conn.AddHandler方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Auth
func Auth(conn *irc.Conn, channel, secret string) {
conn.AddHandler("353", func(c *irc.Conn, l *irc.Line) { // NAMES
if l.Args[2] != channel {
return
}
for _, nick := range strings.Split(l.Args[3], " ", -1) {
if !strings.HasPrefix(nick, "@") {
continue
}
nick = nick[1:]
hash := makeHash(channel, c.Me.Nick, nick, secret)
c.Privmsg(nick, ".authop "+channel+" "+hash)
}
})
conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
if strings.HasPrefix(l.Args[0], "#") {
return
}
p := strings.Split(l.Args[1], " ", -1)
if len(p) != 3 || p[0] != ".authop" || p[1] != channel {
return
}
if p[2] != makeHash(channel, l.Nick, c.Me.Nick, secret) {
return
}
c.Mode(channel, l.Nick+" +o")
})
}
示例2: PlusOne
func PlusOne(conn *irc.Conn, channel string) {
AutoJoin(conn, channel)
conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
if l.Args[0] != channel {
return
}
m := l.Args[1]
if m == ".scores" {
plusOneScores(c, channel)
return
}
if !plusOneRe.MatchString(m) {
return
}
nick := strings.Split(m, ":", 2)[0]
if c.GetNick(nick) == nil {
return
}
nick = Canonical(nick)
if len(nick) == 0 {
return
}
n := 1
if m[len(m)-2] == '-' {
n = -1
}
plusOneCount(nick, n)
})
}
示例3: addWhoHandlers
func addWhoHandlers(irc *client.Conn) {
if !flag.Parsed() {
flag.Parse()
}
irc.AddHandler("352", whoHandler)
irc.AddHandler("315", whoHandler)
return
}
示例4: AutoJoin
func AutoJoin(conn *irc.Conn, channel string) {
autoJoinLock.Lock()
defer autoJoinLock.Unlock()
if autoJoinChannels[channel] {
return
}
autoJoinChannels[channel] = true
conn.AddHandler("CONNECTED", func(c *irc.Conn, l *irc.Line) {
conn.Join(channel)
})
}
示例5: Connect
func (s InBandSource) Connect(c *irc.Conn) (err error) {
if c.Connected {
return nil
}
c.AddHandler(irc.CONNECTED, func(c *irc.Conn, line *irc.Line) {
c.Join(s.Host().Channel)
})
if err := c.Connect(s.Host().Server); err != nil {
return err
}
return nil
}
示例6: YouTuber
func YouTuber(conn *irc.Conn, channel string) {
AutoJoin(conn, channel)
conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
if l.Args[0] != channel {
return
}
m := l.Args[1]
url := youtubeRe.FindStringSubmatch(m)
if url == nil {
return
}
q, _ := http.ParseQuery(url[1])
key, found := q["v"]
if !found {
return
}
printMetadataForKey(c, channel, key[0])
})
}
示例7: addNickHandlers
func addNickHandlers(irc *client.Conn) {
if !flag.Parsed() {
flag.Parse()
}
irc.AddHandler("QUIT", dropIdentifiedCache)
irc.AddHandler("307", isIdentified)
irc.AddHandler("330", isIdentified)
irc.AddHandler("318", isIdentified)
}
示例8: setupClient
func setupClient(c *irc.Conn, chConnected chan bool) {
c.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
chConnected <- true
})
c.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
chConnected <- false
})
c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
if len(line.Args) < 2 || !strings.HasPrefix(line.Args[1], "!") {
return
}
to := line.Args[0]
sender := to
if to == c.Me.Nick {
// TODO: check if sender is in main chan, else return
log.Println("Got ! via PM from " + line.Src)
sender = line.Src // replies go via PM too.
} else {
log.Println("Got ! via chan: " + line.Args[0] + " from " + line.Src)
}
log.Println(line.Args)
switch line.Args[0] {
case "!join":
if len(line.Args) == 2 {
c.Join(line.Args[1])
} else if len(line.Args) == 3 {
c.Join(line.Args[1] + " " + line.Args[2])
} else {
c.Privmsg(sender, "Usage: !join #chan or !join #chan key")
}
case "!part":
if len(line.Args) == 2 {
c.Part(line.Args[1])
} else {
c.Privmsg(sender, "Usage: !part #chan")
}
default:
c.Privmsg(sender, "Invalid command: "+strings.Join(line.Args[1:], " "))
return
}
})
}
示例9: Register
func (plugin *Plugin) Register(conn *irc.Conn) {
conn.AddHandler("PRIVMSG", respond)
}