本文整理匯總了Golang中github.com/fluffle/goirc/client.Conn.StateTracker方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.StateTracker方法的具體用法?Golang Conn.StateTracker怎麽用?Golang Conn.StateTracker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/goirc/client.Conn
的用法示例。
在下文中一共展示了Conn.StateTracker方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handle_command
func handle_command(conn *irc.Conn, line *irc.Line, args []string) {
command := args[0][len(RC.CmdPrefix):]
args = args[1:]
st := conn.StateTracker()
authed := RC.Authed[line.Nick]
if line.Nick == RC.Owner && authed {
// Owner-only commands
if command == "mock" {
for _, n := range args {
_, is_on := st.IsOn(RC.Channel, n)
if is_on {
RC.Mocking[n] = true
conn.Privmsg(RC.Channel, "Now mocking "+n)
}
}
} else if command == "unmock" {
for _, n := range args {
if RC.Mocking[n] {
RC.Mocking[n] = false
conn.Privmsg(RC.Channel, "No longer mocking "+n)
}
}
} else if command == "shorten" {
fmt.Println("unimplemented")
} else if command == "snoop" {
fmt.Println("unimplemented")
}
} else if (RC.Ops[line.Nick] || line.Nick == RC.Owner) && authed {
// Ops-level commands
if command == "poop" {
conn.Privmsg(RC.Channel, "poop")
}
} else if command == "identify" && !line.Public() {
fmt.Println("User " + line.Nick + " attempting to auth...")
h := sha256.New()
h.Write([]byte(args[0]))
pwd_hash := hex.EncodeToString(h.Sum(nil))
if (line.Nick == RC.Owner || RC.Ops[line.Nick]) && RC.Password == pwd_hash {
fmt.Println("Auth succeeded for " + line.Nick)
RC.Authed[line.Nick] = true
conn.Privmsg(line.Nick, "You're authenticated now.")
} else {
fmt.Println("WARNING: Auth failed for " + line.Nick + "!")
conn.Privmsg(line.Nick, "You fucked up.")
}
}
}
示例2: collectorHandler
func (k *KarmaModule) collectorHandler(conn *irc.Conn, msg *Privmsg, match []string) {
nickStr := strings.TrimSpace(match[1])
if msg.Nick == nickStr {
msg.RespondToNick(conn, "You can't karama yourself, you'll go blind!")
return
}
nick := conn.StateTracker().GetNick(nickStr)
if nick == nil {
log.WithFields(logrus.Fields{
"srcNick": msg.Nick,
"dstNick": nickStr,
"channel": msg.Channel,
}).Debug("Karma: unknown nick")
return
}
_, isOnChan := nick.IsOnStr(msg.Channel)
if !isOnChan {
log.WithFields(logrus.Fields{
"srcNick": msg.Nick,
"dstNick": nickStr,
"channel": msg.Channel,
}).Debug("Karma: nick not in the current channel")
return
}
log.WithFields(logrus.Fields{
"srcNick": msg.Nick,
"dstNick": nickStr,
"channel": msg.Channel,
"direction": match[2],
}).Info("Karma: Updating nick")
var karma Karma
db.Where(Karma{Nick: nick.Nick}).FirstOrInit(&karma)
if match[2] == "++" {
karma.Count++
} else {
karma.Count--
}
db.Save(&karma)
}
示例3: setTopic
func setTopic(conn *irc.Conn, channel string) {
defer func() {
if r := recover(); r != nil {
log.Printf("most likely coding error: %v", r)
}
}()
topic := conn.StateTracker().GetChannel(channel).Topic
newtopic := insertNextEvent(topic)
newtopic = advanceDates(newtopic)
if topic == newtopic {
return
}
log.Printf("%s OLD TOPIC: %s", channel, topic)
log.Printf("%s NEW TOPIC: %s", channel, newtopic)
conn.Topic(channel, newtopic)
}