示例#1
0
func get_channel(rtm *slack.RTM, lookfor string) (string, error) {
	has_hash := strings.HasPrefix(strings.Trim(lookfor, " "), "#")
	if has_hash {
		lookfor = strings.TrimPrefix(strings.Trim(lookfor, " "), "#")
	}
	t := time.Now()
	ts := t.Format("Mon Jan 2 15:04:05 -0700 MST 2006")

	// Try public channels first
	l, err := rtm.GetChannels(false)
	if err != nil {
		fmt.Printf("[%s] ERROR Channel list error: %s\n", ts, err)
	}
	for _, v := range l {
		if v.Name == lookfor {
			return v.ID, nil
		}
	}

	// Now private channels, or groups in slack terms
	g, err := rtm.GetGroups(false)
	if err != nil {
		fmt.Printf("[%s] ERROR Channel list error: %s\n", ts, err)
	}
	for _, v := range g {
		if v.Name == lookfor {
			return v.ID, nil
		}
	}

	return "", errors.New("No channel found with this name")
}
示例#2
0
文件: main.go 项目: kienhung/gohome
func lookupChannelByName(api *slack.RTM, name string) *slack.Channel {
	channels, err := api.GetChannels(true)
	if err != nil {
		log.Fatal(err)
	}
	for _, channel := range channels {
		if channel.Name == name {
			return &channel
		}
	}
	return nil
}
示例#3
0
文件: hal.go 项目: andrew-sledge/hal
func get_channel(rtm *slack.RTM, lookfor string) (string, error) {
	has_hash := strings.HasPrefix(strings.Trim(lookfor, " "), "#")
	if has_hash {
		lookfor = strings.TrimPrefix(strings.Trim(lookfor, " "), "#")
	}
	l, err := rtm.GetChannels(false)
	if err != nil {
		t := time.Now()
		ts := t.Format("Mon Jan 2 15:04:05 -0700 MST 2006")
		fmt.Printf("[%s] ERROR Channel list error: %s\n", ts, err)
		os.Exit(1)
	}
	for _, v := range l {
		if v.Name == lookfor {
			return v.ID, nil
		}
	}
	return "", errors.New("No channel found with this name")
}