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