-
Notifications
You must be signed in to change notification settings - Fork 0
/
god.go
114 lines (99 loc) · 2.35 KB
/
god.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"encoding/json"
"errors"
"github.com/Mehigh17/go-off-discord/discord"
"io/ioutil"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
var accCfgPath, channelID, serverID string
app := cli.NewApp()
app.Name = "GOD (Go Off Discord)"
app.Authors = []*cli.Author{
&cli.Author{
Name: "Mihai Stan",
},
}
app.Version = "1.1.0"
app.Usage = "make it an accord"
app.Description = "Get off discord completely with a single command."
app.Commands = []*cli.Command{
{
Name: "delete",
Aliases: []string{"del"},
Usage: "Perform a deletion action on a server or channel",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "account",
Usage: "Load account configuration from `FILE`",
Aliases: []string{"a"},
TakesFile: true,
Required: true,
Destination: &accCfgPath,
},
},
Subcommands: []*cli.Command{
{
Name: "channel",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "Specify the `ID` of the channel",
Required: true,
Destination: &channelID,
},
},
Action: func(ctx *cli.Context) error {
cfg, err := loadConfiguration(accCfgPath)
if err != nil {
return errors.New("couldn't load account configuration, please verify your file")
}
client := discord.Client {
Configuration: cfg,
}
client.DeleteChannel(channelID)
return nil
},
},
{
Name: "server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "Specify the `ID` of the server",
Required: true,
Destination: &serverID,
},
},
Action: func(ctx *cli.Context) error {
cfg, err := loadConfiguration(accCfgPath)
if err != nil {
return errors.New("couldn't load account configuration, please verify your file")
}
client := discord.Client {
Configuration: cfg,
}
client.DeleteServer(serverID)
return nil
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func loadConfiguration(cfgPath string) (discord.AccountConfiguration, error) {
cfg := discord.AccountConfiguration{}
cfgFile, err := ioutil.ReadFile(cfgPath)
if err != nil {
return cfg, err
}
err = json.Unmarshal(cfgFile, &cfg)
return cfg, err
}