func dumpChannels(api *slack.Slack, 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.Id, channel.Name, "channel") } return channels }
func updateChannels(s *slack.Slack, db *sql.DB) error { channels, err := s.GetChannels(false) if err != nil { return err } for _, c := range channels { fmt.Printf("%s : %s\n", c.Name, c.ID) _, err := db.Exec( `INSERT INTO channels(id, name, created_at, updated_at) VALUES(?, ?, NOW(), NOW()) ON DUPLICATE KEY UPDATE name = VALUES(name), updated_at = NOW() `, c.ID, c.Name) if err != nil { return err } } return nil }