blob: 4aae10a3b4c5ed9744362a92df978e1a80a608f1 (
plain)
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
|
import type { Snowflake } from 'discord.js';
/**
* Different options for the bot.
*/
export class Config implements ConfigOptions {
/**
* Credentials for various services that the bot depends on.
*/
public credentials: Credentials;
/**
* The environment that the bot is operating under.
*/
public environment: Environment;
/**
* Bot developers.
*/
public owners: Snowflake[];
/**
* A string that needs to come before text commands.
*/
public prefix: string;
/**
* Various discord channels that logs will be sent in.
*/
public channels: Channels;
/**
* Options for the Postgres database connection.
*/
public db: DataBase;
/**
* Options for what events to log.
*/
public logging: Logging;
/**
* Information regarding the bot's support server.
*/
public supportGuild: SupportGuild;
/**
* @param options The options
*/
public constructor(options: ConfigOptions) {
this.credentials = options.credentials;
this.environment = options.environment;
this.owners = options.owners;
this.prefix = options.prefix;
this.channels = options.channels;
this.db = options.db;
this.logging = options.logging;
this.supportGuild = options.supportGuild;
}
/**
* The appropriate discord token for the environment.
*/
public get token(): string {
switch (this.environment) {
case 'production':
return this.credentials.token;
case 'beta':
return this.credentials.betaToken;
case 'development':
return this.credentials.devToken;
default:
throw new TypeError(`Unexpected environment: "${this.environment}"`);
}
}
/**
* Whether this is the production instance of the bot.
*/
public get isProduction(): boolean {
return this.environment === 'production';
}
/**
* Whether this is the beta instance of the bot.
*/
public get isBeta(): boolean {
return this.environment === 'beta';
}
/**
* Whether this is the development instance of the bot.
*/
public get isDevelopment(): boolean {
return this.environment === 'development';
}
}
/**
* The options to be provided to the {@link Config} class.
*/
export interface ConfigOptions {
/**
* Credentials for various services that the bot depends on.
*/
credentials: Credentials;
/**
* The environment that the bot is operating under.
*/
environment: Environment;
/**
* Bot developers.
*/
owners: Snowflake[];
/**
* A string that needs to come before text commands.
*/
prefix: string;
/**
* Various discord channels that logs will be sent in.
*/
channels: Channels;
/**
* Options for the Postgres database connection.
*/
db: DataBase;
/**
* Options for what events to log.
*/
logging: Logging;
/**
* Information regarding the bot's support server.
*/
supportGuild: SupportGuild;
}
/**
* Credentials for various services that the bot depends on.
*/
export interface Credentials {
/**
* The discord bot token - used when in a 'production' environment.
*/
token: string;
/**
* The discord bot token - used when in a 'beta' environment.
*/
betaToken: string;
/**
* The discord bot token - used when in a 'development' environment.
*/
devToken: string;
/**
* Api Key for the Hypixel Minecraft Java server.
* @see {@link https://api.hypixel.net/#section/Authentication/ApiKey}
*/
hypixelApiKey: string | null;
/**
* The app id for an API Application for WorlframAlpha
* @see {@link https://products.wolframalpha.com/api/}
*/
wolframAlphaAppId: string | null;
/**
* The client id for Imgur's API
* @see {@link https://apidocs.imgur.com/#authorization-and-oauth}
*/
imgurClientId: string | null;
/**
* The client secret for Imgur's API
* @see {@link https://apidocs.imgur.com/#authorization-and-oauth}
*/
imgurClientSecret: string | null;
/**
* The sentry DSN (Data Source Name) for error reporting
* @see {@link https://docs.sentry.io/product/sentry-basics/dsn-explainer/}
*/
sentryDsn: string | null;
/**
* The Perspective API Key
* @see {@link https://perspectiveapi.com/}
*/
perspectiveApiKey: string | null;
}
/**
* The possible environments that the bot can be running in.
*/
export type Environment = 'production' | 'beta' | 'development';
/**
* Various discord channels that logs will be sent in.
*/
export type Channels = {
/**
* The id of a channel to send logging messages in,
* use an empty string for no channel to be used.
*/
[Key in ConfigChannelKey]: Snowflake | '';
};
/**
* The type of information to be sent in the configured channel.
*/
export type ConfigChannelKey = 'log' | 'error' | 'dm' | 'servers';
/**
* Options for the Postgres database connection.
*/
export interface DataBase {
/**
* The host of the database.
*/
host: string;
/**
* The port of the database.
*/
port: number;
/**
* The username which is used to authenticate against the database.
*/
username: string;
/**
* The password which is used to authenticate against the database.
*/
password: string;
}
/**
* Options for what events to log.
*/
export type Logging = {
/**
* Whether or not to log database queries, verbose logs, or informational logs
*/
[Key in LoggingType]: boolean;
};
/**
* The logging level that can be changed.
*/
export type LoggingType = 'db' | 'verbose' | 'info';
/**
* Information regarding the bot's support server.
*/
export interface SupportGuild {
/**
* The id of the support server.
*/
id: Snowflake | null;
/**
* An invite link to the support server.
*/
invite: string | null;
}
|