-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (49 loc) · 1.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"log"
"os"
"github.com/chck/synr/chatwork"
"github.com/chck/synr/slack"
"github.com/chck/synr/config"
flags "github.com/jessevdk/go-flags"
)
type options struct {
ChatName string `short:"c" long:"chatname" description:"A chat name you'd like to leave"`
DryRun bool `short:"d" long:"dry-run" description:"Pre-running to leave unnessesary chat rooms"`
BeforeMonth int `short:"m" long:"before-month" description:"Set X month elapsed when Last of talking date to leave: DEFAULT 1 MONTH AGO"`
}
func cmdOpts() *options {
opts := &options{}
parser := flags.NewParser(opts, flags.PrintErrors)
parser.Name = "synr"
parser.Usage = "-c slack"
args, _ := parser.Parse()
if len(args) != 0 || opts.ChatName == "" {
parser.WriteHelp(os.Stdout)
os.Exit(1)
}
return opts
}
func main() {
log.Println("Erase your past glory...")
log.Println("++++++++++++++++++++++++")
tokens := config.Load().Tokens
opts := cmdOpts()
switch opts.ChatName {
case "chatwork":
client := chatwork.New(tokens.Chatwork)
rooms, _ := client.GetRooms()
for _, room := range rooms {
chatwork.MayBeLeaveRoom(opts.DryRun, opts.BeforeMonth, client, &room)
}
case "slack":
client := slack.New(tokens.Slack)
channels, _ := client.GetChannels(false)
starredIDs := slack.StarredChannelIDs(client)
for _, channel := range channels {
slack.MayBeLeaveChannel(opts.DryRun, opts.BeforeMonth, client, channel, starredIDs)
}
}
log.Println("++++++++++++++++++++++++")
log.Println("Done!!")
}