-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathConfig.java
More file actions
345 lines (316 loc) · 12.6 KB
/
Config.java
File metadata and controls
345 lines (316 loc) · 12.6 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package org.togetherjava.tjbot.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Configuration of the application. Create instances using {@link #load(Path)}.
*/
public final class Config {
private final String token;
private final String gistApiKey;
private final String databasePath;
private final String projectWebsite;
private final String discordGuildInvite;
private final String modAuditLogChannelPattern;
private final String modMailChannelPattern;
private final String mutedRolePattern;
private final String heavyModerationRolePattern;
private final String softModerationRolePattern;
private final String tagManageRolePattern;
private final String excludeCodeAutoDetectionRolePattern;
private final SuggestionsConfig suggestions;
private final String quarantinedRolePattern;
private final ScamBlockerConfig scamBlocker;
private final String wolframAlphaAppId;
private final HelpSystemConfig helpSystem;
private final List<String> blacklistedFileExtension;
private final String mediaOnlyChannelPattern;
private final String logInfoChannelWebhook;
private final String logErrorChannelWebhook;
private final String openaiApiKey;
private final String sourceCodeBaseUrl;
private final JShellConfig jshell;
@SuppressWarnings("ConstructorWithTooManyParameters")
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private Config(@JsonProperty(value = "token", required = true) String token,
@JsonProperty(value = "gistApiKey", required = true) String gistApiKey,
@JsonProperty(value = "databasePath", required = true) String databasePath,
@JsonProperty(value = "projectWebsite", required = true) String projectWebsite,
@JsonProperty(value = "discordGuildInvite", required = true) String discordGuildInvite,
@JsonProperty(value = "modAuditLogChannelPattern",
required = true) String modAuditLogChannelPattern,
@JsonProperty(value = "modMailChannelPattern",
required = true) String modMailChannelPattern,
@JsonProperty(value = "mutedRolePattern", required = true) String mutedRolePattern,
@JsonProperty(value = "heavyModerationRolePattern",
required = true) String heavyModerationRolePattern,
@JsonProperty(value = "softModerationRolePattern",
required = true) String softModerationRolePattern,
@JsonProperty(value = "tagManageRolePattern",
required = true) String tagManageRolePattern,
@JsonProperty(value = "excludeCodeAutoDetectionRolePattern",
required = true) String excludeCodeAutoDetectionRolePattern,
@JsonProperty(value = "suggestions", required = true) SuggestionsConfig suggestions,
@JsonProperty(value = "quarantinedRolePattern",
required = true) String quarantinedRolePattern,
@JsonProperty(value = "scamBlocker", required = true) ScamBlockerConfig scamBlocker,
@JsonProperty(value = "wolframAlphaAppId", required = true) String wolframAlphaAppId,
@JsonProperty(value = "helpSystem", required = true) HelpSystemConfig helpSystem,
@JsonProperty(value = "mediaOnlyChannelPattern",
required = true) String mediaOnlyChannelPattern,
@JsonProperty(value = "blacklistedFileExtension",
required = true) List<String> blacklistedFileExtension,
@JsonProperty(value = "logInfoChannelWebhook",
required = true) String logInfoChannelWebhook,
@JsonProperty(value = "logErrorChannelWebhook",
required = true) String logErrorChannelWebhook,
@JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey,
@JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl,
@JsonProperty(value = "jshell", required = true) JShellConfig jshell) {
this.token = Objects.requireNonNull(token);
this.gistApiKey = Objects.requireNonNull(gistApiKey);
this.databasePath = Objects.requireNonNull(databasePath);
this.projectWebsite = Objects.requireNonNull(projectWebsite);
this.discordGuildInvite = Objects.requireNonNull(discordGuildInvite);
this.modAuditLogChannelPattern = Objects.requireNonNull(modAuditLogChannelPattern);
this.modMailChannelPattern = Objects.requireNonNull(modMailChannelPattern);
this.mutedRolePattern = Objects.requireNonNull(mutedRolePattern);
this.heavyModerationRolePattern = Objects.requireNonNull(heavyModerationRolePattern);
this.softModerationRolePattern = Objects.requireNonNull(softModerationRolePattern);
this.tagManageRolePattern = Objects.requireNonNull(tagManageRolePattern);
this.excludeCodeAutoDetectionRolePattern =
Objects.requireNonNull(excludeCodeAutoDetectionRolePattern);
this.suggestions = Objects.requireNonNull(suggestions);
this.quarantinedRolePattern = Objects.requireNonNull(quarantinedRolePattern);
this.scamBlocker = Objects.requireNonNull(scamBlocker);
this.wolframAlphaAppId = Objects.requireNonNull(wolframAlphaAppId);
this.helpSystem = Objects.requireNonNull(helpSystem);
this.mediaOnlyChannelPattern = Objects.requireNonNull(mediaOnlyChannelPattern);
this.blacklistedFileExtension = Objects.requireNonNull(blacklistedFileExtension);
this.logInfoChannelWebhook = Objects.requireNonNull(logInfoChannelWebhook);
this.logErrorChannelWebhook = Objects.requireNonNull(logErrorChannelWebhook);
this.openaiApiKey = Objects.requireNonNull(openaiApiKey);
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
this.jshell = Objects.requireNonNull(jshell);
}
/**
* Loads the configuration from the given file.
*
* @param path the configuration file, as JSON object
* @return the loaded configuration
* @throws IOException if the file could not be loaded
*/
public static Config load(Path path) throws IOException {
return new ObjectMapper().registerModule(new JavaTimeModule())
.readValue(path.toFile(), Config.class);
}
/**
* Gets the REGEX pattern used to identify the role assigned to muted users.
*
* @return the role name pattern
*/
public String getMutedRolePattern() {
return mutedRolePattern;
}
/**
* Gets the REGEX pattern used to identify the channel that is supposed to contain all mod audit
* logs.
*
* @return the channel name pattern
*/
public String getModAuditLogChannelPattern() {
return modAuditLogChannelPattern;
}
/**
* Gets the REGEX pattern used to identify the channel that is supposed to contain all messages
* from users who want to contact a moderator.
*
* @return the channel name pattern
*/
public String getModMailChannelPattern() {
return modMailChannelPattern;
}
/**
* Gets the token of the Discord bot to connect this application to.
*
* @return the Discord bot token
*/
public String getToken() {
return token;
}
/**
* Gets the API Key of GitHub to upload pastes via the API.
*
* @return the upload services API Key
* @see <a href=
* "https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">Create
* a GitHub key</a>
*/
public String getGistApiKey() {
return gistApiKey;
}
/**
* Gets the path where the database of the application is located at.
*
* @return the path of the database
*/
public String getDatabasePath() {
return databasePath;
}
/**
* Gets a URL of the project's website, for example to tell the user where he can contribute.
*
* @return the website of the project
*/
public String getProjectWebsite() {
return projectWebsite;
}
/**
* Gets an invite-URL to join the Discord guild this application is connected to.
*
* @return an invite-URL for this Discord guild
*/
public String getDiscordGuildInvite() {
return discordGuildInvite;
}
/**
* Gets the REGEX pattern used to identify roles that are allowed to use heavy moderation
* commands, such as banning, based on role names.
*
* @return the REGEX pattern
*/
public String getHeavyModerationRolePattern() {
return heavyModerationRolePattern;
}
/**
* Gets the REGEX pattern used to identify roles that are allowed to use soft moderation
* commands, such as kicking, muting or message deletion, based on role names.
*
* @return the REGEX pattern
*/
public String getSoftModerationRolePattern() {
return softModerationRolePattern;
}
/**
* Gets the REGEX pattern used to identify roles that are allowed to use the tag-manage command,
* such as creating or editing tags.
*
* @return the REGEX pattern
*/
public String getTagManageRolePattern() {
return tagManageRolePattern;
}
/**
* Gets the REGEX pattern used to identify roles that will be ignored for code actions
* auto-detection
*
* @return the REGEX pattern
*/
public String getExcludeCodeAutoDetectionRolePattern() {
return excludeCodeAutoDetectionRolePattern;
}
/**
* Gets the config for the suggestion system.
*
* @return the suggestion system config
*/
public SuggestionsConfig getSuggestions() {
return suggestions;
}
/**
* Gets the REGEX pattern used to identify the role assigned to quarantined users.
*
* @return the role name pattern
*/
public String getQuarantinedRolePattern() {
return quarantinedRolePattern;
}
/**
* Gets the config for the scam blocker system.
*
* @return the scam blocker system config
*/
public ScamBlockerConfig getScamBlocker() {
return scamBlocker;
}
/**
* Gets the application ID used to connect to the WolframAlpha API.
*
* @return the application ID for the WolframAlpha API
*/
public String getWolframAlphaAppId() {
return wolframAlphaAppId;
}
/**
* Gets the config for the help system.
*
* @return the help system config
*/
public HelpSystemConfig getHelpSystem() {
return helpSystem;
}
/**
* Gets the REGEX pattern used to identify the channel that is supposed to contain only Media.
*
* @return the channel name pattern
*/
public String getMediaOnlyChannelPattern() {
return mediaOnlyChannelPattern;
}
/**
* Gets a list of all blacklisted file extensions.
*
* @return a list of all blacklisted file extensions
*/
public List<String> getBlacklistedFileExtensions() {
return Collections.unmodifiableList(blacklistedFileExtension);
}
/**
* The Discord channel webhook for posting log messages with levels INFO, DEBUG and TRACE.
*
* @return the webhook URL
*/
public String getLogInfoChannelWebhook() {
return logInfoChannelWebhook;
}
/**
* The Discord channel webhook for posting log messages with levels FATAL, ERROR and WARNING.
*
* @return the webhook URL
*/
public String getLogErrorChannelWebhook() {
return logErrorChannelWebhook;
}
/**
* The OpenAI token needed for communicating with OpenAI ChatGPT.
*
* @return the OpenAI API Token
*/
public String getOpenaiApiKey() {
return openaiApiKey;
}
/**
* The base URL of the source code of this bot. E.g.
* {@code getSourceCodeBaseUrl() + "/org/togetherjava/tjbot/config/Config.java"} would point to
* this file.
*
* @return the base url of the source code of this bot
*/
public String getSourceCodeBaseUrl() {
return sourceCodeBaseUrl;
}
/**
* The configuration about jshell REST API and command/code action settings.
*
* @return the jshell configuration
*/
public JShellConfig getJshell() {
return jshell;
}
}