package eve import ( "fmt" "time" "strings" ) // GetActiveChannels will parse a list of files for ones with today's timestamps // This really just returns a list of human-readable channel names so // there will be some eve specific logic to guess the channel name // ..also it'll ignore "Private Chats" and any without todays YYYYMMDD timestamp func GetActiveChannels(fileList []string) []string { var chanList []string var candidateFiles []string t := time.Now() layout := "20060102" todayString := fmt.Sprintf(t.Format(layout)) for _, file := range fileList { if !strings.Contains(file, "Corp") { if !strings.Contains(file, "Alliance") { if !strings.Contains(file, "Local") { if !strings.Contains(file, "Private Chat") { if strings.Contains(file, todayString) { candidateFiles = append(candidateFiles, file) } } } } } } for _, file := range candidateFiles { fmt.Println(file) chanList = append(chanList, chatNameFromFile(file)) } fmt.Printf("searched %v files.. found %v chanels\n", len(fileList), len(chanList)) return chanList } func chatNameFromFile(fname string) string { a := strings.Split(fname, "/") b := a[len(a)-1] // returns file name without any "/" prefixes // create a rune of the file name only c := []rune(b) // count how many characters.. minus the 20 at the end // EG: // "Rookie Help_20191218_161504.txt" // becomes: "Rookie Help" chars := len(c) - 20 myShortString := string(c[0:chars]) return myShortString } // TODO: run a uniq pass on the list of channels maybe //func unique(intSlice []int) []int { // keys := make(map[int]bool) // list := []int{} // for _, entry := range intSlice { // if _, value := keys[entry]; !value { // keys[entry] = true // list = append(list, entry) // } // } // return list //} // //func uniqueTest() { // intSlice := []int{1,5,3,6,9,9,4,2,3,1,5} // fmt.Println(intSlice) // uniqueSlice := unique(intSlice) // fmt.Println(uniqueSlice) //}