本文整理匯總了Golang中github.com/nlopes/slack.Slack.GetUserInfo方法的典型用法代碼示例。如果您正苦於以下問題:Golang Slack.GetUserInfo方法的具體用法?Golang Slack.GetUserInfo怎麽用?Golang Slack.GetUserInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nlopes/slack.Slack
的用法示例。
在下文中一共展示了Slack.GetUserInfo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PipeSlackToIRC
func PipeSlackToIRC(slackAPI *slack.Slack, ircLink *irc.Connection) {
//sender := make(chan slack.OutgoingMessage)
receiver := make(chan slack.SlackEvent)
wsAPI, err := slackAPI.StartRTM("", "http://example.com")
if err != nil {
log.Fatalf("StartRTM() error: %s", err)
}
go wsAPI.HandleIncomingEvents(receiver)
go wsAPI.Keepalive(10 * time.Second)
for {
msg := <-receiver
switch msg.Data.(type) {
case *slack.MessageEvent:
msgEvent := msg.Data.(*slack.MessageEvent)
// Ignore bot messages, including our own
if msgEvent.BotId != "" {
break
}
fmt.Printf("Message: %s\n", msgEvent)
user, err := slackAPI.GetUserInfo(msgEvent.UserId)
if err != nil {
log.Printf("GetUserInfo(): %s\n", err)
break
}
msg := fmt.Sprintf("(Slack) <%s> %s", user.Profile.RealName, unescapeMessage(msgEvent.Text))
ircLink.Privmsg(IRCChannel, msg)
fmt.Println("Slack -> IRC:", msg)
}
}
}
示例2: handleMessage
// handleMessage receives an event and passes it to the MessageResponders
func handleMessage(c *slack.Slack, e *slack.MessageEvent, responders []*MessageResponder) {
if e.Username == "cbot" {
return
}
content, args, err := parseMessageContent(e)
if err != nil {
log.Printf("Error parsing message: %v", err)
return
}
if len(content) == 0 {
return
}
// determine if this is a direct message (prefixed with bots name)
direct := len(args) > 0 && args[0] == *prefix
// handle 'help' command
if direct && (len(args) == 1 || (len(args) > 1 && args[1] == "help")) {
helpTxt := bytes.NewBufferString("I understand:\n")
for _, r := range responders {
if r.Name[0] == '_' {
continue
}
helpTxt.WriteString(fmt.Sprintf(" %s %s\n", *prefix, r.Name))
}
params := slack.PostMessageParameters{Username: *prefix}
if _, _, err := c.PostMessage(e.Channel, helpTxt.String(), params); err != nil {
log.Println(err)
}
return
}
directHandled := !direct
user, err := c.GetUserInfo(e.Msg.User)
os.Setenv("CURRENT_FLOW", e.Channel)
os.Setenv("CURRENT_USER_AVATAR", user.Profile.ImageOriginal)
os.Setenv("CURRENT_USER_EMAIL", user.Profile.Email)
os.Setenv("CURRENT_USER_NICK", user.Name)
os.Setenv("CURRENT_USER_NAME", user.Profile.RealName)
os.Setenv("CURRENT_USER_ID", string(user.ID))
for _, responder := range responders {
caught, err := responder.Handle(direct, content, args[1:], func(response string) error {
// handle the output of the command by replying to the message
params := slack.PostMessageParameters{Username: *prefix}
_, _, error := c.PostMessage(e.Channel, response, params)
return error
})
if err != nil {
log.Println(err)
continue
}
if caught && direct {
directHandled = true
}
}
// handle case when a direct message wasn't handled
if !directHandled {
log.Printf("Unhandled direct message: %s", content)
resp := "Sorry, didn't recognize that command. Try 'cbot help'"
params := slack.PostMessageParameters{Username: *prefix}
if _, _, err := c.PostMessage(e.Channel, resp, params); err != nil {
log.Println(err)
}
}
}