Example #1
0
// InitUserCache is called by a main goroutine
// to prepopulate the user cache
func InitUserCache(client *slack.Client) error {
	if Users == nil {
		log.Printf("Initializing the user cache")

		Users = &UserCache{
			client: client,
			cache:  common.NewBiMap()}

		users, err := client.GetUsers()
		if err != nil {
			return err
		}

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

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

	return nil
}
Example #2
0
// 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
}
Example #3
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
}