-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_examples.go
302 lines (272 loc) · 7.23 KB
/
config_examples.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package main
import (
"log"
"os"
"strings"
)
func createExampleBotConfig(confDir, conf, verbose string) (err error) {
newBot := parkertron{
Services: []string{"discord"},
Log: logConf{
Level: "info",
Location: "logs/",
},
Parsing: botParseConfig{
Max: 5,
Response: []string{"There were too many logs to read &user&. Please post 5 or less."},
},
}
// create file
fileCheck, err := os.OpenFile(confDir+conf, os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return
}
if err := fileCheck.Close(); err != nil {
return err
}
file, err := os.Stat(confDir + conf)
if err != nil {
return
}
if file.Size() == 0 {
if strings.HasSuffix(conf, "yaml") || strings.HasSuffix(conf, "yml") {
// if config is yaml
if verbose == "debug" {
log.Printf("file %s%s is yaml", confDir, conf)
}
if verbose == "debug" {
log.Printf("writing to %s%s", confDir, conf)
}
if err = writeYamlToFile(confDir+conf, newBot); err != nil {
return
}
} else if strings.HasSuffix(conf, "json") {
// if config is json
if verbose == "debug" {
log.Printf("file %s%s is json", confDir, conf)
}
if verbose == "debug" {
log.Printf("writing to %s%s", confDir, conf)
}
if err = writeJSONToFile(confDir+conf, newBot); err != nil {
return
}
}
}
return
}
func createExampleDiscordConfig(confDir string) (err error) {
// if the config dir doesn't exist make it
Log.Debugf("creating example config folder %s if it doesn't exist", confDir)
if err = createIfDoesntExist(confDir); err != nil {
return
}
// if the config dir doesn't exist make it
Log.Debugf("creating example config folder %s if it doesn't exist", confDir+"example-bot/")
if err = createIfDoesntExist(confDir + "example-bot/"); err != nil {
}
// if the config dir doesn't exist make it
Log.Debugf("creating example config file %s if it doesn't exist", confDir+"example-bot/example.yml")
if err = createIfDoesntExist(confDir + "example-bot/example.yml"); err != nil {
return
}
newDiscordBot := discordBot{}
newDiscordBotConfig := discordBotConfig{
Token: "An example token",
Game: "Supporting Humans",
DMResp: responseArray{
Response: []string{""},
Reaction: []string{""},
},
}
Log.Debugf("writing example config to file %s", confDir+"example-bot/example.yml")
newDiscordBot.Config = newDiscordBotConfig
if err = writeYamlToFile(confDir+"example-bot/example.yml", newDiscordBot); err != nil {
return
}
// if the config dir doesn't exist make it
Log.Debugf("creating example server config folder %s if it doesn't exist", confDir+"example-bot/example-server/")
if err = createIfDoesntExist(confDir + "example-bot/example-server/"); err != nil {
return
}
newServer := discordServer{
ServerID: "a-server-id",
Config: discordServerConfig{
Prefix: ".",
Clear: true,
},
ChanGroups: []channelGroup{
{
ChannelIDs: []string{
"a-channel-id",
"another-channel-id",
},
Mentions: mentions{
Ping: responseArray{
Reaction: []string{"👋"},
Response: []string{"I see I was pinged.", "Please just post the issue you are having", " Or you can gather your logs and post them"},
},
Mention: responseArray{
Reaction: []string{"👋"},
Response: []string{""},
},
},
Commands: []command{
{
Command: "example",
Response: []string{"This is the response to the &prefix&example command"},
},
},
Keywords: []keyword{
{
Keyword: "example",
Reaction: []string{""},
Response: []string{"I have responded to seeing the word example."},
},
},
Regex: []pattern{
{
Pattern: ".*example.*",
Reaction: []string{""},
Response: []string{"I have found the word example somewhere in there."},
},
},
Parsing: parsing{
Image: parsingImageConfig{
FileTypes: []string{
"png",
"jpg"},
Sites: []parsingConfig{
{
Name: "pastebin",
URL: "'https://pastebin.com/'",
Format: "'https://pastebin.com/raw/&filename&'",
},
{
Name: "hastebin",
URL: "'https://hastebin.com/'",
Format: "'https://hastebin.com/raw/&filename&'",
},
},
},
Paste: parsingPasteConfig{
Sites: []parsingConfig{},
},
},
KOM: discordKickOnMention{},
},
},
Permissions: []permission{
{
Group: "admin",
Users: []string{},
Roles: []string{},
Blacklisted: false,
},
},
Filters: []filter{
{
Term: "a bad word",
Reason: []string{
"the message was removed because it had 'a bad word' in it",
},
},
},
}
Log.Debugf("writing example server config to file %s", confDir+"example-bot/example-server/example.yml")
if err = writeYamlToFile(confDir+"example-bot/example-server/example-server.yml", newServer); err != nil {
return
}
return
}
func createExampleIRCConfig(confDir string) (err error) {
// if the config dir doesn't exist make it
Log.Debugf("creating example config folder %s if it doesn't exist", confDir)
if err = createIfDoesntExist(confDir); err != nil {
return
}
// if the config dir doesn't exist make it
Log.Debugf("creating example config folder %s if it doesn't exist", confDir+"example-bot/")
if err = createIfDoesntExist(confDir + "example-bot/"); err != nil {
}
// if the config dir doesn't exist make it
Log.Debugf("creating example config file %s if it doesn't exist", confDir+"example-bot/example-bot.yml")
if err = createIfDoesntExist(confDir + "example-bot/example.yml"); err != nil {
return
}
newIrc := ircBot{
Config: ircBotConfig{
Server: ircServerConfig{
Address: "irc.freenode.net",
Port: 6667,
SSLEnable: true,
Ident: "parkertron",
Password: "Set-Your-Own",
Nickname: "parkertron",
RealName: "Parker McBot",
},
DMResp: responseArray{
Response: []string{},
},
Prefix: ".",
},
ChanGroups: []channelGroup{
{
ChannelIDs: []string{
"a-channel-name",
"another-channel-name",
},
Mentions: mentions{
Ping: responseArray{
Response: []string{},
},
Mention: responseArray{
Response: []string{},
},
},
Commands: []command{
{
Command: "example",
Reaction: []string{""},
Response: []string{"This is the response to the &prefix&example command"},
},
},
Keywords: []keyword{
{
Keyword: "example",
Response: []string{"I have responded to seeing the word example."},
},
},
Regex: []pattern{
{
Pattern: ".*example.*",
Reaction: []string{""},
Response: []string{"I have found the word example somewhere in there."},
},
},
Parsing: parsing{
Image: parsingImageConfig{
FileTypes: []string{},
Sites: []parsingConfig{},
},
Paste: parsingPasteConfig{
Sites: []parsingConfig{},
},
},
Permissions: []permission{
{
Group: "admin",
Users: []string{},
Roles: []string{},
Blacklisted: false,
},
},
},
},
}
Log.Debugf("writing example config to file %s", confDir+"example-bot/example-bot.yml")
if err = writeYamlToFile(confDir+"example-bot/example.yml", newIrc); err != nil {
return
}
return
}