-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_handlers.go
277 lines (251 loc) · 6.79 KB
/
config_handlers.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
package main
func getBlacklist(inService, botName, inServer, inChannel string) (blacklist []string) {
perms := []permission{}
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
perms = server.Permissions
}
}
}
}
case "irc":
for _, group := range getChannelGroups(inService, botName, inServer, inChannel) {
for _, channel := range group.ChannelIDs {
if channel == inChannel {
perms = group.Permissions
}
}
}
default:
}
// load users that are in blacklisted groups
for _, perm := range perms {
if perm.Blacklisted {
for _, user := range perm.Users {
blacklist = append(blacklist, user)
}
}
}
return
}
func getChannels(inService, botName, inServer string) (channels []string) {
Log.Debugf("service: %s, bot: %s, server: %s", inService, botName, inServer)
switch inService {
case "discord":
for bid := range discordGlobal.Bots {
Log.Debugf("checking for bot: %s", discordGlobal.Bots[bid].BotName)
if botName == discordGlobal.Bots[bid].BotName {
Log.Debugf("matched for %s", discordGlobal.Bots[bid].BotName)
for sid := range discordGlobal.Bots[bid].Servers {
Log.Debugf("checking for server: %s", discordGlobal.Bots[bid].Servers[sid].ServerID)
if inServer == discordGlobal.Bots[bid].Servers[sid].ServerID {
Log.Debugf("matched for %s", discordGlobal.Bots[bid].Servers[sid].ServerID)
for gid := range discordGlobal.Bots[bid].Servers[sid].ChanGroups {
Log.Debugf("%s", discordGlobal.Bots[bid].Servers[sid].ChanGroups[gid].ChannelIDs)
for _, channel := range discordGlobal.Bots[bid].Servers[sid].ChanGroups[gid].ChannelIDs {
channels = append(channels, channel)
}
}
}
}
}
}
case "irc":
for _, bot := range ircGlobal.Bots {
if bot.BotName == botName {
for _, group := range bot.ChanGroups {
for _, channel := range group.ChannelIDs {
channels = append(channels, channel)
}
}
}
}
default:
}
Log.Debugf("handing channels back with a value of %s", channels)
return
}
func getChannelGroups(inService, botName, inServer, inChannel string) (chanGroups []channelGroup) {
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
chanGroups = server.ChanGroups
}
}
}
}
case "irc":
for _, bot := range ircGlobal.Bots {
if bot.BotName == botName {
chanGroups = bot.ChanGroups
}
}
default:
}
return
}
func getCommands(inService, botName, inServer, inChannel string) (commands []command) {
// prep stuff for passing to the parser
for _, group := range getChannelGroups(inService, botName, inServer, inChannel) {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
for _, command := range group.Commands {
commands = append(commands, command)
}
}
}
}
return
}
func getKeywords(inService, botName, inServer, inChannel string) (keywords []keyword) {
// prep stuff for passing to the parser
for _, group := range getChannelGroups(inService, botName, inServer, inChannel) {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
for _, keyword := range group.Keywords {
keywords = append(keywords, keyword)
}
}
}
}
return
}
func getRegexPatterns(inService, botName, inServer, inChannel string) (patterns []pattern) {
// prep stuff for passing to the parser
for _, group := range getChannelGroups(inService, botName, inServer, inChannel) {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
for _, pat := range group.Regex {
patterns = append(patterns, pat)
}
}
}
}
return
}
func getMentions(inService, botName, inServer, inChannel string) (ping, mention responseArray) {
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
if inChannel == "DirectMessage" {
mention = bot.Config.DMResp
} else {
for _, group := range server.ChanGroups {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
Log.Debugf("bot was mentioned on channel %s", channel)
Log.Debugf("ping resp %s", group.Mentions.Ping)
Log.Debugf("mention resp %s", group.Mentions.Mention)
ping = group.Mentions.Ping
mention = group.Mentions.Mention
return
}
}
}
}
}
}
}
}
case "irc":
for _, bot := range ircGlobal.Bots {
if bot.BotName == botName {
if inChannel == bot.Config.Server.Nickname {
mention = bot.Config.DMResp
} else {
for _, group := range bot.ChanGroups {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
ping = group.Mentions.Ping
mention = group.Mentions.Mention
return
}
}
}
}
}
}
default:
}
return
}
func getParsing(inService, botName, inServer, inChannel string) (parseConf parsing) {
// prep stuff for passing to the parser
for _, group := range getChannelGroups(inService, botName, inServer, inChannel) {
for _, channel := range group.ChannelIDs {
if inChannel == channel {
parseConf = group.Parsing
}
}
}
return
}
func getFilter(inService, botName, inServer string) (filters []filter) {
// prep stuff for passing to the parser
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
filters = server.Filters
}
}
}
}
case "irc":
default:
}
return
}
func getBotParseConfig() (maxLogs int, response, reaction []string, allowIP bool) {
return botConfig.Parsing.Max, botConfig.Parsing.Response, botConfig.Parsing.Reaction, botConfig.Parsing.AllowIP
}
func getPrefix(inService, botName, inServer string) (prefix string) {
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
prefix = server.Config.Prefix
}
}
}
}
case "irc":
for _, bot := range ircGlobal.Bots {
if bot.BotName == botName {
prefix = bot.Config.Prefix
}
}
default:
}
return
}
func getCommandClear(inService, botName, inServer string) (clear bool) {
switch inService {
case "discord":
for _, bot := range discordGlobal.Bots {
if bot.BotName == botName {
for _, server := range bot.Servers {
if inServer == server.ServerID {
clear = server.Config.Clear
}
}
}
}
default:
}
return
}