// InitGroupCache is called by a main goroutine // to prepopulate the group cache func InitGroupCache(client *slack.Client) error { if Groups == nil { log.Printf("Initializing the group cache") Groups = &GroupCache{ client: client, cache: common.NewBiMap()} groups, err := client.GetGroups(true) if err != nil { return err } for _, v := range groups { Groups.cache.Put(v.ID, v.Name) SB.ChanPersist <- &common.SlackItem{ ID: v.ID, Name: v.Name, Type: common.SlackItemTypeGroup} } log.Printf("Done initializing the group cache") } return nil }
func dumpGroups(api *slack.Client, dir string, rooms []string) []slack.Group { groups, err := api.GetGroups(false) check(err) if len(rooms) > 0 { groups = FilterGroups(groups, func(group slack.Group) bool { for _, room := range rooms { if room == group.Name { return true } } return false }) } if len(groups) == 0 { var groups []slack.Group return groups } for _, group := range groups { dumpChannel(api, dir, group.Conversation.ID, group.Name, "group") } return groups }
func updateDutyGroup(api *slack.Client, groupName string) { allChanenels, err := api.GetChannels(true) if err != nil { panic("Cannot get all channels") } allGroups, err := api.GetGroups(true) if err != nil { panic("Cannot get all groups") } var dutyChannel *slack.Channel for _, v := range allChanenels { if v.Name == groupName { dutyChannel, err = api.GetChannelInfo(v.ID) if err != nil { panic(err) } dutyMembers = dutyChannel.Members } } var dutyGroup *slack.Group for _, v := range allGroups { if v.Name == groupName { dutyGroup, err = api.GetGroupInfo(v.ID) if err != nil { panic(err) } dutyMembers = dutyGroup.Members } } if dutyChannel == nil && dutyGroup == nil { panic("Duty group not found") } fmt.Printf("Alld duties %s\n", dutyMembers) }
func getChannelId(name string, api *slack.Client) string { var channel_id string // update the name if the first character of the name is '#' if len([]rune(name)) > 0 && string([]rune(name)[0]) == "#" { name = string([]rune(name)[1:]) } // Check if the channel is hidden groups, err := api.GetGroups(true) if err != nil { fmt.Println("WARN: Could not get list of groups. This is only important if channel is hidden.") fmt.Println(err) } for _, g := range groups { if g.Name == name { channel_id = g.ID } } // It is not necessary to travese the open channels as well if we already have the channel id if channel_id != "" { return channel_id } channels, err := api.GetChannels(true) if err != nil { fmt.Println("ERROR: Could not get the Slack channels.") fmt.Println(err) os.Exit(2) } for _, c := range channels { if c.Name == name { channel_id = c.ID } } if channel_id == "" { fmt.Println("ERROR: Could not find the Slack channel specified. Be sure you did not comment the line in the config file by adding '#' to the channel name.") os.Exit(2) } return channel_id }