本文整理匯總了Golang中github.com/nlopes/slack.RTM.GetUserInfo方法的典型用法代碼示例。如果您正苦於以下問題:Golang RTM.GetUserInfo方法的具體用法?Golang RTM.GetUserInfo怎麽用?Golang RTM.GetUserInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nlopes/slack.RTM
的用法示例。
在下文中一共展示了RTM.GetUserInfo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleMessage
func handleMessage(rtm *slack.RTM) {
// 會話
session := new(plugin.Session)
session.ResetSession()
// 注冊命令處理器
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Help))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Hello))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Shell))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Time))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Mail))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Service))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Nginx))
plugin.BotCommands = append(plugin.BotCommands, new(plugin.Joke))
user, err := rtm.GetUserInfo(botID)
if err != nil {
fmt.Println(err)
return
}
botName := user.Profile.FirstName + " " + user.Profile.LastName
for {
select {
case msg := <-rtm.IncomingEvents:
fmt.Print("Event Received: ")
switch evt := msg.Data.(type) {
case *slack.HelloEvent:
// Ignore hello
case *slack.ConnectedEvent:
fmt.Println("Info:", evt.Info)
fmt.Println("Connection counter:", evt.ConnectionCount)
rtm.SendMessage(rtm.NewOutgoingMessage("Hello world", "#general"))
case *slack.MessageEvent:
fmt.Printf("Message: %v\n", evt)
if evt.Channel == botChannelID && evt.Team == mxTeamID {
text, sendToMXBot := checkMessage(evt.Text)
if sendToMXBot && len(text) > 0 {
go handleCommand(rtm, session, botName, evt.Channel, evt.User, strings.TrimSpace(text))
}
} else if evt.Channel == botDMChannelID && evt.Team == mxTeamID {
go handleCommand(rtm, session, botName, evt.Channel, evt.User, strings.TrimSpace(evt.Text))
}
case *slack.ChannelJoinedEvent:
// Ignore
case *slack.PresenceChangeEvent:
fmt.Printf("Presence Change: %v\n", evt)
case *slack.LatencyReport:
fmt.Printf("Current latency: %v\n", evt.Value)
case *slack.RTMError:
fmt.Printf("Error: %s\n", evt.Error())
case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials")
return
default:
// Ignore other events...
}
}
}
}
示例2: flattenSlackMessage
func flattenSlackMessage(rtm *slack.RTM, text string) string {
text = slackLink1Regex.ReplaceAllString(text, "$1")
text = slackLink2Regex.ReplaceAllString(text, "$1")
text = slackLink3Regex.ReplaceAllString(text, "$1")
text = slackActionRegex.ReplaceAllString(text, "@$1")
text = slackEmojiRegex.ReplaceAllStringFunc(text, func(text string) string {
if emoji, ok := emojis[text[1:len(text)-1]]; ok {
return emoji
}
return text
})
text = slackReference1Regex.ReplaceAllString(text, "$1$4")
text = slackReference2Regex.ReplaceAllStringFunc(text, func(text string) string {
switch text[:2] {
case "<#":
ch, err := rtm.GetChannelInfo(text[2 : len(text)-1])
if err == nil {
return "#" + ch.Name
}
case "<@":
user, err := rtm.GetUserInfo(text[2 : len(text)-1])
if err == nil {
return "@" + user.Name
}
}
return text
})
text = html.UnescapeString(text)
return text
}