@dereekb/nestjs 13.2.2 → 13.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/discord/index.cjs.js +1171 -207
- package/discord/index.esm.js +1173 -209
- package/discord/package.json +5 -5
- package/index.cjs.js +918 -144
- package/index.esm.js +914 -146
- package/mailgun/index.cjs.js +797 -315
- package/mailgun/index.esm.js +797 -315
- package/mailgun/package.json +8 -8
- package/openai/index.cjs.js +867 -154
- package/openai/index.esm.js +867 -154
- package/openai/package.json +8 -8
- package/package.json +4 -4
- package/src/lib/decorators/local.decorator.d.ts +1 -1
- package/src/lib/decorators/rawbody.d.ts +73 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/middlewares/json.middleware.d.ts +10 -0
- package/src/lib/middlewares/webhook.d.ts +1 -1
- package/src/lib/module/client/client.config.d.ts +16 -0
- package/src/lib/module/env/env.config.d.ts +6 -0
- package/src/lib/module/env/env.service.d.ts +1 -0
- package/src/lib/util/encryption/index.d.ts +1 -0
- package/src/lib/util/encryption/json.encrypt.d.ts +130 -0
- package/src/lib/util/index.d.ts +1 -0
- package/stripe/index.cjs.js +625 -114
- package/stripe/index.esm.js +625 -114
- package/stripe/package.json +8 -8
- package/typeform/index.cjs.js +930 -173
- package/typeform/index.esm.js +930 -173
- package/typeform/package.json +8 -8
- package/vapiai/index.cjs.js +876 -151
- package/vapiai/index.esm.js +876 -151
- package/vapiai/package.json +8 -8
package/discord/index.cjs.js
CHANGED
|
@@ -8,79 +8,280 @@ var crypto = require('crypto');
|
|
|
8
8
|
var config = require('@nestjs/config');
|
|
9
9
|
var fetch = require('@dereekb/util/fetch');
|
|
10
10
|
|
|
11
|
+
function _define_property$6(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
function _object_spread$2(target) {
|
|
25
|
+
for(var i = 1; i < arguments.length; i++){
|
|
26
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
27
|
+
var ownKeys = Object.keys(source);
|
|
28
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
29
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
30
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
ownKeys.forEach(function(key) {
|
|
34
|
+
_define_property$6(target, key, source[key]);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
function ownKeys$1(object, enumerableOnly) {
|
|
40
|
+
var keys = Object.keys(object);
|
|
41
|
+
if (Object.getOwnPropertySymbols) {
|
|
42
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
43
|
+
keys.push.apply(keys, symbols);
|
|
44
|
+
}
|
|
45
|
+
return keys;
|
|
46
|
+
}
|
|
47
|
+
function _object_spread_props$1(target, source) {
|
|
48
|
+
source = source != null ? source : {};
|
|
49
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
50
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
51
|
+
} else {
|
|
52
|
+
ownKeys$1(Object(source)).forEach(function(key) {
|
|
53
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
11
58
|
/**
|
|
12
59
|
* Casts an untyped Discord interaction to a typed one.
|
|
13
60
|
*
|
|
14
61
|
* @param interaction - the raw interaction to cast
|
|
15
|
-
*/
|
|
16
|
-
function discordWebhookInteraction(interaction) {
|
|
62
|
+
*/ function discordWebhookInteraction(interaction) {
|
|
17
63
|
return interaction;
|
|
18
64
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
65
|
+
var discordInteractionHandlerFactory = util.handlerFactory(function(x) {
|
|
66
|
+
return x.type;
|
|
67
|
+
});
|
|
68
|
+
var discordInteractionHandlerConfigurerFactory = util.handlerConfigurerFactory({
|
|
69
|
+
configurerForAccessor: function configurerForAccessor(accessor) {
|
|
22
70
|
// eslint-disable-next-line
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...accessor,
|
|
71
|
+
var fnWithKey = util.handlerMappedSetFunctionFactory(accessor, discordWebhookInteraction);
|
|
72
|
+
var configurer = _object_spread_props$1(_object_spread$2({}, accessor), {
|
|
26
73
|
handleApplicationCommand: fnWithKey(discord_js.InteractionType.ApplicationCommand),
|
|
27
74
|
handleMessageComponent: fnWithKey(discord_js.InteractionType.MessageComponent),
|
|
28
75
|
handleModalSubmit: fnWithKey(discord_js.InteractionType.ModalSubmit),
|
|
29
76
|
handleAutocomplete: fnWithKey(discord_js.InteractionType.ApplicationCommandAutocomplete)
|
|
30
|
-
};
|
|
77
|
+
});
|
|
31
78
|
return configurer;
|
|
32
79
|
}
|
|
33
80
|
});
|
|
34
81
|
|
|
82
|
+
function _class_call_check$6(instance, Constructor) {
|
|
83
|
+
if (!(instance instanceof Constructor)) {
|
|
84
|
+
throw new TypeError("Cannot call a class as a function");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function _defineProperties$4(target, props) {
|
|
88
|
+
for(var i = 0; i < props.length; i++){
|
|
89
|
+
var descriptor = props[i];
|
|
90
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
91
|
+
descriptor.configurable = true;
|
|
92
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
93
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function _create_class$4(Constructor, protoProps, staticProps) {
|
|
97
|
+
if (staticProps) _defineProperties$4(Constructor, staticProps);
|
|
98
|
+
return Constructor;
|
|
99
|
+
}
|
|
100
|
+
function _define_property$5(obj, key, value) {
|
|
101
|
+
if (key in obj) {
|
|
102
|
+
Object.defineProperty(obj, key, {
|
|
103
|
+
value: value,
|
|
104
|
+
enumerable: true,
|
|
105
|
+
configurable: true,
|
|
106
|
+
writable: true
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
obj[key] = value;
|
|
110
|
+
}
|
|
111
|
+
return obj;
|
|
112
|
+
}
|
|
35
113
|
/**
|
|
36
114
|
* Default environment variable for the Discord application public key.
|
|
37
|
-
*/
|
|
38
|
-
const DISCORD_PUBLIC_KEY_ENV_VAR = 'DISCORD_PUBLIC_KEY';
|
|
115
|
+
*/ var DISCORD_PUBLIC_KEY_ENV_VAR = 'DISCORD_PUBLIC_KEY';
|
|
39
116
|
/**
|
|
40
117
|
* Configuration for the DiscordWebhookService.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!config.discordWebhook.publicKey) {
|
|
46
|
-
throw new Error('No Discord public key specified.');
|
|
47
|
-
}
|
|
118
|
+
*/ var DiscordWebhookServiceConfig = /*#__PURE__*/ function() {
|
|
119
|
+
function DiscordWebhookServiceConfig() {
|
|
120
|
+
_class_call_check$6(this, DiscordWebhookServiceConfig);
|
|
121
|
+
_define_property$5(this, "discordWebhook", void 0);
|
|
48
122
|
}
|
|
49
|
-
|
|
123
|
+
_create_class$4(DiscordWebhookServiceConfig, null, [
|
|
124
|
+
{
|
|
125
|
+
key: "assertValidConfig",
|
|
126
|
+
value: function assertValidConfig(config) {
|
|
127
|
+
if (!config.discordWebhook.publicKey) {
|
|
128
|
+
throw new Error('No Discord public key specified.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
return DiscordWebhookServiceConfig;
|
|
134
|
+
}
|
|
135
|
+
();
|
|
50
136
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
70
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
71
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
72
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function __param(paramIndex, decorator) {
|
|
76
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
80
|
-
var e = new Error(message);
|
|
81
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
137
|
+
function _type_of(obj) {
|
|
138
|
+
"@swc/helpers - typeof";
|
|
139
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
140
|
+
}
|
|
141
|
+
function __decorate(decorators, target, key, desc) {
|
|
142
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
143
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
144
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
145
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
146
|
+
}
|
|
147
|
+
function __param(paramIndex, decorator) {
|
|
148
|
+
return function(target, key) {
|
|
149
|
+
decorator(target, key, paramIndex);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
153
|
+
var e = new Error(message);
|
|
154
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
82
155
|
};
|
|
83
156
|
|
|
157
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
158
|
+
try {
|
|
159
|
+
var info = gen[key](arg);
|
|
160
|
+
var value = info.value;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
reject(error);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (info.done) {
|
|
166
|
+
resolve(value);
|
|
167
|
+
} else {
|
|
168
|
+
Promise.resolve(value).then(_next, _throw);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function _async_to_generator$3(fn) {
|
|
172
|
+
return function() {
|
|
173
|
+
var self = this, args = arguments;
|
|
174
|
+
return new Promise(function(resolve, reject) {
|
|
175
|
+
var gen = fn.apply(self, args);
|
|
176
|
+
function _next(value) {
|
|
177
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
178
|
+
}
|
|
179
|
+
function _throw(err) {
|
|
180
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
181
|
+
}
|
|
182
|
+
_next(undefined);
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function _ts_generator$3(thisArg, body) {
|
|
187
|
+
var f, y, t, _ = {
|
|
188
|
+
label: 0,
|
|
189
|
+
sent: function() {
|
|
190
|
+
if (t[0] & 1) throw t[1];
|
|
191
|
+
return t[1];
|
|
192
|
+
},
|
|
193
|
+
trys: [],
|
|
194
|
+
ops: []
|
|
195
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
196
|
+
return d(g, "next", {
|
|
197
|
+
value: verb(0)
|
|
198
|
+
}), d(g, "throw", {
|
|
199
|
+
value: verb(1)
|
|
200
|
+
}), d(g, "return", {
|
|
201
|
+
value: verb(2)
|
|
202
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
203
|
+
value: function() {
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
}), g;
|
|
207
|
+
function verb(n) {
|
|
208
|
+
return function(v) {
|
|
209
|
+
return step([
|
|
210
|
+
n,
|
|
211
|
+
v
|
|
212
|
+
]);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function step(op) {
|
|
216
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
217
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
218
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
219
|
+
if (y = 0, t) op = [
|
|
220
|
+
op[0] & 2,
|
|
221
|
+
t.value
|
|
222
|
+
];
|
|
223
|
+
switch(op[0]){
|
|
224
|
+
case 0:
|
|
225
|
+
case 1:
|
|
226
|
+
t = op;
|
|
227
|
+
break;
|
|
228
|
+
case 4:
|
|
229
|
+
_.label++;
|
|
230
|
+
return {
|
|
231
|
+
value: op[1],
|
|
232
|
+
done: false
|
|
233
|
+
};
|
|
234
|
+
case 5:
|
|
235
|
+
_.label++;
|
|
236
|
+
y = op[1];
|
|
237
|
+
op = [
|
|
238
|
+
0
|
|
239
|
+
];
|
|
240
|
+
continue;
|
|
241
|
+
case 7:
|
|
242
|
+
op = _.ops.pop();
|
|
243
|
+
_.trys.pop();
|
|
244
|
+
continue;
|
|
245
|
+
default:
|
|
246
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
247
|
+
_ = 0;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
251
|
+
_.label = op[1];
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
255
|
+
_.label = t[1];
|
|
256
|
+
t = op;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
if (t && _.label < t[2]) {
|
|
260
|
+
_.label = t[2];
|
|
261
|
+
_.ops.push(op);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
if (t[2]) _.ops.pop();
|
|
265
|
+
_.trys.pop();
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
op = body.call(thisArg, _);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
op = [
|
|
271
|
+
6,
|
|
272
|
+
e
|
|
273
|
+
];
|
|
274
|
+
y = 0;
|
|
275
|
+
} finally{
|
|
276
|
+
f = t = 0;
|
|
277
|
+
}
|
|
278
|
+
if (op[0] & 5) throw op[1];
|
|
279
|
+
return {
|
|
280
|
+
value: op[0] ? op[1] : void 0,
|
|
281
|
+
done: true
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
84
285
|
/**
|
|
85
286
|
* Creates a verifier for Discord interaction webhook requests.
|
|
86
287
|
*
|
|
@@ -101,11 +302,10 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
101
302
|
* // result.body contains the parsed interaction
|
|
102
303
|
* }
|
|
103
304
|
* ```
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
const { publicKey: publicKeyHex } = config;
|
|
305
|
+
*/ function discordWebhookEventVerifier(config) {
|
|
306
|
+
var publicKeyHex = config.publicKey;
|
|
107
307
|
// Import the raw 32-byte Ed25519 public key via JWK format.
|
|
108
|
-
|
|
308
|
+
var publicKey = crypto.createPublicKey({
|
|
109
309
|
key: {
|
|
110
310
|
kty: 'OKP',
|
|
111
311
|
crv: 'Ed25519',
|
|
@@ -113,80 +313,487 @@ function discordWebhookEventVerifier(config) {
|
|
|
113
313
|
},
|
|
114
314
|
format: 'jwk'
|
|
115
315
|
});
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
316
|
+
return function(request, rawBody) {
|
|
317
|
+
return _async_to_generator$3(function() {
|
|
318
|
+
var signature, timestamp, result, message, signatureBuffer, valid, body;
|
|
319
|
+
return _ts_generator$3(this, function(_state) {
|
|
320
|
+
signature = request.headers['x-signature-ed25519'];
|
|
321
|
+
timestamp = request.headers['x-signature-timestamp'];
|
|
322
|
+
if (!signature || !timestamp) {
|
|
323
|
+
result = {
|
|
324
|
+
valid: false
|
|
325
|
+
};
|
|
326
|
+
} else {
|
|
327
|
+
message = Buffer.concat([
|
|
328
|
+
Buffer.from(timestamp),
|
|
329
|
+
rawBody
|
|
330
|
+
]);
|
|
331
|
+
signatureBuffer = Buffer.from(signature, 'hex');
|
|
332
|
+
valid = false;
|
|
333
|
+
try {
|
|
334
|
+
valid = crypto.verify(null, message, publicKey, signatureBuffer);
|
|
335
|
+
} catch (unused) {
|
|
336
|
+
valid = false;
|
|
337
|
+
}
|
|
338
|
+
if (valid) {
|
|
339
|
+
body = JSON.parse(rawBody.toString('utf-8'));
|
|
340
|
+
result = {
|
|
341
|
+
valid: true,
|
|
342
|
+
body: body
|
|
343
|
+
};
|
|
344
|
+
} else {
|
|
345
|
+
result = {
|
|
346
|
+
valid: false
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return [
|
|
351
|
+
2,
|
|
352
|
+
result
|
|
353
|
+
];
|
|
354
|
+
});
|
|
355
|
+
})();
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
360
|
+
try {
|
|
361
|
+
var info = gen[key](arg);
|
|
362
|
+
var value = info.value;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
reject(error);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (info.done) {
|
|
368
|
+
resolve(value);
|
|
369
|
+
} else {
|
|
370
|
+
Promise.resolve(value).then(_next, _throw);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function _async_to_generator$2(fn) {
|
|
374
|
+
return function() {
|
|
375
|
+
var self = this, args = arguments;
|
|
376
|
+
return new Promise(function(resolve, reject) {
|
|
377
|
+
var gen = fn.apply(self, args);
|
|
378
|
+
function _next(value) {
|
|
379
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
132
380
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
result = { valid: true, body };
|
|
381
|
+
function _throw(err) {
|
|
382
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
136
383
|
}
|
|
137
|
-
|
|
138
|
-
|
|
384
|
+
_next(undefined);
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function _class_call_check$5(instance, Constructor) {
|
|
389
|
+
if (!(instance instanceof Constructor)) {
|
|
390
|
+
throw new TypeError("Cannot call a class as a function");
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function _defineProperties$3(target, props) {
|
|
394
|
+
for(var i = 0; i < props.length; i++){
|
|
395
|
+
var descriptor = props[i];
|
|
396
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
397
|
+
descriptor.configurable = true;
|
|
398
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
399
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
403
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
404
|
+
return Constructor;
|
|
405
|
+
}
|
|
406
|
+
function _define_property$4(obj, key, value) {
|
|
407
|
+
if (key in obj) {
|
|
408
|
+
Object.defineProperty(obj, key, {
|
|
409
|
+
value: value,
|
|
410
|
+
enumerable: true,
|
|
411
|
+
configurable: true,
|
|
412
|
+
writable: true
|
|
413
|
+
});
|
|
414
|
+
} else {
|
|
415
|
+
obj[key] = value;
|
|
416
|
+
}
|
|
417
|
+
return obj;
|
|
418
|
+
}
|
|
419
|
+
function _ts_generator$2(thisArg, body) {
|
|
420
|
+
var f, y, t, _ = {
|
|
421
|
+
label: 0,
|
|
422
|
+
sent: function() {
|
|
423
|
+
if (t[0] & 1) throw t[1];
|
|
424
|
+
return t[1];
|
|
425
|
+
},
|
|
426
|
+
trys: [],
|
|
427
|
+
ops: []
|
|
428
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
429
|
+
return d(g, "next", {
|
|
430
|
+
value: verb(0)
|
|
431
|
+
}), d(g, "throw", {
|
|
432
|
+
value: verb(1)
|
|
433
|
+
}), d(g, "return", {
|
|
434
|
+
value: verb(2)
|
|
435
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
436
|
+
value: function() {
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
}), g;
|
|
440
|
+
function verb(n) {
|
|
441
|
+
return function(v) {
|
|
442
|
+
return step([
|
|
443
|
+
n,
|
|
444
|
+
v
|
|
445
|
+
]);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function step(op) {
|
|
449
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
450
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
451
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
452
|
+
if (y = 0, t) op = [
|
|
453
|
+
op[0] & 2,
|
|
454
|
+
t.value
|
|
455
|
+
];
|
|
456
|
+
switch(op[0]){
|
|
457
|
+
case 0:
|
|
458
|
+
case 1:
|
|
459
|
+
t = op;
|
|
460
|
+
break;
|
|
461
|
+
case 4:
|
|
462
|
+
_.label++;
|
|
463
|
+
return {
|
|
464
|
+
value: op[1],
|
|
465
|
+
done: false
|
|
466
|
+
};
|
|
467
|
+
case 5:
|
|
468
|
+
_.label++;
|
|
469
|
+
y = op[1];
|
|
470
|
+
op = [
|
|
471
|
+
0
|
|
472
|
+
];
|
|
473
|
+
continue;
|
|
474
|
+
case 7:
|
|
475
|
+
op = _.ops.pop();
|
|
476
|
+
_.trys.pop();
|
|
477
|
+
continue;
|
|
478
|
+
default:
|
|
479
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
480
|
+
_ = 0;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
484
|
+
_.label = op[1];
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
488
|
+
_.label = t[1];
|
|
489
|
+
t = op;
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
if (t && _.label < t[2]) {
|
|
493
|
+
_.label = t[2];
|
|
494
|
+
_.ops.push(op);
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
if (t[2]) _.ops.pop();
|
|
498
|
+
_.trys.pop();
|
|
499
|
+
continue;
|
|
139
500
|
}
|
|
501
|
+
op = body.call(thisArg, _);
|
|
502
|
+
} catch (e) {
|
|
503
|
+
op = [
|
|
504
|
+
6,
|
|
505
|
+
e
|
|
506
|
+
];
|
|
507
|
+
y = 0;
|
|
508
|
+
} finally{
|
|
509
|
+
f = t = 0;
|
|
140
510
|
}
|
|
141
|
-
|
|
142
|
-
|
|
511
|
+
if (op[0] & 5) throw op[1];
|
|
512
|
+
return {
|
|
513
|
+
value: op[0] ? op[1] : void 0,
|
|
514
|
+
done: true
|
|
515
|
+
};
|
|
516
|
+
}
|
|
143
517
|
}
|
|
144
|
-
|
|
145
518
|
/**
|
|
146
519
|
* Service that handles Discord interaction webhook events.
|
|
147
520
|
*
|
|
148
521
|
* Verifies incoming webhook signatures and dispatches interactions to registered handlers.
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
522
|
+
*/ exports.DiscordWebhookService = /*#__PURE__*/ function() {
|
|
523
|
+
function DiscordWebhookService(discordWebhookServiceConfig) {
|
|
524
|
+
_class_call_check$5(this, DiscordWebhookService);
|
|
525
|
+
_define_property$4(this, "logger", new common.Logger('DiscordWebhookService'));
|
|
526
|
+
_define_property$4(this, "_verifier", void 0);
|
|
527
|
+
_define_property$4(this, "handler", discordInteractionHandlerFactory());
|
|
528
|
+
_define_property$4(this, "configure", discordInteractionHandlerConfigurerFactory(this.handler));
|
|
156
529
|
this._verifier = discordWebhookEventVerifier({
|
|
157
530
|
publicKey: discordWebhookServiceConfig.discordWebhook.publicKey
|
|
158
531
|
});
|
|
159
532
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
533
|
+
_create_class$3(DiscordWebhookService, [
|
|
534
|
+
{
|
|
535
|
+
key: "updateForWebhook",
|
|
536
|
+
value: function updateForWebhook(req, rawBody) {
|
|
537
|
+
return _async_to_generator$2(function() {
|
|
538
|
+
var result;
|
|
539
|
+
return _ts_generator$2(this, function(_state) {
|
|
540
|
+
switch(_state.label){
|
|
541
|
+
case 0:
|
|
542
|
+
return [
|
|
543
|
+
4,
|
|
544
|
+
this._verifier(req, rawBody)
|
|
545
|
+
];
|
|
546
|
+
case 1:
|
|
547
|
+
result = _state.sent();
|
|
548
|
+
if (!!result.valid) return [
|
|
549
|
+
3,
|
|
550
|
+
2
|
|
551
|
+
];
|
|
552
|
+
this.logger.warn('Received invalid Discord interaction event.', req);
|
|
553
|
+
return [
|
|
554
|
+
3,
|
|
555
|
+
4
|
|
556
|
+
];
|
|
557
|
+
case 2:
|
|
558
|
+
return [
|
|
559
|
+
4,
|
|
560
|
+
this.updateForDiscordInteraction(result.body)
|
|
561
|
+
];
|
|
562
|
+
case 3:
|
|
563
|
+
_state.sent();
|
|
564
|
+
_state.label = 4;
|
|
565
|
+
case 4:
|
|
566
|
+
return [
|
|
567
|
+
2
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}).call(this);
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
key: "updateForDiscordInteraction",
|
|
576
|
+
value: function updateForDiscordInteraction(interaction) {
|
|
577
|
+
return _async_to_generator$2(function() {
|
|
578
|
+
var result;
|
|
579
|
+
return _ts_generator$2(this, function(_state) {
|
|
580
|
+
switch(_state.label){
|
|
581
|
+
case 0:
|
|
582
|
+
return [
|
|
583
|
+
4,
|
|
584
|
+
this.handler(interaction)
|
|
585
|
+
];
|
|
586
|
+
case 1:
|
|
587
|
+
result = _state.sent();
|
|
588
|
+
if (!result) {
|
|
589
|
+
this.logger.warn('Received unexpected/unhandled Discord interaction.', interaction);
|
|
590
|
+
}
|
|
591
|
+
return [
|
|
592
|
+
2
|
|
593
|
+
];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}).call(this);
|
|
597
|
+
}
|
|
173
598
|
}
|
|
174
|
-
|
|
175
|
-
|
|
599
|
+
]);
|
|
600
|
+
return DiscordWebhookService;
|
|
601
|
+
}();
|
|
176
602
|
exports.DiscordWebhookService = __decorate([
|
|
177
603
|
common.Injectable(),
|
|
178
604
|
__param(0, common.Inject(DiscordWebhookServiceConfig))
|
|
179
605
|
], exports.DiscordWebhookService);
|
|
180
606
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
607
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
608
|
+
try {
|
|
609
|
+
var info = gen[key](arg);
|
|
610
|
+
var value = info.value;
|
|
611
|
+
} catch (error) {
|
|
612
|
+
reject(error);
|
|
613
|
+
return;
|
|
185
614
|
}
|
|
186
|
-
|
|
187
|
-
|
|
615
|
+
if (info.done) {
|
|
616
|
+
resolve(value);
|
|
617
|
+
} else {
|
|
618
|
+
Promise.resolve(value).then(_next, _throw);
|
|
188
619
|
}
|
|
189
|
-
}
|
|
620
|
+
}
|
|
621
|
+
function _async_to_generator$1(fn) {
|
|
622
|
+
return function() {
|
|
623
|
+
var self = this, args = arguments;
|
|
624
|
+
return new Promise(function(resolve, reject) {
|
|
625
|
+
var gen = fn.apply(self, args);
|
|
626
|
+
function _next(value) {
|
|
627
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
628
|
+
}
|
|
629
|
+
function _throw(err) {
|
|
630
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
631
|
+
}
|
|
632
|
+
_next(undefined);
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function _class_call_check$4(instance, Constructor) {
|
|
637
|
+
if (!(instance instanceof Constructor)) {
|
|
638
|
+
throw new TypeError("Cannot call a class as a function");
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function _defineProperties$2(target, props) {
|
|
642
|
+
for(var i = 0; i < props.length; i++){
|
|
643
|
+
var descriptor = props[i];
|
|
644
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
645
|
+
descriptor.configurable = true;
|
|
646
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
647
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
651
|
+
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
652
|
+
return Constructor;
|
|
653
|
+
}
|
|
654
|
+
function _define_property$3(obj, key, value) {
|
|
655
|
+
if (key in obj) {
|
|
656
|
+
Object.defineProperty(obj, key, {
|
|
657
|
+
value: value,
|
|
658
|
+
enumerable: true,
|
|
659
|
+
configurable: true,
|
|
660
|
+
writable: true
|
|
661
|
+
});
|
|
662
|
+
} else {
|
|
663
|
+
obj[key] = value;
|
|
664
|
+
}
|
|
665
|
+
return obj;
|
|
666
|
+
}
|
|
667
|
+
function _ts_generator$1(thisArg, body) {
|
|
668
|
+
var f, y, t, _ = {
|
|
669
|
+
label: 0,
|
|
670
|
+
sent: function() {
|
|
671
|
+
if (t[0] & 1) throw t[1];
|
|
672
|
+
return t[1];
|
|
673
|
+
},
|
|
674
|
+
trys: [],
|
|
675
|
+
ops: []
|
|
676
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
677
|
+
return d(g, "next", {
|
|
678
|
+
value: verb(0)
|
|
679
|
+
}), d(g, "throw", {
|
|
680
|
+
value: verb(1)
|
|
681
|
+
}), d(g, "return", {
|
|
682
|
+
value: verb(2)
|
|
683
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
684
|
+
value: function() {
|
|
685
|
+
return this;
|
|
686
|
+
}
|
|
687
|
+
}), g;
|
|
688
|
+
function verb(n) {
|
|
689
|
+
return function(v) {
|
|
690
|
+
return step([
|
|
691
|
+
n,
|
|
692
|
+
v
|
|
693
|
+
]);
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function step(op) {
|
|
697
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
698
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
699
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
700
|
+
if (y = 0, t) op = [
|
|
701
|
+
op[0] & 2,
|
|
702
|
+
t.value
|
|
703
|
+
];
|
|
704
|
+
switch(op[0]){
|
|
705
|
+
case 0:
|
|
706
|
+
case 1:
|
|
707
|
+
t = op;
|
|
708
|
+
break;
|
|
709
|
+
case 4:
|
|
710
|
+
_.label++;
|
|
711
|
+
return {
|
|
712
|
+
value: op[1],
|
|
713
|
+
done: false
|
|
714
|
+
};
|
|
715
|
+
case 5:
|
|
716
|
+
_.label++;
|
|
717
|
+
y = op[1];
|
|
718
|
+
op = [
|
|
719
|
+
0
|
|
720
|
+
];
|
|
721
|
+
continue;
|
|
722
|
+
case 7:
|
|
723
|
+
op = _.ops.pop();
|
|
724
|
+
_.trys.pop();
|
|
725
|
+
continue;
|
|
726
|
+
default:
|
|
727
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
728
|
+
_ = 0;
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
732
|
+
_.label = op[1];
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
736
|
+
_.label = t[1];
|
|
737
|
+
t = op;
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
if (t && _.label < t[2]) {
|
|
741
|
+
_.label = t[2];
|
|
742
|
+
_.ops.push(op);
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
if (t[2]) _.ops.pop();
|
|
746
|
+
_.trys.pop();
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
op = body.call(thisArg, _);
|
|
750
|
+
} catch (e) {
|
|
751
|
+
op = [
|
|
752
|
+
6,
|
|
753
|
+
e
|
|
754
|
+
];
|
|
755
|
+
y = 0;
|
|
756
|
+
} finally{
|
|
757
|
+
f = t = 0;
|
|
758
|
+
}
|
|
759
|
+
if (op[0] & 5) throw op[1];
|
|
760
|
+
return {
|
|
761
|
+
value: op[0] ? op[1] : void 0,
|
|
762
|
+
done: true
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
exports.DiscordWebhookController = /*#__PURE__*/ function() {
|
|
767
|
+
function DiscordWebhookController(discordWebhookService) {
|
|
768
|
+
_class_call_check$4(this, DiscordWebhookController);
|
|
769
|
+
_define_property$3(this, "_discordWebhookService", void 0);
|
|
770
|
+
this._discordWebhookService = discordWebhookService;
|
|
771
|
+
}
|
|
772
|
+
_create_class$2(DiscordWebhookController, [
|
|
773
|
+
{
|
|
774
|
+
key: "handleDiscordWebhook",
|
|
775
|
+
value: function handleDiscordWebhook(req, rawBody) {
|
|
776
|
+
return _async_to_generator$1(function() {
|
|
777
|
+
return _ts_generator$1(this, function(_state) {
|
|
778
|
+
switch(_state.label){
|
|
779
|
+
case 0:
|
|
780
|
+
return [
|
|
781
|
+
4,
|
|
782
|
+
this._discordWebhookService.updateForWebhook(req, rawBody)
|
|
783
|
+
];
|
|
784
|
+
case 1:
|
|
785
|
+
_state.sent();
|
|
786
|
+
return [
|
|
787
|
+
2
|
|
788
|
+
];
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}).call(this);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
]);
|
|
795
|
+
return DiscordWebhookController;
|
|
796
|
+
}();
|
|
190
797
|
__decorate([
|
|
191
798
|
common.Post(),
|
|
192
799
|
__param(0, common.Req()),
|
|
@@ -197,11 +804,15 @@ exports.DiscordWebhookController = __decorate([
|
|
|
197
804
|
__param(0, common.Inject(exports.DiscordWebhookService))
|
|
198
805
|
], exports.DiscordWebhookController);
|
|
199
806
|
|
|
807
|
+
function _class_call_check$3(instance, Constructor) {
|
|
808
|
+
if (!(instance instanceof Constructor)) {
|
|
809
|
+
throw new TypeError("Cannot call a class as a function");
|
|
810
|
+
}
|
|
811
|
+
}
|
|
200
812
|
/**
|
|
201
813
|
* Factory that creates a DiscordWebhookServiceConfig from environment variables.
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
const config = {
|
|
814
|
+
*/ function discordWebhookServiceConfigFactory(configService) {
|
|
815
|
+
var config = {
|
|
205
816
|
discordWebhook: {
|
|
206
817
|
publicKey: configService.get(DISCORD_PUBLIC_KEY_ENV_VAR)
|
|
207
818
|
}
|
|
@@ -214,89 +825,338 @@ function discordWebhookServiceConfigFactory(configService) {
|
|
|
214
825
|
*
|
|
215
826
|
* Standalone — does not depend on DiscordModule (no bot token needed).
|
|
216
827
|
* Reads the application public key from the DISCORD_PUBLIC_KEY environment variable.
|
|
217
|
-
*/
|
|
218
|
-
|
|
828
|
+
*/ exports.DiscordWebhookModule = function DiscordWebhookModule() {
|
|
829
|
+
_class_call_check$3(this, DiscordWebhookModule);
|
|
219
830
|
};
|
|
220
831
|
exports.DiscordWebhookModule = __decorate([
|
|
221
832
|
common.Module({
|
|
222
|
-
imports: [
|
|
223
|
-
|
|
833
|
+
imports: [
|
|
834
|
+
config.ConfigModule
|
|
835
|
+
],
|
|
836
|
+
controllers: [
|
|
837
|
+
exports.DiscordWebhookController
|
|
838
|
+
],
|
|
224
839
|
providers: [
|
|
225
840
|
{
|
|
226
841
|
provide: DiscordWebhookServiceConfig,
|
|
227
|
-
inject: [
|
|
842
|
+
inject: [
|
|
843
|
+
config.ConfigService
|
|
844
|
+
],
|
|
228
845
|
useFactory: discordWebhookServiceConfigFactory
|
|
229
846
|
},
|
|
230
847
|
exports.DiscordWebhookService
|
|
231
848
|
],
|
|
232
|
-
exports: [
|
|
849
|
+
exports: [
|
|
850
|
+
exports.DiscordWebhookService
|
|
851
|
+
]
|
|
233
852
|
})
|
|
234
853
|
], exports.DiscordWebhookModule);
|
|
235
854
|
|
|
855
|
+
function _class_call_check$2(instance, Constructor) {
|
|
856
|
+
if (!(instance instanceof Constructor)) {
|
|
857
|
+
throw new TypeError("Cannot call a class as a function");
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
function _defineProperties$1(target, props) {
|
|
861
|
+
for(var i = 0; i < props.length; i++){
|
|
862
|
+
var descriptor = props[i];
|
|
863
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
864
|
+
descriptor.configurable = true;
|
|
865
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
866
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
870
|
+
if (staticProps) _defineProperties$1(Constructor, staticProps);
|
|
871
|
+
return Constructor;
|
|
872
|
+
}
|
|
873
|
+
function _define_property$2(obj, key, value) {
|
|
874
|
+
if (key in obj) {
|
|
875
|
+
Object.defineProperty(obj, key, {
|
|
876
|
+
value: value,
|
|
877
|
+
enumerable: true,
|
|
878
|
+
configurable: true,
|
|
879
|
+
writable: true
|
|
880
|
+
});
|
|
881
|
+
} else {
|
|
882
|
+
obj[key] = value;
|
|
883
|
+
}
|
|
884
|
+
return obj;
|
|
885
|
+
}
|
|
236
886
|
/**
|
|
237
887
|
* Default environment variable for the Discord bot token.
|
|
238
|
-
*/
|
|
239
|
-
const DISCORD_BOT_TOKEN_ENV_VAR = 'DISCORD_BOT_TOKEN';
|
|
888
|
+
*/ var DISCORD_BOT_TOKEN_ENV_VAR = 'DISCORD_BOT_TOKEN';
|
|
240
889
|
/**
|
|
241
890
|
* Default gateway intents for a bot that reads guild messages.
|
|
242
891
|
*
|
|
243
892
|
* Includes Guilds, GuildMessages, and MessageContent.
|
|
244
893
|
* Note: MessageContent is a privileged intent and must be enabled in the Discord Developer Portal.
|
|
245
|
-
*/
|
|
246
|
-
|
|
894
|
+
*/ var DISCORD_DEFAULT_INTENTS = [
|
|
895
|
+
discord_js.GatewayIntentBits.Guilds,
|
|
896
|
+
discord_js.GatewayIntentBits.GuildMessages,
|
|
897
|
+
discord_js.GatewayIntentBits.MessageContent
|
|
898
|
+
];
|
|
247
899
|
/**
|
|
248
900
|
* Configuration for the DiscordApi service.
|
|
249
|
-
*/
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
901
|
+
*/ var DiscordServiceConfig = /*#__PURE__*/ function() {
|
|
902
|
+
function DiscordServiceConfig() {
|
|
903
|
+
_class_call_check$2(this, DiscordServiceConfig);
|
|
904
|
+
_define_property$2(this, "discord", void 0);
|
|
905
|
+
}
|
|
906
|
+
_create_class$1(DiscordServiceConfig, null, [
|
|
907
|
+
{
|
|
908
|
+
key: "assertValidConfig",
|
|
909
|
+
value: function assertValidConfig(config) {
|
|
910
|
+
if (!config.discord.botToken) {
|
|
911
|
+
throw new Error('No Discord bot token specified.');
|
|
912
|
+
}
|
|
913
|
+
}
|
|
255
914
|
}
|
|
915
|
+
]);
|
|
916
|
+
return DiscordServiceConfig;
|
|
917
|
+
}
|
|
918
|
+
();
|
|
919
|
+
|
|
920
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
921
|
+
try {
|
|
922
|
+
var info = gen[key](arg);
|
|
923
|
+
var value = info.value;
|
|
924
|
+
} catch (error) {
|
|
925
|
+
reject(error);
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (info.done) {
|
|
929
|
+
resolve(value);
|
|
930
|
+
} else {
|
|
931
|
+
Promise.resolve(value).then(_next, _throw);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function _async_to_generator(fn) {
|
|
935
|
+
return function() {
|
|
936
|
+
var self = this, args = arguments;
|
|
937
|
+
return new Promise(function(resolve, reject) {
|
|
938
|
+
var gen = fn.apply(self, args);
|
|
939
|
+
function _next(value) {
|
|
940
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
941
|
+
}
|
|
942
|
+
function _throw(err) {
|
|
943
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
944
|
+
}
|
|
945
|
+
_next(undefined);
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function _class_call_check$1(instance, Constructor) {
|
|
950
|
+
if (!(instance instanceof Constructor)) {
|
|
951
|
+
throw new TypeError("Cannot call a class as a function");
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
function _defineProperties(target, props) {
|
|
955
|
+
for(var i = 0; i < props.length; i++){
|
|
956
|
+
var descriptor = props[i];
|
|
957
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
958
|
+
descriptor.configurable = true;
|
|
959
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
960
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
964
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
965
|
+
return Constructor;
|
|
966
|
+
}
|
|
967
|
+
function _define_property$1(obj, key, value) {
|
|
968
|
+
if (key in obj) {
|
|
969
|
+
Object.defineProperty(obj, key, {
|
|
970
|
+
value: value,
|
|
971
|
+
enumerable: true,
|
|
972
|
+
configurable: true,
|
|
973
|
+
writable: true
|
|
974
|
+
});
|
|
975
|
+
} else {
|
|
976
|
+
obj[key] = value;
|
|
977
|
+
}
|
|
978
|
+
return obj;
|
|
979
|
+
}
|
|
980
|
+
function _instanceof(left, right) {
|
|
981
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
982
|
+
return !!right[Symbol.hasInstance](left);
|
|
983
|
+
} else {
|
|
984
|
+
return left instanceof right;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function _object_spread$1(target) {
|
|
988
|
+
for(var i = 1; i < arguments.length; i++){
|
|
989
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
990
|
+
var ownKeys = Object.keys(source);
|
|
991
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
992
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
993
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
994
|
+
}));
|
|
995
|
+
}
|
|
996
|
+
ownKeys.forEach(function(key) {
|
|
997
|
+
_define_property$1(target, key, source[key]);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
return target;
|
|
1001
|
+
}
|
|
1002
|
+
function _ts_generator(thisArg, body) {
|
|
1003
|
+
var f, y, t, _ = {
|
|
1004
|
+
label: 0,
|
|
1005
|
+
sent: function() {
|
|
1006
|
+
if (t[0] & 1) throw t[1];
|
|
1007
|
+
return t[1];
|
|
1008
|
+
},
|
|
1009
|
+
trys: [],
|
|
1010
|
+
ops: []
|
|
1011
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1012
|
+
return d(g, "next", {
|
|
1013
|
+
value: verb(0)
|
|
1014
|
+
}), d(g, "throw", {
|
|
1015
|
+
value: verb(1)
|
|
1016
|
+
}), d(g, "return", {
|
|
1017
|
+
value: verb(2)
|
|
1018
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1019
|
+
value: function() {
|
|
1020
|
+
return this;
|
|
1021
|
+
}
|
|
1022
|
+
}), g;
|
|
1023
|
+
function verb(n) {
|
|
1024
|
+
return function(v) {
|
|
1025
|
+
return step([
|
|
1026
|
+
n,
|
|
1027
|
+
v
|
|
1028
|
+
]);
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
function step(op) {
|
|
1032
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1033
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1034
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1035
|
+
if (y = 0, t) op = [
|
|
1036
|
+
op[0] & 2,
|
|
1037
|
+
t.value
|
|
1038
|
+
];
|
|
1039
|
+
switch(op[0]){
|
|
1040
|
+
case 0:
|
|
1041
|
+
case 1:
|
|
1042
|
+
t = op;
|
|
1043
|
+
break;
|
|
1044
|
+
case 4:
|
|
1045
|
+
_.label++;
|
|
1046
|
+
return {
|
|
1047
|
+
value: op[1],
|
|
1048
|
+
done: false
|
|
1049
|
+
};
|
|
1050
|
+
case 5:
|
|
1051
|
+
_.label++;
|
|
1052
|
+
y = op[1];
|
|
1053
|
+
op = [
|
|
1054
|
+
0
|
|
1055
|
+
];
|
|
1056
|
+
continue;
|
|
1057
|
+
case 7:
|
|
1058
|
+
op = _.ops.pop();
|
|
1059
|
+
_.trys.pop();
|
|
1060
|
+
continue;
|
|
1061
|
+
default:
|
|
1062
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1063
|
+
_ = 0;
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1067
|
+
_.label = op[1];
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1071
|
+
_.label = t[1];
|
|
1072
|
+
t = op;
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
if (t && _.label < t[2]) {
|
|
1076
|
+
_.label = t[2];
|
|
1077
|
+
_.ops.push(op);
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
if (t[2]) _.ops.pop();
|
|
1081
|
+
_.trys.pop();
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
op = body.call(thisArg, _);
|
|
1085
|
+
} catch (e) {
|
|
1086
|
+
op = [
|
|
1087
|
+
6,
|
|
1088
|
+
e
|
|
1089
|
+
];
|
|
1090
|
+
y = 0;
|
|
1091
|
+
} finally{
|
|
1092
|
+
f = t = 0;
|
|
1093
|
+
}
|
|
1094
|
+
if (op[0] & 5) throw op[1];
|
|
1095
|
+
return {
|
|
1096
|
+
value: op[0] ? op[1] : void 0,
|
|
1097
|
+
done: true
|
|
1098
|
+
};
|
|
256
1099
|
}
|
|
257
1100
|
}
|
|
258
|
-
|
|
259
1101
|
/**
|
|
260
1102
|
* Injectable service that wraps the discord.js Client for bot operations.
|
|
261
1103
|
*
|
|
262
1104
|
* Automatically logs in on module init and destroys the client on module destroy
|
|
263
1105
|
* when autoLogin is enabled (default).
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
1106
|
+
*/ exports.DiscordApi = /*#__PURE__*/ function() {
|
|
1107
|
+
function DiscordApi(config) {
|
|
1108
|
+
_class_call_check$1(this, DiscordApi);
|
|
1109
|
+
_define_property$1(this, "config", void 0);
|
|
1110
|
+
_define_property$1(this, "logger", new common.Logger('DiscordApi'));
|
|
1111
|
+
/**
|
|
269
1112
|
* The underlying discord.js Client instance.
|
|
270
|
-
*/
|
|
271
|
-
client;
|
|
272
|
-
constructor(config) {
|
|
1113
|
+
*/ _define_property$1(this, "client", void 0);
|
|
273
1114
|
this.config = config;
|
|
274
|
-
|
|
275
|
-
this.client = new discord_js.Client({
|
|
276
|
-
intents: DISCORD_DEFAULT_INTENTS
|
|
277
|
-
|
|
278
|
-
});
|
|
1115
|
+
var clientOptions = config.discord.clientOptions;
|
|
1116
|
+
this.client = new discord_js.Client(_object_spread$1({
|
|
1117
|
+
intents: DISCORD_DEFAULT_INTENTS
|
|
1118
|
+
}, clientOptions));
|
|
279
1119
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
1120
|
+
_create_class(DiscordApi, [
|
|
1121
|
+
{
|
|
1122
|
+
key: "onModuleInit",
|
|
1123
|
+
value: function onModuleInit() {
|
|
1124
|
+
return _async_to_generator(function() {
|
|
1125
|
+
var _this, _this_config_discord, _this_config_discord_autoLogin, autoLogin, botToken, result;
|
|
1126
|
+
return _ts_generator(this, function(_state) {
|
|
1127
|
+
_this = this;
|
|
1128
|
+
_this_config_discord = this.config.discord, _this_config_discord_autoLogin = _this_config_discord.autoLogin, autoLogin = _this_config_discord_autoLogin === void 0 ? true : _this_config_discord_autoLogin, botToken = _this_config_discord.botToken;
|
|
1129
|
+
if (autoLogin) {
|
|
1130
|
+
result = this.client.login(botToken).then(function() {}).catch(function(e) {
|
|
1131
|
+
_this.logger.error('Failed to log in to Discord', e);
|
|
1132
|
+
});
|
|
1133
|
+
} else {
|
|
1134
|
+
result = Promise.resolve();
|
|
1135
|
+
}
|
|
1136
|
+
return [
|
|
1137
|
+
2,
|
|
1138
|
+
result
|
|
1139
|
+
];
|
|
1140
|
+
});
|
|
1141
|
+
}).call(this);
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
key: "onModuleDestroy",
|
|
1146
|
+
value: function onModuleDestroy() {
|
|
1147
|
+
return _async_to_generator(function() {
|
|
1148
|
+
return _ts_generator(this, function(_state) {
|
|
1149
|
+
return [
|
|
1150
|
+
2,
|
|
1151
|
+
this.client.destroy()
|
|
1152
|
+
];
|
|
1153
|
+
});
|
|
1154
|
+
}).call(this);
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
key: "sendMessage",
|
|
1159
|
+
value: /**
|
|
300
1160
|
* Sends a text message to a Discord channel.
|
|
301
1161
|
*
|
|
302
1162
|
* @param channelId - target channel's snowflake ID
|
|
@@ -308,15 +1168,32 @@ exports.DiscordApi = class DiscordApi {
|
|
|
308
1168
|
* ```ts
|
|
309
1169
|
* const message = await discordApi.sendMessage('123456789', 'Hello from the bot!');
|
|
310
1170
|
* ```
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
1171
|
+
*/ function sendMessage(channelId, content) {
|
|
1172
|
+
return _async_to_generator(function() {
|
|
1173
|
+
var channel;
|
|
1174
|
+
return _ts_generator(this, function(_state) {
|
|
1175
|
+
switch(_state.label){
|
|
1176
|
+
case 0:
|
|
1177
|
+
return [
|
|
1178
|
+
4,
|
|
1179
|
+
this.client.channels.fetch(channelId)
|
|
1180
|
+
];
|
|
1181
|
+
case 1:
|
|
1182
|
+
channel = _state.sent();
|
|
1183
|
+
if (!channel || !_instanceof(channel, discord_js.TextChannel)) {
|
|
1184
|
+
throw new Error("Channel ".concat(channelId, " not found or is not a text channel."));
|
|
1185
|
+
}
|
|
1186
|
+
return [
|
|
1187
|
+
2,
|
|
1188
|
+
channel.send(content)
|
|
1189
|
+
];
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
}).call(this);
|
|
1193
|
+
}
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
/**
|
|
320
1197
|
* Registers a handler for the MessageCreate event (incoming messages).
|
|
321
1198
|
*
|
|
322
1199
|
* Returns an unsubscribe function to remove the handler.
|
|
@@ -334,22 +1211,32 @@ exports.DiscordApi = class DiscordApi {
|
|
|
334
1211
|
* // Later, to stop listening:
|
|
335
1212
|
* unsubscribe();
|
|
336
1213
|
* ```
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
1214
|
+
*/ key: "onMessage",
|
|
1215
|
+
value: function onMessage(handler) {
|
|
1216
|
+
var _this = this;
|
|
1217
|
+
this.client.on(discord_js.Events.MessageCreate, handler);
|
|
1218
|
+
return function() {
|
|
1219
|
+
return _this.client.off(discord_js.Events.MessageCreate, handler);
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
]);
|
|
1224
|
+
return DiscordApi;
|
|
1225
|
+
}();
|
|
343
1226
|
exports.DiscordApi = __decorate([
|
|
344
1227
|
common.Injectable(),
|
|
345
1228
|
__param(0, common.Inject(DiscordServiceConfig))
|
|
346
1229
|
], exports.DiscordApi);
|
|
347
1230
|
|
|
1231
|
+
function _class_call_check(instance, Constructor) {
|
|
1232
|
+
if (!(instance instanceof Constructor)) {
|
|
1233
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
348
1236
|
/**
|
|
349
1237
|
* Factory that creates a DiscordServiceConfig from environment variables.
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
const config = {
|
|
1238
|
+
*/ function discordServiceConfigFactory(configService) {
|
|
1239
|
+
var config = {
|
|
353
1240
|
discord: {
|
|
354
1241
|
botToken: configService.get(DISCORD_BOT_TOKEN_ENV_VAR),
|
|
355
1242
|
autoLogin: true
|
|
@@ -362,28 +1249,80 @@ function discordServiceConfigFactory(configService) {
|
|
|
362
1249
|
* NestJS module that provides the DiscordApi service.
|
|
363
1250
|
*
|
|
364
1251
|
* Reads the bot token from the DISCORD_BOT_TOKEN environment variable.
|
|
365
|
-
*/
|
|
366
|
-
|
|
1252
|
+
*/ exports.DiscordModule = function DiscordModule() {
|
|
1253
|
+
_class_call_check(this, DiscordModule);
|
|
367
1254
|
};
|
|
368
1255
|
exports.DiscordModule = __decorate([
|
|
369
1256
|
common.Module({
|
|
370
|
-
imports: [
|
|
1257
|
+
imports: [
|
|
1258
|
+
config.ConfigModule
|
|
1259
|
+
],
|
|
371
1260
|
providers: [
|
|
372
1261
|
{
|
|
373
1262
|
provide: DiscordServiceConfig,
|
|
374
|
-
inject: [
|
|
1263
|
+
inject: [
|
|
1264
|
+
config.ConfigService
|
|
1265
|
+
],
|
|
375
1266
|
useFactory: discordServiceConfigFactory
|
|
376
1267
|
},
|
|
377
1268
|
exports.DiscordApi
|
|
378
1269
|
],
|
|
379
|
-
exports: [
|
|
1270
|
+
exports: [
|
|
1271
|
+
exports.DiscordApi
|
|
1272
|
+
]
|
|
380
1273
|
})
|
|
381
1274
|
], exports.DiscordModule);
|
|
382
1275
|
|
|
1276
|
+
function _define_property(obj, key, value) {
|
|
1277
|
+
if (key in obj) {
|
|
1278
|
+
Object.defineProperty(obj, key, {
|
|
1279
|
+
value: value,
|
|
1280
|
+
enumerable: true,
|
|
1281
|
+
configurable: true,
|
|
1282
|
+
writable: true
|
|
1283
|
+
});
|
|
1284
|
+
} else {
|
|
1285
|
+
obj[key] = value;
|
|
1286
|
+
}
|
|
1287
|
+
return obj;
|
|
1288
|
+
}
|
|
1289
|
+
function _object_spread(target) {
|
|
1290
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1291
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1292
|
+
var ownKeys = Object.keys(source);
|
|
1293
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1294
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1295
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1296
|
+
}));
|
|
1297
|
+
}
|
|
1298
|
+
ownKeys.forEach(function(key) {
|
|
1299
|
+
_define_property(target, key, source[key]);
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
return target;
|
|
1303
|
+
}
|
|
1304
|
+
function ownKeys(object, enumerableOnly) {
|
|
1305
|
+
var keys = Object.keys(object);
|
|
1306
|
+
if (Object.getOwnPropertySymbols) {
|
|
1307
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
1308
|
+
keys.push.apply(keys, symbols);
|
|
1309
|
+
}
|
|
1310
|
+
return keys;
|
|
1311
|
+
}
|
|
1312
|
+
function _object_spread_props(target, source) {
|
|
1313
|
+
source = source != null ? source : {};
|
|
1314
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
1315
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1316
|
+
} else {
|
|
1317
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
1318
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
return target;
|
|
1322
|
+
}
|
|
383
1323
|
/**
|
|
384
1324
|
* Default number of messages per page when fetching Discord channel messages.
|
|
385
|
-
*/
|
|
386
|
-
const DISCORD_DEFAULT_MESSAGES_PER_PAGE = 100;
|
|
1325
|
+
*/ var DISCORD_DEFAULT_MESSAGES_PER_PAGE = 100;
|
|
387
1326
|
/**
|
|
388
1327
|
* Creates a page factory that wraps a Discord message fetch function with automatic cursor-based pagination.
|
|
389
1328
|
*
|
|
@@ -407,40 +1346,67 @@ const DISCORD_DEFAULT_MESSAGES_PER_PAGE = 100;
|
|
|
407
1346
|
* const secondPage = await firstPage.fetchNext();
|
|
408
1347
|
* }
|
|
409
1348
|
* ```
|
|
410
|
-
*/
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
1349
|
+
*/ function discordFetchMessagePageFactory(fetch$1, config, defaults) {
|
|
1350
|
+
var _ref;
|
|
1351
|
+
var readMessageId = (_ref = config === null || config === void 0 ? void 0 : config.readMessageId) !== null && _ref !== void 0 ? _ref : function(message) {
|
|
1352
|
+
return message.id;
|
|
1353
|
+
};
|
|
1354
|
+
return fetch.fetchPageFactory(_object_spread_props(_object_spread({}, defaults), {
|
|
415
1355
|
fetch: fetch$1,
|
|
416
|
-
readFetchPageResultInfo(result) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1356
|
+
readFetchPageResultInfo: function readFetchPageResultInfo(result) {
|
|
1357
|
+
var count = result.data.length;
|
|
1358
|
+
var lastMessage = util.lastValue(result.data);
|
|
1359
|
+
var nextCursor = lastMessage ? readMessageId(lastMessage) : undefined;
|
|
420
1360
|
return {
|
|
421
1361
|
hasNext: count > 0,
|
|
422
1362
|
nextPageCursor: nextCursor
|
|
423
1363
|
};
|
|
424
1364
|
},
|
|
425
|
-
buildInputForNextPage(pageResult, input, options) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
1365
|
+
buildInputForNextPage: function buildInputForNextPage(pageResult, input, options) {
|
|
1366
|
+
var _ref, _options_maxItemsPerPage, _ref1;
|
|
1367
|
+
var _pageResult_result;
|
|
1368
|
+
var nextCursor = pageResult.nextPageCursor;
|
|
1369
|
+
var effectiveLimit = (_ref = (_options_maxItemsPerPage = options.maxItemsPerPage) !== null && _options_maxItemsPerPage !== void 0 ? _options_maxItemsPerPage : input.limit) !== null && _ref !== void 0 ? _ref : DISCORD_DEFAULT_MESSAGES_PER_PAGE;
|
|
1370
|
+
var resultCount = (_ref1 = (_pageResult_result = pageResult.result) === null || _pageResult_result === void 0 ? void 0 : _pageResult_result.data.length) !== null && _ref1 !== void 0 ? _ref1 : 0;
|
|
429
1371
|
// Discord signals no more results when fewer items than the limit are returned
|
|
430
1372
|
if (!nextCursor || resultCount < effectiveLimit) {
|
|
431
1373
|
return undefined;
|
|
432
1374
|
}
|
|
433
|
-
return {
|
|
434
|
-
...input,
|
|
1375
|
+
return _object_spread_props(_object_spread({}, input), {
|
|
435
1376
|
before: nextCursor,
|
|
436
1377
|
after: undefined,
|
|
437
1378
|
around: undefined,
|
|
438
1379
|
limit: effectiveLimit
|
|
439
|
-
};
|
|
1380
|
+
});
|
|
440
1381
|
}
|
|
441
|
-
});
|
|
1382
|
+
}));
|
|
442
1383
|
}
|
|
443
1384
|
|
|
1385
|
+
function _array_like_to_array(arr, len) {
|
|
1386
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1387
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1388
|
+
return arr2;
|
|
1389
|
+
}
|
|
1390
|
+
function _array_without_holes(arr) {
|
|
1391
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1392
|
+
}
|
|
1393
|
+
function _iterable_to_array(iter) {
|
|
1394
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1395
|
+
}
|
|
1396
|
+
function _non_iterable_spread() {
|
|
1397
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1398
|
+
}
|
|
1399
|
+
function _to_consumable_array(arr) {
|
|
1400
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
1401
|
+
}
|
|
1402
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1403
|
+
if (!o) return;
|
|
1404
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1405
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1406
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1407
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1408
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1409
|
+
}
|
|
444
1410
|
/**
|
|
445
1411
|
* Returns default ClientOptions for a bot that reads guild messages.
|
|
446
1412
|
*
|
|
@@ -451,8 +1417,7 @@ function discordFetchMessagePageFactory(fetch$1, config, defaults) {
|
|
|
451
1417
|
* const options = discordDefaultClientOptions();
|
|
452
1418
|
* // options.intents === [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
|
|
453
1419
|
* ```
|
|
454
|
-
*/
|
|
455
|
-
function discordDefaultClientOptions() {
|
|
1420
|
+
*/ function discordDefaultClientOptions() {
|
|
456
1421
|
return {
|
|
457
1422
|
intents: DISCORD_DEFAULT_INTENTS
|
|
458
1423
|
};
|
|
@@ -467,10 +1432,9 @@ function discordDefaultClientOptions() {
|
|
|
467
1432
|
* const options = discordClientOptionsWithIntents([GatewayIntentBits.DirectMessages]);
|
|
468
1433
|
* // options.intents includes Guilds, GuildMessages, MessageContent, and DirectMessages
|
|
469
1434
|
* ```
|
|
470
|
-
*/
|
|
471
|
-
function discordClientOptionsWithIntents(additionalIntents) {
|
|
1435
|
+
*/ function discordClientOptionsWithIntents(additionalIntents) {
|
|
472
1436
|
return {
|
|
473
|
-
intents:
|
|
1437
|
+
intents: _to_consumable_array(DISCORD_DEFAULT_INTENTS).concat(_to_consumable_array(additionalIntents))
|
|
474
1438
|
};
|
|
475
1439
|
}
|
|
476
1440
|
|