-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.go
68 lines (54 loc) · 1.23 KB
/
slack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/charmbracelet/log"
"github.com/slack-go/slack"
)
func ConnectSlack() {
App.slack = make(map[string]*slack.Client)
teams, err := ListTeams()
if err != nil {
log.Error("Could not list teams.", "err", err)
return
}
for i, _ := range teams {
team := teams[i]
go team.Connect()
}
go commonSlackHandler()
}
func ListChannelMembers(teamID string, channel string) ([]string, error) {
client, ok := App.slack[teamID]
if !ok {
return []string{}, fmt.Errorf("not connected to team %s", teamID)
}
var allUsers []string
cursor := "_initial"
for cursor != "" {
var response []string
var err error
if cursor == "_initial" {
cursor = ""
}
response, cursor, err = client.GetUsersInConversation(&slack.GetUsersInConversationParameters{
ChannelID: channel,
Cursor: cursor,
})
if err != nil {
return []string{}, err
}
allUsers = append(allUsers, response...)
}
return allUsers, nil
}
func LoadMemberName(teamID string, user string) (string, error) {
client, ok := App.slack[teamID]
if !ok {
return "", fmt.Errorf("not connected to team %s", teamID)
}
resp, err := client.GetUserInfo(user)
if err != nil {
return "", err
}
return resp.RealName, err
}