Skip to content

Instantly share code, notes, and snippets.

@yukpiz
Created October 11, 2018 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukpiz/5b36d417e92ffb7ced122668774cad44 to your computer and use it in GitHub Desktop.
Save yukpiz/5b36d417e92ffb7ced122668774cad44 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
type Data struct {
Ok bool `json:"ok"`
Channels []Channel `json:"channels"`
}
type Channel struct {
ID string `json:"id"`
Name string `json:"name"`
IsChannel bool `json:"is_channel"`
Created int32 `json:"created"`
IsArchived bool `json:"is_archived"`
IsGeneral bool `json:"is_general"`
Unlinked int32 `json:"unlinked"`
Creator string `json:"creator"`
NameNormalized string `json:"name_normalized"`
IsShared bool `json:"is_shared"`
IsOrgShared bool `json:"is_org_shared"`
IsMember bool `json:"is_member"`
IsPrivate bool `json:"is_private"`
IsMpim bool `json:"is_mpim"`
Members []string `json:"members"`
Topic Topic `json:"topic"`
Purpose Purpose `json:"purpose"`
PreviousNames []string `json:"previous_names"`
NumMembers int32 `json:"num_members"`
}
type Topic struct {
Value string `json:"value"`
Creator string `json:"creator"`
LastSet int32 `json:"last_set"`
}
type Purpose struct {
Value string `json:"value"`
Creator string `json:"creator"`
LastSet int32 `json:"last_set"`
}
func main() {
url := "https://slack.com/api/channels.list?token={YOUR_TOKEN}&exclude_archived=true&pretty=1"
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
var data Data
json.Unmarshal(bytes, &data)
c1 := []string{}
c2 := []string{}
for _, c := range data.Channels {
if c.IsPrivate || c.IsArchived {
continue
}
if strings.Index(c.Name, "time") < 0 {
c1 = append(c1, c.Name)
continue
}
c2 = append(c2, c.Name)
}
fmt.Println("=== Times Channels ======")
for _, n := range c2 {
fmt.Printf("#%s\n", n)
}
fmt.Println("")
fmt.Println("=== Public Channels ======")
for _, n := range c1 {
fmt.Printf("#%s\n", n)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment