Esempio n. 1
0
// InitChannelCache is called by a main goroutine
// to prepopulate the channel cache
func InitChannelCache(client *slack.Client) error {
	if Channels == nil {
		log.Printf("Initializing the channel cache")

		Channels = &ChannelCache{
			client: client,
			cache:  common.NewBiMap()}

		channels, err := client.GetChannels(true)
		if err != nil {
			return err
		}

		for _, v := range channels {
			Channels.cache.Put(v.ID, v.Name)
			SB.ChanPersist <- &common.SlackItem{
				ID:   v.ID,
				Name: v.Name,
				Type: common.SlackItemTypeChannel}
		}

		log.Printf("Done initializing the channel cache")
	}

	return nil
}
Esempio n. 2
0
func dumpChannels(api *slack.Client, dir string, rooms []string) []slack.Channel {
	channels, err := api.GetChannels(false)
	check(err)

	if len(rooms) > 0 {
		channels = FilterChannels(channels, func(channel slack.Channel) bool {
			for _, room := range rooms {
				if room == channel.Name {
					return true
				}
			}
			return false
		})
	}

	if len(channels) == 0 {
		var channels []slack.Channel
		return channels
	}

	for _, channel := range channels {
		dumpChannel(api, dir, channel.Conversation.ID, channel.Name, "channel")
	}

	return channels
}
Esempio n. 3
0
File: main.go Progetto: ewok/tools
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)

}
Esempio n. 4
0
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
}