lunibee 0.3.3 → 0.4.0

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.
Files changed (125) hide show
  1. package/README.md +1 -1
  2. package/dist/builders/commands.d.ts +1 -1
  3. package/dist/builders/components.d.ts +9 -11
  4. package/dist/builders/embed.d.ts +1 -1
  5. package/dist/builders/index.d.ts +1 -1
  6. package/dist/builders/index.js +87 -1298
  7. package/dist/builders/index.js.map +3 -11
  8. package/dist/chunks/index-0wn81eng.js +2492 -0
  9. package/dist/chunks/index-0wn81eng.js.map +17 -0
  10. package/dist/chunks/index-2en489j6.js +40 -0
  11. package/dist/chunks/index-2en489j6.js.map +10 -0
  12. package/dist/chunks/index-3hyps48a.js +203 -0
  13. package/dist/chunks/index-3hyps48a.js.map +11 -0
  14. package/dist/chunks/index-57c5n3ms.js +2274 -0
  15. package/dist/chunks/index-57c5n3ms.js.map +19 -0
  16. package/dist/chunks/index-5yx92e36.js +1170 -0
  17. package/dist/chunks/index-5yx92e36.js.map +14 -0
  18. package/dist/chunks/index-690bp093.js +95 -0
  19. package/dist/chunks/index-690bp093.js.map +10 -0
  20. package/dist/chunks/index-7fp2hvmg.js +2155 -0
  21. package/dist/chunks/index-7fp2hvmg.js.map +24 -0
  22. package/dist/chunks/index-cnmsajvk.js +1119 -0
  23. package/dist/chunks/index-cnmsajvk.js.map +12 -0
  24. package/dist/chunks/index-fdvgk2sw.js +1310 -0
  25. package/dist/chunks/index-fdvgk2sw.js.map +21 -0
  26. package/dist/chunks/index-gyvps8b9.js +214 -0
  27. package/dist/chunks/index-gyvps8b9.js.map +12 -0
  28. package/dist/chunks/index-jzg4bh99.js +1533 -0
  29. package/dist/chunks/index-jzg4bh99.js.map +21 -0
  30. package/dist/chunks/index-mgw2yvrm.js +3547 -0
  31. package/dist/chunks/index-mgw2yvrm.js.map +25 -0
  32. package/dist/chunks/index-yh76b55h.js +3449 -0
  33. package/dist/chunks/index-yh76b55h.js.map +29 -0
  34. package/dist/collection/index.js +9 -1118
  35. package/dist/collection/index.js.map +3 -6
  36. package/dist/core/api.d.ts +3 -3
  37. package/dist/core/channel-create.d.ts +2 -2
  38. package/dist/core/commands.d.ts +3 -3
  39. package/dist/core/events.d.ts +4 -4
  40. package/dist/core/handles.d.ts +4 -4
  41. package/dist/core/index.d.ts +25 -20
  42. package/dist/core/index.js +68 -10130
  43. package/dist/core/index.js.map +3 -65
  44. package/dist/core/permissions.d.ts +1 -1
  45. package/dist/core/redis-cache.d.ts +1 -1
  46. package/dist/formatters/index.js +41 -110
  47. package/dist/formatters/index.js.map +3 -4
  48. package/dist/handlers/index.js +5 -37
  49. package/dist/handlers/index.js.map +3 -4
  50. package/dist/index.d.ts +21 -21
  51. package/dist/index.js +641 -16325
  52. package/dist/index.js.map +3 -92
  53. package/dist/managers/advanced.d.ts +3 -3
  54. package/dist/managers/application.d.ts +2 -2
  55. package/dist/managers/base.d.ts +1 -1
  56. package/dist/managers/emoji.d.ts +2 -2
  57. package/dist/managers/guild-resources.d.ts +6 -6
  58. package/dist/managers/guild.d.ts +3 -3
  59. package/dist/managers/index.d.ts +4 -8
  60. package/dist/managers/index.js +51 -4060
  61. package/dist/managers/index.js.map +3 -29
  62. package/dist/managers/member.d.ts +2 -2
  63. package/dist/managers/message.d.ts +14 -6
  64. package/dist/managers/role.d.ts +2 -2
  65. package/dist/managers/thread.d.ts +3 -3
  66. package/dist/managers/user.d.ts +7 -4
  67. package/dist/rest/index.d.ts +10 -35
  68. package/dist/rest/index.js +57 -2184
  69. package/dist/rest/index.js.map +3 -18
  70. package/dist/rest/limiter.d.ts +9 -1
  71. package/dist/rest/webhook.d.ts +2 -8
  72. package/dist/sharding/bus.d.ts +2 -2
  73. package/dist/sharding/cluster.d.ts +45 -5
  74. package/dist/sharding/context.d.ts +45 -3
  75. package/dist/sharding/gateway-bot.d.ts +2 -1
  76. package/dist/sharding/health.d.ts +1 -1
  77. package/dist/sharding/identify.d.ts +12 -0
  78. package/dist/sharding/index.d.ts +44 -11
  79. package/dist/sharding/index.js +60 -4620
  80. package/dist/sharding/index.js.map +3 -33
  81. package/dist/sharding/supervisor.d.ts +4 -2
  82. package/dist/structures/audit-log.d.ts +1 -1
  83. package/dist/structures/base.d.ts +6 -6
  84. package/dist/structures/channels.d.ts +1 -1
  85. package/dist/structures/embed.d.ts +1 -1
  86. package/dist/structures/index.d.ts +14 -14
  87. package/dist/structures/index.js +109 -2382
  88. package/dist/structures/index.js.map +3 -16
  89. package/dist/structures/interactions.d.ts +13 -9
  90. package/dist/structures/options.d.ts +1 -1
  91. package/dist/structures/permissions.d.ts +2 -2
  92. package/dist/structures/resources.d.ts +10 -10
  93. package/dist/structures/sticker.d.ts +1 -1
  94. package/dist/types/gateway.d.ts +2 -79
  95. package/dist/types/index.d.ts +0 -6
  96. package/dist/types/index.js +41 -272
  97. package/dist/types/index.js.map +3 -6
  98. package/dist/utils/index.js +23 -209
  99. package/dist/utils/index.js.map +3 -5
  100. package/dist/voice/connection.d.ts +200 -0
  101. package/dist/voice/crypto.d.ts +50 -0
  102. package/dist/voice/dave.d.ts +85 -0
  103. package/dist/voice/effects.d.ts +31 -0
  104. package/dist/voice/emitter.d.ts +14 -0
  105. package/dist/voice/gateway.d.ts +59 -0
  106. package/dist/voice/index.d.ts +25 -228
  107. package/dist/voice/index.js +111 -442
  108. package/dist/voice/index.js.map +3 -4
  109. package/dist/voice/libopus.d.ts +88 -0
  110. package/dist/voice/networking.d.ts +80 -0
  111. package/dist/voice/ogg.d.ts +24 -0
  112. package/dist/voice/opus.d.ts +18 -0
  113. package/dist/voice/player.d.ts +79 -0
  114. package/dist/voice/protocol.d.ts +76 -0
  115. package/dist/voice/receiver.d.ts +59 -0
  116. package/dist/voice/resource.d.ts +102 -0
  117. package/dist/voice/udp.d.ts +40 -0
  118. package/dist/ws/close-codes.d.ts +1 -1
  119. package/dist/ws/index.d.ts +25 -4
  120. package/dist/ws/index.js +47 -1336
  121. package/dist/ws/index.js.map +3 -17
  122. package/dist/ws/protocol.d.ts +1 -1
  123. package/dist/ws/send-budget.d.ts +0 -2
  124. package/dist/ws/state.d.ts +0 -10
  125. package/package.json +19 -16
@@ -1,4062 +1,53 @@
1
1
  // @bun
2
- // packages/collection/src/redis.ts
3
- var PRELUDE = `
4
- local exp, lru, clock, ep = KEYS[1], KEYS[2], KEYS[3], ARGV[1]
5
- local t = redis.call('TIME')
6
- local now = tonumber(t[1]) * 1000 + math.floor(tonumber(t[2]) / 1000)
7
- local out = {}
8
- local function drop(m, reason)
9
- local v = redis.call('GET', ep .. m)
10
- redis.call('DEL', ep .. m)
11
- redis.call('ZREM', exp, m)
12
- redis.call('ZREM', lru, m)
13
- if reason then
14
- table.insert(out, m)
15
- table.insert(out, v or false)
16
- table.insert(out, reason)
17
- end
18
- end
19
- local gone = redis.call('ZRANGEBYSCORE', exp, '-inf', now, 'LIMIT', 0, 1000)
20
- for _, m in ipairs(gone) do drop(m, 'expired') end
21
- local function touch(m) redis.call('ZADD', lru, redis.call('INCR', clock), m) end
22
- `;
23
- var SET_SCRIPT = `${PRELUDE}
24
- local m, payload, ttl, max, mode = ARGV[2], ARGV[3], tonumber(ARGV[4]), tonumber(ARGV[5]), ARGV[6]
25
- if mode == 'nx' then
26
- local cur = redis.call('GET', ep .. m)
27
- if cur then
28
- touch(m)
29
- table.insert(out, 1, cur)
30
- return out
31
- end
32
- end
33
- local env = ttl .. ':' .. payload
34
- if ttl > 0 then
35
- -- The key outlives its logical expiry by a grace second, so the prune
36
- -- that reports the expiry can still hand the value to onEvict.
37
- redis.call('SET', ep .. m, env, 'PX', ttl + 1000)
38
- redis.call('ZADD', exp, now + ttl, m)
39
- else
40
- redis.call('SET', ep .. m, env)
41
- redis.call('ZREM', exp, m)
42
- end
43
- touch(m)
44
- if max > 0 then
45
- local n = redis.call('ZCARD', lru)
46
- while n > max do
47
- local popped = redis.call('ZPOPMIN', lru)
48
- local victim = popped[1]
49
- if victim == nil then break end
50
- if victim ~= m then drop(victim, 'evicted') end
51
- n = n - 1
52
- end
53
- end
54
- table.insert(out, 1, false)
55
- return out
56
- `;
57
- var GET_SCRIPT = `${PRELUDE}
58
- local m, slide, mark = ARGV[2], ARGV[3], ARGV[4]
59
- local env = redis.call('GET', ep .. m)
60
- if not env then
61
- redis.call('ZREM', exp, m)
62
- redis.call('ZREM', lru, m)
63
- table.insert(out, 1, false)
64
- return out
65
- end
66
- if mark == '1' then touch(m) end
67
- if slide == '1' then
68
- local ttl = tonumber(string.match(env, '^(%d+):'))
69
- if ttl and ttl > 0 then
70
- redis.call('PEXPIRE', ep .. m, ttl + 1000)
71
- redis.call('ZADD', exp, now + ttl, m)
72
- end
73
- end
74
- table.insert(out, 1, env)
75
- return out
76
- `;
77
- var DELETE_SCRIPT = `${PRELUDE}
78
- local m = ARGV[2]
79
- local existed = redis.call('EXISTS', ep .. m)
80
- drop(m, nil)
81
- table.insert(out, 1, existed)
82
- return out
83
- `;
84
- var LIST_SCRIPT = `${PRELUDE}
85
- local what = ARGV[2]
86
- if what == 'clear' then
87
- local n = 0
88
- repeat
89
- local batch = redis.call('ZRANGE', lru, 0, 999)
90
- for _, m in ipairs(batch) do drop(m, nil) end
91
- n = n + #batch
92
- until #batch == 0
93
- redis.call('DEL', exp, lru, clock)
94
- return {n}
95
- end
96
- local result = what == 'size' and redis.call('ZCARD', lru) or redis.call('ZRANGE', lru, 0, -1)
97
- return {result, unpack(out)}
98
- `;
99
-
100
- // packages/collection/src/index.ts
101
- function newPolicy(options = {}) {
102
- return {
103
- ttl: options.ttl,
104
- jitter: options.jitter ?? 0,
105
- maxSize: options.maxSize,
106
- slide: options.slide ?? true,
107
- onEvict: options.onEvict,
108
- expired: 0,
109
- evicted: 0,
110
- entries: new Map,
111
- oldest: undefined,
112
- newest: undefined,
113
- lruSize: 0,
114
- heap: [],
115
- armedFor: Infinity
116
- };
117
- }
118
- function peekOf(collection, key) {
119
- return collection instanceof Map ? Map.prototype.get.call(collection, key) : collection.get(key);
120
- }
121
- var mapGet = Map.prototype.get;
122
- var mapHas = Map.prototype.has;
123
- function sample(items, amount) {
124
- if (!Number.isInteger(amount) || amount < 0)
125
- throw new RangeError("amount must be a non-negative integer.");
126
- const count = Math.min(amount, items.length);
127
- for (let i = 0;i < count; i++) {
128
- const j = i + Math.floor(Math.random() * (items.length - i));
129
- [items[i], items[j]] = [items[j], items[i]];
130
- }
131
- items.length = count;
132
- return items;
133
- }
134
- function assertTTL(ttl) {
135
- if (ttl !== undefined && (!Number.isFinite(ttl) || ttl <= 0))
136
- throw new RangeError("TTL must be a positive number, or omitted.");
137
- }
138
-
139
- class Collection extends Map {
140
- #policy;
141
- #hits = 0;
142
- #misses = 0;
143
- constructor(entries, options = {}) {
144
- super();
145
- assertTTL(options.ttl);
146
- if (options.jitter !== undefined && !(options.jitter >= 0 && options.jitter <= 1))
147
- throw new RangeError("jitter must be between 0 and 1.");
148
- if (options.maxSize !== undefined && (!Number.isInteger(options.maxSize) || options.maxSize <= 0))
149
- throw new RangeError("maxSize must be a positive integer.");
150
- if (options.ttl !== undefined || options.jitter !== undefined || options.maxSize !== undefined || options.slide !== undefined || options.onEvict !== undefined)
151
- this.#policy = newPolicy(options);
152
- if (entries)
153
- for (const [key, value] of entries)
154
- this.set(key, value);
155
- }
156
- set(key, value, ttl) {
157
- let policy = this.#policy;
158
- if (ttl === undefined && policy === undefined)
159
- return super.set(key, value);
160
- if (ttl !== undefined)
161
- assertTTL(ttl);
162
- let window = ttl ?? policy?.ttl;
163
- if (window !== undefined && policy !== undefined && policy.jitter > 0)
164
- window = Math.max(1, window * (1 - policy.jitter * Math.random()));
165
- if (policy === undefined) {
166
- if (window === undefined)
167
- return super.set(key, value);
168
- policy = this.#policy = newPolicy();
169
- }
170
- const entry = policy.entries.get(key);
171
- super.set(key, value);
172
- if (entry !== undefined && window !== undefined && entry.window !== 0) {
173
- const deadline = Date.now() + window;
174
- if (deadline >= entry.filed) {
175
- entry.value = value;
176
- entry.deadline = deadline;
177
- entry.window = window;
178
- if (entry.inLru)
179
- this.#promote(policy, entry);
180
- return this;
181
- }
182
- }
183
- this.#track(key, value, window, entry);
184
- if (policy.maxSize !== undefined && policy.lruSize > policy.maxSize)
185
- this.#enforceCap();
186
- return this;
187
- }
188
- setWithoutTTL(key, value) {
189
- if (this.#policy)
190
- this.#forget(key);
191
- super.set(key, value);
192
- return this;
193
- }
194
- get(key) {
195
- const policy = this.#policy;
196
- const entry = policy?.entries.get(key);
197
- if (entry === undefined) {
198
- const value = mapGet.call(this, key);
199
- if (value !== undefined || mapHas.call(this, key)) {
200
- this.#hits++;
201
- return value;
202
- }
203
- this.#misses++;
204
- return;
205
- }
206
- const timed = entry.window !== 0;
207
- const now = timed ? Date.now() : 0;
208
- if (timed && entry.deadline <= now) {
209
- this.#expire(entry);
210
- this.#misses++;
211
- return;
212
- }
213
- this.#hits++;
214
- if (timed && policy.slide)
215
- entry.deadline = now + entry.window;
216
- if (entry.inLru)
217
- this.#promote(policy, entry);
218
- return entry.value;
219
- }
220
- ensure(key, factory, ttl) {
221
- const existing = this.get(key);
222
- if (existing !== undefined || super.has(key))
223
- return existing;
224
- const created = factory(key, this);
225
- this.set(key, created, ttl);
226
- return created;
227
- }
228
- peek(key) {
229
- if (!this.#expireIfDue(key) && super.has(key)) {
230
- this.#hits++;
231
- return super.get(key);
232
- }
233
- this.#misses++;
234
- return;
235
- }
236
- get stats() {
237
- return {
238
- hits: this.#hits,
239
- misses: this.#misses,
240
- expired: this.#policy?.expired ?? 0,
241
- evicted: this.#policy?.evicted ?? 0
242
- };
243
- }
244
- has(key) {
245
- return !this.#expireIfDue(key) && super.has(key);
246
- }
247
- delete(key) {
248
- if (this.#expireIfDue(key))
249
- return false;
250
- if (this.#policy)
251
- this.#forget(key);
252
- return super.delete(key);
253
- }
254
- clear() {
255
- super.clear();
256
- const policy = this.#policy;
257
- if (!policy)
258
- return;
259
- policy.entries.clear();
260
- policy.oldest = policy.newest = undefined;
261
- policy.lruSize = 0;
262
- policy.heap.length = 0;
263
- if (policy.timer)
264
- clearTimeout(policy.timer);
265
- policy.timer = undefined;
266
- policy.armedFor = Infinity;
267
- }
268
- get size() {
269
- this.purge();
270
- return super.size;
271
- }
272
- entries() {
273
- this.purge();
274
- return super.entries();
275
- }
276
- keys() {
277
- this.purge();
278
- return super.keys();
279
- }
280
- values() {
281
- this.purge();
282
- return super.values();
283
- }
284
- [Symbol.iterator]() {
285
- return this.entries();
286
- }
287
- forEach(callback, thisArg) {
288
- this.purge();
289
- super.forEach(callback, thisArg);
290
- }
291
- ttlRemaining(key) {
292
- if (this.#expireIfDue(key))
293
- return;
294
- const entry = this.#policy?.entries.get(key);
295
- return entry && entry.window !== 0 ? Math.max(0, entry.deadline - Date.now()) : undefined;
296
- }
297
- purge() {
298
- if (!this.#policy || this.#policy.heap.length === 0)
299
- return 0;
300
- const now = Date.now();
301
- let removed = 0;
302
- const dropped = [];
303
- while (this.#nextDeadline() <= now) {
304
- const due = this.#heapPop();
305
- dropped.push([due.key, super.get(due.key)]);
306
- this.#remove(due.key);
307
- removed++;
308
- }
309
- this.#policy.expired += removed;
310
- this.#rearm();
311
- for (const [key, value] of dropped)
312
- this.#notify(key, value, "expired");
313
- return removed;
314
- }
315
- #expireIfDue(key) {
316
- const entry = this.#policy?.entries.get(key);
317
- if (!entry || entry.window === 0 || entry.deadline > Date.now())
318
- return false;
319
- this.#expire(entry);
320
- return true;
321
- }
322
- #expire(entry) {
323
- const value = super.get(entry.key);
324
- this.#remove(entry.key);
325
- this.#policy.expired++;
326
- this.#notify(entry.key, value, "expired");
327
- }
328
- #remove(key) {
329
- this.#forget(key);
330
- super.delete(key);
331
- }
332
- #forget(key) {
333
- const policy = this.#policy;
334
- const entry = policy.entries.get(key);
335
- if (!entry)
336
- return;
337
- if (entry.inLru)
338
- this.#unlink(policy, entry);
339
- policy.entries.delete(key);
340
- }
341
- #track(key, value, window, existing) {
342
- const policy = this.#policy;
343
- const lru = policy.maxSize !== undefined;
344
- let entry = existing;
345
- if (entry)
346
- entry.value = value;
347
- if (window === undefined) {
348
- if (entry && entry.window !== 0) {
349
- if (lru)
350
- entry = this.#replace(policy, entry, 0, 0);
351
- else {
352
- this.#forget(key);
353
- return;
354
- }
355
- }
356
- if (!entry && lru) {
357
- entry = this.#create(key, value, 0, 0);
358
- policy.entries.set(key, entry);
359
- }
360
- if (entry)
361
- this.#promote(policy, entry);
362
- return;
363
- }
364
- const deadline = Date.now() + window;
365
- if (entry && entry.window !== 0) {
366
- entry.deadline = deadline;
367
- entry.window = window;
368
- if (deadline < entry.filed)
369
- entry = this.#replace(policy, entry, window, deadline);
370
- else {
371
- if (entry.inLru)
372
- this.#promote(policy, entry);
373
- return;
374
- }
375
- } else if (entry) {
376
- entry.window = window;
377
- entry.deadline = entry.filed = deadline;
378
- } else {
379
- entry = this.#create(key, value, window, deadline);
380
- policy.entries.set(key, entry);
381
- }
382
- if (lru)
383
- this.#promote(policy, entry);
384
- this.#heapPush(entry);
385
- if (policy.heap.length > 2 * policy.entries.size + 8)
386
- this.#compact();
387
- if (policy.timer === undefined || deadline < policy.armedFor)
388
- this.#rearm();
389
- }
390
- #create(key, value, window, deadline) {
391
- return {
392
- key,
393
- value,
394
- older: undefined,
395
- newer: undefined,
396
- inLru: false,
397
- window,
398
- deadline,
399
- filed: deadline
400
- };
401
- }
402
- #replace(policy, old, window, deadline) {
403
- const entry = {
404
- ...old,
405
- window,
406
- deadline,
407
- filed: deadline
408
- };
409
- if (old.inLru) {
410
- if (old.older)
411
- old.older.newer = entry;
412
- else
413
- policy.oldest = entry;
414
- if (old.newer)
415
- old.newer.older = entry;
416
- else
417
- policy.newest = entry;
418
- }
419
- policy.entries.set(old.key, entry);
420
- return entry;
421
- }
422
- #promote(policy, entry) {
423
- if (entry === policy.newest)
424
- return;
425
- if (entry.inLru)
426
- this.#unlink(policy, entry, true);
427
- else {
428
- entry.inLru = true;
429
- policy.lruSize++;
430
- }
431
- entry.older = policy.newest;
432
- entry.newer = undefined;
433
- if (policy.newest)
434
- policy.newest.newer = entry;
435
- else
436
- policy.oldest = entry;
437
- policy.newest = entry;
438
- }
439
- #unlink(policy, entry, keepCount = false) {
440
- if (entry.older)
441
- entry.older.newer = entry.newer;
442
- else
443
- policy.oldest = entry.newer;
444
- if (entry.newer)
445
- entry.newer.older = entry.older;
446
- else
447
- policy.newest = entry.older;
448
- entry.older = entry.newer = undefined;
449
- if (!keepCount) {
450
- entry.inLru = false;
451
- policy.lruSize--;
452
- }
453
- }
454
- #derived() {
455
- const Species = this.constructor[Symbol.species] ?? Collection;
456
- return new Species;
457
- }
458
- #notify(key, value, reason) {
459
- const onEvict = this.#policy?.onEvict;
460
- if (!onEvict)
461
- return;
462
- try {
463
- onEvict(key, value, reason);
464
- } catch {}
465
- }
466
- #enforceCap() {
467
- const policy = this.#policy;
468
- const max = policy.maxSize;
469
- if (max === undefined)
470
- return;
471
- if (policy.lruSize > max && policy.heap.length > 0 && policy.heap[0].filed <= Date.now())
472
- this.purge();
473
- while (policy.lruSize > max) {
474
- const oldest = policy.oldest;
475
- const value = policy.onEvict ? super.get(oldest.key) : undefined;
476
- const next = oldest.newer;
477
- policy.oldest = next;
478
- if (next)
479
- next.older = undefined;
480
- else
481
- policy.newest = undefined;
482
- oldest.newer = undefined;
483
- oldest.inLru = false;
484
- policy.lruSize--;
485
- policy.entries.delete(oldest.key);
486
- super.delete(oldest.key);
487
- policy.evicted++;
488
- if (policy.onEvict)
489
- this.#notify(oldest.key, value, "evicted");
490
- }
491
- }
492
- #nextDeadline() {
493
- const policy = this.#policy;
494
- for (;; ) {
495
- const top = policy.heap[0];
496
- if (top === undefined)
497
- return Infinity;
498
- if (policy.entries.get(top.key) !== top) {
499
- this.#heapPop();
500
- continue;
501
- }
502
- if (top.deadline === top.filed)
503
- return top.filed;
504
- this.#heapPop();
505
- top.filed = top.deadline;
506
- this.#heapPush(top);
507
- }
508
- }
509
- #compact() {
510
- const policy = this.#policy;
511
- const live = policy.heap.filter((entry) => policy.entries.get(entry.key) === entry);
512
- policy.heap.length = 0;
513
- for (const entry of live)
514
- this.#heapPush(entry);
515
- }
516
- #rearm() {
517
- const p = this.#policy;
518
- const deadline = this.#nextDeadline();
519
- if (p.timer !== undefined && deadline >= p.armedFor)
520
- return;
521
- if (p.timer)
522
- clearTimeout(p.timer);
523
- p.timer = undefined;
524
- p.armedFor = deadline;
525
- if (deadline === Infinity)
526
- return;
527
- p.timer = setTimeout(() => {
528
- p.timer = undefined;
529
- p.armedFor = Infinity;
530
- this.purge();
531
- }, Math.max(0, deadline - Date.now()));
532
- p.timer.unref?.();
533
- }
534
- #heapPush(entry) {
535
- const heap = this.#policy.heap;
536
- let i = heap.length;
537
- heap.push(entry);
538
- while (i > 0) {
539
- const parent = i - 1 >> 1;
540
- const above = heap[parent];
541
- if (above.filed <= entry.filed)
542
- break;
543
- heap[i] = above;
544
- i = parent;
545
- }
546
- heap[i] = entry;
547
- }
548
- #heapPop() {
549
- const heap = this.#policy.heap;
550
- const top = heap[0];
551
- const last = heap.pop();
552
- if (top === undefined || heap.length === 0)
553
- return top;
554
- let i = 0;
555
- for (;; ) {
556
- let child = 2 * i + 1;
557
- if (child >= heap.length)
558
- break;
559
- if (child + 1 < heap.length && heap[child + 1].filed < heap[child].filed)
560
- child++;
561
- if (heap[child].filed >= last.filed)
562
- break;
563
- heap[i] = heap[child];
564
- i = child;
565
- }
566
- heap[i] = last;
567
- return top;
568
- }
569
- first() {
570
- for (const value of this.values())
571
- return value;
572
- return;
573
- }
574
- firstKey() {
575
- for (const key of this.keys())
576
- return key;
577
- return;
578
- }
579
- last() {
580
- let value;
581
- for (const item of this.values())
582
- value = item;
583
- return value;
584
- }
585
- lastKey() {
586
- let key;
587
- for (const item of this.keys())
588
- key = item;
589
- return key;
590
- }
591
- find(predicate) {
592
- for (const [key, value] of this) {
593
- if (predicate(value, key, this))
594
- return value;
595
- }
596
- return;
597
- }
598
- findLast(predicate) {
599
- const keys = this.keyArray();
600
- const values = this.array();
601
- for (let i = values.length - 1;i >= 0; i--)
602
- if (predicate(values[i], keys[i], this))
603
- return values[i];
604
- return;
605
- }
606
- findLastKey(predicate) {
607
- const keys = this.keyArray();
608
- const values = this.array();
609
- for (let i = values.length - 1;i >= 0; i--)
610
- if (predicate(values[i], keys[i], this))
611
- return keys[i];
612
- return;
613
- }
614
- filter(predicate) {
615
- const result = this.#derived();
616
- this.forEach((value, key) => {
617
- if (predicate(value, key, this))
618
- result.set(key, value);
619
- });
620
- return result;
621
- }
622
- map(transform) {
623
- const result = [];
624
- this.forEach((value, key) => {
625
- result.push(transform(value, key, this));
626
- });
627
- return result;
628
- }
629
- some(predicate) {
630
- for (const [key, value] of this) {
631
- if (predicate(value, key, this))
632
- return true;
633
- }
634
- return false;
635
- }
636
- every(predicate) {
637
- for (const [key, value] of this) {
638
- if (!predicate(value, key, this))
639
- return false;
640
- }
641
- return true;
642
- }
643
- each(callback) {
644
- this.forEach((value, key) => {
645
- callback(value, key, this);
646
- });
647
- return this;
648
- }
649
- array() {
650
- return [...this.values()];
651
- }
652
- keyArray() {
653
- return [...this.keys()];
654
- }
655
- entriesArray() {
656
- return [...this.entries()];
657
- }
658
- clone() {
659
- const copy = this.#derived();
660
- this.forEach((value, key) => {
661
- copy.set(key, value);
662
- });
663
- return copy;
664
- }
665
- hasAll(...keys) {
666
- for (let i = 0;i < keys.length; i++) {
667
- if (!this.has(keys[i]))
668
- return false;
669
- }
670
- return true;
671
- }
672
- hasAny(...keys) {
673
- for (let i = 0;i < keys.length; i++) {
674
- if (this.has(keys[i]))
675
- return true;
676
- }
677
- return false;
678
- }
679
- findKey(predicate) {
680
- for (const [key, value] of this) {
681
- if (predicate(value, key, this))
682
- return key;
683
- }
684
- return;
685
- }
686
- someEntry(predicate) {
687
- return this.some(predicate);
688
- }
689
- sweep(predicate) {
690
- let removed = 0;
691
- for (const [key, value] of this) {
692
- if (predicate(value, key, this) && this.delete(key))
693
- removed++;
694
- }
695
- return removed;
696
- }
697
- firstEntry() {
698
- for (const [key, value] of this)
699
- return [key, value];
700
- return;
701
- }
702
- lastEntry() {
703
- let entry;
704
- for (const item of this)
705
- entry = [item[0], item[1]];
706
- return entry;
707
- }
708
- union(other) {
709
- const result = this.clone();
710
- for (const [key, value] of other)
711
- result.set(key, value);
712
- return result;
713
- }
714
- intersection(other) {
715
- const result = this.#derived();
716
- for (const [key, value] of this) {
717
- if (other.has(key))
718
- result.set(key, value);
719
- }
720
- return result;
721
- }
722
- difference(other) {
723
- const result = this.#derived();
724
- for (const [key, value] of this) {
725
- if (!other.has(key))
726
- result.set(key, value);
727
- }
728
- return result;
729
- }
730
- partition(predicate) {
731
- const pass = this.#derived();
732
- const fail = this.#derived();
733
- for (const [key, value] of this) {
734
- if (predicate(value, key, this))
735
- pass.set(key, value);
736
- else
737
- fail.set(key, value);
738
- }
739
- return [pass, fail];
740
- }
741
- symmetricDifference(other) {
742
- const result = this.#derived();
743
- for (const [key, value] of this)
744
- if (!other.has(key))
745
- result.set(key, value);
746
- for (const [key, value] of other)
747
- if (!this.has(key))
748
- result.set(key, value);
749
- return result;
750
- }
751
- concat(...collections) {
752
- const result = this.clone();
753
- for (const collection of collections)
754
- for (const [key, value] of collection)
755
- result.set(key, value);
756
- return result;
757
- }
758
- merge(other, whenInSelf, whenInOther, whenInBoth) {
759
- const result = this.#derived();
760
- const decide = (key, kept) => {
761
- if (kept.keep)
762
- result.set(key, kept.value);
763
- };
764
- for (const [key, value] of this) {
765
- decide(key, other.has(key) ? whenInBoth(value, peekOf(other, key), key) : whenInSelf(value, key));
766
- }
767
- for (const [key, value] of other)
768
- if (!this.has(key))
769
- decide(key, whenInOther(value, key));
770
- return result;
771
- }
772
- equals(other) {
773
- if (!other)
774
- return false;
775
- if (other === this)
776
- return true;
777
- if (this.size !== other.size)
778
- return false;
779
- for (const [key, value] of this) {
780
- if (!other.has(key))
781
- return false;
782
- if (value !== peekOf(other, key))
783
- return false;
784
- }
785
- return true;
786
- }
787
- mapValues(transform) {
788
- const result = this.#derived();
789
- for (const [key, value] of this)
790
- result.set(key, transform(value, key, this));
791
- return result;
792
- }
793
- toReversed() {
794
- const result = this.#derived();
795
- const entries = [...this];
796
- for (let i = entries.length - 1;i >= 0; i--)
797
- result.set(entries[i][0], entries[i][1]);
798
- return result;
799
- }
800
- toSorted(comparator) {
801
- return this.sorted(comparator);
802
- }
803
- static groupBy(items, keySelector) {
804
- const groups = new Collection;
805
- let index = 0;
806
- for (const item of items)
807
- groups.ensure(keySelector(item, index++), () => []).push(item);
808
- return groups;
809
- }
810
- static combineEntries(entries, combine) {
811
- const result = new Collection;
812
- for (const [key, value] of entries)
813
- result.set(key, result.has(key) ? combine(result.get(key), value, key) : value);
814
- return result;
815
- }
816
- tap(fn) {
817
- fn(this);
818
- return this;
819
- }
820
- flatMap(transform) {
821
- const result = [];
822
- for (const [key, value] of this) {
823
- for (const item of transform(value, key, this))
824
- result.push(item);
825
- }
826
- return result;
827
- }
828
- reduce(fn, initialValue) {
829
- let acc = initialValue;
830
- for (const [key, value] of this)
831
- acc = fn(acc, value, key, this);
832
- return acc;
833
- }
834
- reduceRight(fn, initialValue) {
835
- const entries = [...this];
836
- let acc = initialValue;
837
- for (let i = entries.length - 1;i >= 0; i--)
838
- acc = fn(acc, entries[i][1], entries[i][0], this);
839
- return acc;
840
- }
841
- sorted(comparator) {
842
- const decorated = [...this.entries()].map((entry, index) => ({
843
- entry,
844
- index
845
- }));
846
- if (comparator)
847
- decorated.sort((x, y) => {
848
- const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
849
- return comparison !== 0 ? comparison : x.index - y.index;
850
- });
851
- const result = this.#derived();
852
- for (const { entry } of decorated)
853
- result.set(entry[0], entry[1]);
854
- return result;
855
- }
856
- random(amount) {
857
- if (amount !== undefined)
858
- return sample([...this.values()], amount);
859
- const size = this.size;
860
- if (size === 0)
861
- return;
862
- let index = Math.floor(Math.random() * size);
863
- for (const value of this.values())
864
- if (index-- === 0)
865
- return value;
866
- return;
867
- }
868
- randomKey(amount) {
869
- if (amount !== undefined)
870
- return sample([...this.keys()], amount);
871
- const size = this.size;
872
- if (size === 0)
873
- return;
874
- let index = Math.floor(Math.random() * size);
875
- for (const key of this.keys())
876
- if (index-- === 0)
877
- return key;
878
- return;
879
- }
880
- at(index) {
881
- let remaining = index < 0 ? this.size + index : index;
882
- if (remaining < 0)
883
- return;
884
- for (const value of this.values())
885
- if (remaining-- === 0)
886
- return value;
887
- return;
888
- }
889
- keyAt(index) {
890
- let remaining = index < 0 ? this.size + index : index;
891
- if (remaining < 0)
892
- return;
893
- for (const key of this.keys())
894
- if (remaining-- === 0)
895
- return key;
896
- return;
897
- }
898
- toJSON() {
899
- return [...this.entries()];
900
- }
901
- }
902
-
903
- // packages/managers/src/base.ts
904
- function assignFields(into, from) {
905
- const target = into;
906
- const source = from;
907
- for (const key of Object.keys(source))
908
- target[key] = source[key];
909
- return into;
910
- }
911
- function splitReason(options) {
912
- const { reason, ...payload } = options;
913
- return [payload, reason];
914
- }
915
-
916
- class Manager {
917
- cache;
918
- #bounded;
919
- constructor(maxSize) {
920
- this.#bounded = maxSize !== undefined;
921
- this.cache = new Collection(null, { maxSize });
922
- }
923
- get(id) {
924
- return this.cache.get(id);
925
- }
926
- has(id) {
927
- return this.cache.has(id);
928
- }
929
- #inflight = new Map;
930
- fetchOnce(id, load, store = (value) => {
931
- this.set(id, value);
932
- return value;
933
- }) {
934
- const pending = this.#inflight.get(id);
935
- if (pending)
936
- return pending.promise;
937
- const entry = {
938
- promise: new Promise((resolve) => resolve(load())),
939
- dirty: false
940
- };
941
- this.#inflight.set(id, entry);
942
- entry.promise = entry.promise.then((value) => {
943
- this.#inflight.delete(id);
944
- return entry.dirty ? this.get(id) ?? value : store(value);
945
- }, (error) => {
946
- this.#inflight.delete(id);
947
- throw error;
948
- });
949
- return entry.promise;
950
- }
951
- #markDirty(id) {
952
- const pending = this.#inflight.get(id);
953
- if (pending)
954
- pending.dirty = true;
955
- }
956
- set(id, value) {
957
- this.#markDirty(id);
958
- if (this.#bounded)
959
- this.cache.set(id, value);
960
- else
961
- this.cache.setWithoutTTL(id, value);
962
- return this;
963
- }
964
- delete(id) {
965
- this.#markDirty(id);
966
- return this.cache.delete(id);
967
- }
968
- clear() {
969
- this.cache.clear();
970
- }
971
- get size() {
972
- return this.cache.size;
973
- }
974
- first() {
975
- return this.cache.first();
976
- }
977
- values() {
978
- return this.cache.array();
979
- }
980
- find(predicate) {
981
- return this.cache.find(predicate);
982
- }
983
- [Symbol.iterator]() {
984
- return this.cache[Symbol.iterator]();
985
- }
986
- }
987
-
988
- class ResourceManager extends Manager {
989
- #fetcher;
990
- #key;
991
- constructor(fetcher, key, maxSize) {
992
- super(maxSize);
993
- if (typeof fetcher !== "function" || typeof key !== "function")
994
- throw new TypeError("ResourceManager requires fetcher and key functions.");
995
- this.#fetcher = fetcher;
996
- this.#key = key;
997
- }
998
- async resolve(id) {
999
- return this.get(id) ?? this.fetch(id);
1000
- }
1001
- fetch(id) {
1002
- return this.fetchOnce(id, () => this.#fetcher(id), (value) => this.upsert(value));
1003
- }
1004
- async fetchMany(ids) {
1005
- return Promise.all([...ids].map((id) => this.resolve(id)));
1006
- }
1007
- upsert(resource) {
1008
- const key = this.#key(resource);
1009
- const existing = this.get(key);
1010
- if (existing !== undefined && existing !== resource && typeof existing === "object" && existing !== null) {
1011
- assignFields(existing, resource);
1012
- this.set(key, existing);
1013
- return existing;
1014
- }
1015
- this.set(key, resource);
1016
- return resource;
1017
- }
1018
- update(resource) {
1019
- return this.upsert(resource);
1020
- }
1021
- }
1022
- // packages/rest/package.json
1023
- var package_default = {
1024
- name: "@lunibee/rest",
1025
- version: "0.3.3",
1026
- type: "module",
1027
- module: "./src/index.ts",
1028
- types: "./src/index.ts",
1029
- exports: {
1030
- ".": "./src/index.ts"
1031
- },
1032
- dependencies: {
1033
- "@lunibee/types": "workspace:*"
1034
- }
1035
- };
1036
-
1037
- // packages/rest/src/routes.ts
1038
- var Routes = {
1039
- user: () => "/users/@me",
1040
- userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
1041
- guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
1042
- currentUserGuild: (guildId) => `/users/@me/guilds/${snowflake(guildId, "Guild ID")}`,
1043
- sticker: (stickerId) => `/stickers/${snowflake(stickerId, "Sticker ID")}`,
1044
- messageReactionUser: (channelId, messageId, emoji, userId) => `${Routes.messageReactions(channelId, messageId, emoji)}/${snowflake(userId, "User ID")}`,
1045
- guildPreview: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/preview`,
1046
- guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
1047
- guildWebhooks: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/webhooks`,
1048
- guildInvites: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/invites`,
1049
- guildChannels: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/channels`,
1050
- guildMember: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}`,
1051
- guildRoles: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles`,
1052
- guildRole: (guildId, roleId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles/${snowflake(roleId, "Role ID")}`,
1053
- guildMemberRole: (guildId, userId, roleId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}/roles/${snowflake(roleId, "Role ID")}`,
1054
- guildBans: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/bans`,
1055
- guildBan: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/bans/${snowflake(userId, "User ID")}`,
1056
- channel: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}`,
1057
- channelMessages: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages`,
1058
- message: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/${snowflake(messageId, "Message ID")}`,
1059
- crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
1060
- messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
1061
- messageReactionMe: (channelId, messageId, emoji) => `${Routes.messageReactions(channelId, messageId, emoji)}/@me`,
1062
- messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
1063
- channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
1064
- channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
1065
- messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
1066
- channelBulkDelete: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/bulk-delete`,
1067
- channelWebhooks: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/webhooks`,
1068
- channelInvites: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/invites`,
1069
- webhook: (webhookId, token) => `/webhooks/${snowflake(webhookId, "Webhook ID")}${token ? `/${encodeURIComponent(token)}` : ""}`,
1070
- webhookMessage: (webhookId, token, messageId) => `/webhooks/${snowflake(webhookId, "Webhook ID")}/${encodeURIComponent(token)}/messages/${snowflake(messageId, "Message ID")}`,
1071
- applicationCommands: (applicationId) => `/applications/${snowflake(applicationId, "Application ID")}/commands`,
1072
- applicationCommand: (applicationId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/commands/${snowflake(commandId, "Command ID")}`,
1073
- guildApplicationCommands: (applicationId, guildId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands`,
1074
- guildApplicationCommand: (applicationId, guildId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands/${snowflake(commandId, "Command ID")}`,
1075
- interactionCallback: (interactionId, token) => `/interactions/${snowflake(interactionId, "Interaction ID")}/${encodeURIComponent(token)}/callback`,
1076
- interactionOriginalResponse: (applicationId, token) => `/webhooks/${snowflake(applicationId, "Application ID")}/${encodeURIComponent(token)}/messages/@original`,
1077
- channelPublicArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/public`,
1078
- channelPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/private`,
1079
- channelJoinedPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/users/@me/threads/archived/private`,
1080
- threadMember: (threadId, userId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members/${userOrMe(userId)}`,
1081
- channelTyping: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/typing`,
1082
- channelThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads`,
1083
- threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
1084
- guildScheduledEvents: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events`,
1085
- guildScheduledEvent: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}`,
1086
- guildScheduledEventUsers: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}/users`,
1087
- channelPermission: (channelId, overwriteId) => `/channels/${snowflake(channelId, "Channel ID")}/permissions/${snowflake(overwriteId, "Overwrite ID")}`,
1088
- guildAutoModerationRules: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules`,
1089
- guildAutoModerationRule: (guildId, ruleId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules/${snowflake(ruleId, "Rule ID")}`,
1090
- voiceRegions: () => "/voice/regions",
1091
- gateway: () => "/gateway",
1092
- gatewayBot: () => "/gateway/bot",
1093
- guildAuditLog: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/audit-logs`,
1094
- guildMembers: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members`,
1095
- guildMembersSearch: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/search`,
1096
- guildMemberMe: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/@me`,
1097
- guildBulkBan: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/bulk-ban`,
1098
- guildVoiceState: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/voice-states/${userOrMe(userId)}`,
1099
- guildIntegration: (guildId, integrationId) => `/guilds/${snowflake(guildId, "Guild ID")}/integrations/${snowflake(integrationId, "Integration ID")}`,
1100
- userGuilds: () => "/users/@me/guilds",
1101
- stickerPacks: (packId) => packId ? `/sticker-packs/${snowflake(packId, "Sticker pack ID")}` : "/sticker-packs",
1102
- guildWelcomeScreen: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/welcome-screen`,
1103
- guildOnboarding: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/onboarding`,
1104
- guildPrune: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/prune`,
1105
- stageInstances: () => "/stage-instances",
1106
- stageInstanceByChannel: (channelId) => `/stage-instances/${snowflake(channelId, "Channel ID")}`,
1107
- invite: (code) => `/invites/${encodeURIComponent(code)}`,
1108
- guildVanity: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/vanity-url`,
1109
- guildEmoji: (guildId, emojiId) => emojiId ? `/guilds/${snowflake(guildId, "Guild ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/guilds/${snowflake(guildId, "Guild ID")}/emojis`,
1110
- applicationEmoji: (applicationId, emojiId) => emojiId ? `/applications/${snowflake(applicationId, "Application ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/applications/${snowflake(applicationId, "Application ID")}/emojis`,
1111
- pollExpire: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/polls/${snowflake(messageId, "Message ID")}/expire`,
1112
- pollAnswerVoters: (channelId, messageId, answerId) => `/channels/${snowflake(channelId, "Channel ID")}/polls/${snowflake(messageId, "Message ID")}/answers/${integer(answerId, "Answer ID")}`,
1113
- guildSticker: (guildId, stickerId) => stickerId ? `/guilds/${snowflake(guildId, "Guild ID")}/stickers/${snowflake(stickerId, "Sticker ID")}` : `/guilds/${snowflake(guildId, "Guild ID")}/stickers`,
1114
- sendSoundboardSound: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/send-soundboard-sound`,
1115
- soundboardDefaultSounds: () => "/soundboard-default-sounds",
1116
- guildSoundboardSound: (guildId, soundId) => soundId ? `/guilds/${snowflake(guildId, "Guild ID")}/soundboard-sounds/${snowflake(soundId, "Sound ID")}` : `/guilds/${snowflake(guildId, "Guild ID")}/soundboard-sounds`,
1117
- applicationSkus: (applicationId) => `/applications/${snowflake(applicationId, "Application ID")}/skus`,
1118
- applicationEntitlement: (applicationId, entitlementId) => entitlementId ? `/applications/${snowflake(applicationId, "Application ID")}/entitlements/${snowflake(entitlementId, "Entitlement ID")}` : `/applications/${snowflake(applicationId, "Application ID")}/entitlements`,
1119
- consumeEntitlement: (applicationId, entitlementId) => `/applications/${snowflake(applicationId, "Application ID")}/entitlements/${snowflake(entitlementId, "Entitlement ID")}/consume`,
1120
- skuSubscription: (skuId, subscriptionId) => subscriptionId ? `/skus/${snowflake(skuId, "SKU ID")}/subscriptions/${snowflake(subscriptionId, "Subscription ID")}` : `/skus/${snowflake(skuId, "SKU ID")}/subscriptions`
1121
- };
1122
- function userOrMe(value) {
1123
- return value === "@me" ? value : snowflake(value, "User ID");
1124
- }
1125
- function integer(value, field) {
1126
- if (!Number.isInteger(value) || value < 0)
1127
- throw new TypeError(`${field} must be a non-negative integer.`);
1128
- return String(value);
1129
- }
1130
- function snowflake(value, field) {
1131
- if (!/^\d{1,20}$/.test(value))
1132
- throw new TypeError(`${field} must be a valid Discord snowflake.`);
1133
- return value;
1134
- }
1135
- // packages/rest/src/redis.ts
1136
- var LUA_PRELUDE = `
1137
- local function now_ms()
1138
- local t = redis.call('TIME')
1139
- return tonumber(t[1]) * 1000 + math.floor(tonumber(t[2]) / 1000)
1140
- end
1141
- local function load(key)
1142
- local raw = redis.call('GET', key)
1143
- if not raw then return nil end
1144
- local ok, s = pcall(cjson.decode, raw)
1145
- if ok and type(s) == 'table' and type(s.resetAt) == 'number'
1146
- and type(s.remaining) == 'number' then return s end
1147
- return nil
1148
- end
1149
- local function save(key, s, now, linger)
1150
- local ttl = math.max(1, math.ceil(s.resetAt - now)) + linger
1151
- redis.call('SET', key, cjson.encode(s), 'PX', ttl)
1152
- end
1153
- `;
1154
- var RESERVE_SCRIPT = `${LUA_PRELUDE}
1155
- local now = now_ms()
1156
- local glimit, gwindow = tonumber(ARGV[4]) or 0, tonumber(ARGV[5]) or 1000
1157
- if #KEYS > 1 then
1158
- local g = tonumber(redis.call('GET', KEYS[2]) or '0') or 0
1159
- if g > now then return {0, math.ceil(g - now), 'global'} end
1160
- end
1161
- if #KEYS < 3 then glimit = 0 end
1162
- -- A sliding log of send times: at most glimit in any gwindow span.
1163
- if glimit > 0 then
1164
- redis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now - gwindow)
1165
- if redis.call('ZCARD', KEYS[3]) >= glimit then
1166
- local oldest = redis.call('ZRANGE', KEYS[3], 0, 0, 'WITHSCORES')
1167
- return {0, math.max(1, tonumber(oldest[2]) + gwindow - now + 1), 'global'}
1168
- end
1169
- end
1170
- local function count()
1171
- if glimit > 0 then
1172
- local seq = redis.call('ZCARD', KEYS[3])
1173
- redis.call('ZADD', KEYS[3], now, now .. ':' .. seq)
1174
- redis.call('PEXPIRE', KEYS[3], gwindow + 1000)
1175
- end
1176
- end
1177
- local probe, poll, linger = tonumber(ARGV[1]), tonumber(ARGV[2]), tonumber(ARGV[3])
1178
- local s = load(KEYS[1])
1179
- if s and s.resetAt > now then
1180
- if s.remaining > 0 then
1181
- s.remaining = s.remaining - 1
1182
- save(KEYS[1], s, now, linger)
1183
- count()
1184
- return {1, s.resetAt, 1}
1185
- end
1186
- local wait = s.resetAt - now
1187
- if s.provisional then wait = math.min(wait, poll) end
1188
- local reason = 'bucket'
1189
- if s.probe then reason = 'probe' end
1190
- return {0, math.ceil(wait), reason}
1191
- end
1192
- local resetAt = now + probe
1193
- if s and type(s.limit) == 'number' and s.limit > 0 then
1194
- save(KEYS[1], {remaining = s.limit - 1, resetAt = resetAt, limit = s.limit, provisional = true}, now, linger)
1195
- count()
1196
- return {1, resetAt, 1}
1197
- end
1198
- save(KEYS[1], {remaining = 0, resetAt = resetAt, provisional = true, probe = true}, now, 0)
1199
- count()
1200
- return {1, resetAt, 0}
1201
- `;
1202
- var RECONCILE_SCRIPT = `${LUA_PRELUDE}
1203
- local now = now_ms()
1204
- local rem, after, limit = tonumber(ARGV[1]), tonumber(ARGV[2]), tonumber(ARGV[3])
1205
- local win, retry, linger = tonumber(ARGV[4]), tonumber(ARGV[5]), tonumber(ARGV[6])
1206
- local tol = 50
1207
- local incoming = nil
1208
- if after then incoming = math.ceil(now + after) end
1209
- local s = load(KEYS[1])
1210
- local n
1211
- if s and s.resetAt > now and not s.probe then
1212
- n = s
1213
- local stale = win and n.window and win < n.window - tol
1214
- if not stale then
1215
- if rem then n.remaining = math.min(n.remaining, rem) end
1216
- if incoming then
1217
- local newer = win and n.window and win > n.window + tol
1218
- if n.provisional or newer then n.resetAt = incoming
1219
- else n.resetAt = math.max(n.resetAt, incoming) end
1220
- n.provisional = nil
1221
- end
1222
- if win then n.window = math.max(n.window or 0, win) end
1223
- end
1224
- else
1225
- if not rem and not retry then
1226
- if s and s.probe then redis.call('DEL', KEYS[1]) end
1227
- return 0
1228
- end
1229
- n = {remaining = rem or 0, resetAt = incoming or now}
1230
- if s and type(s.limit) == 'number' then n.limit = s.limit end
1231
- if win then n.window = win end
1232
- end
1233
- if limit and limit > 0 then n.limit = limit end
1234
- if retry then
1235
- n.remaining = 0
1236
- n.resetAt = math.max(n.resetAt, math.ceil(now + retry))
1237
- n.provisional = nil
1238
- end
1239
- save(KEYS[1], n, now, linger)
1240
- return 1
1241
- `;
1242
- var EXTEND_GLOBAL_SCRIPT = `${LUA_PRELUDE}
1243
- local now = now_ms()
1244
- local target = math.ceil(now + tonumber(ARGV[1]))
1245
- local cur = tonumber(redis.call('GET', KEYS[1]) or '0') or 0
1246
- if target > cur then
1247
- redis.call('SET', KEYS[1], tostring(target), 'PX', math.max(1, target - now))
1248
- return target - now
1249
- end
1250
- return math.max(0, cur - now)
1251
- `;
1252
- var RELEASE_SCRIPT = `${LUA_PRELUDE}
1253
- local s = load(KEYS[1])
1254
- if not s or s.resetAt ~= tonumber(ARGV[1]) then return 0 end
1255
- if s.probe then
1256
- redis.call('DEL', KEYS[1])
1257
- return 1
1258
- end
1259
- if ARGV[2] == '1' then
1260
- local cap = s.remaining + 1
1261
- if type(s.limit) == 'number' then cap = math.min(cap, s.limit) end
1262
- s.remaining = cap
1263
- redis.call('SET', KEYS[1], cjson.encode(s), 'KEEPTTL')
1264
- return 1
1265
- end
1266
- return 0
1267
- `;
1268
-
1269
- // packages/rest/src/index.ts
1270
- var LIBRARY_VERSION = package_default.version;
1271
- var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
1272
- var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${LIBRARY_VERSION})`;
1273
- var REQUEST_DATA_KEYS = new Set([
1274
- "body",
1275
- "files",
1276
- "query",
1277
- "headers",
1278
- "reason",
1279
- "auth",
1280
- "signal",
1281
- "maxQueueWait"
1282
- ]);
1283
-
1284
- // packages/types/src/channel-kind.ts
1285
- var ChannelKinds = {
1286
- text: [0],
1287
- dm: [1],
1288
- voice: [2],
1289
- "group-dm": [3],
1290
- category: [4],
1291
- announcement: [5],
1292
- thread: [10, 11, 12],
1293
- stage: [13],
1294
- directory: [14],
1295
- forum: [15],
1296
- media: [16]
1297
- };
1298
- var KIND_OF_TYPE = new Map(Object.keys(ChannelKinds).flatMap((kind) => ChannelKinds[kind].map((type) => [type, kind])));
1299
- function channelKindOf(type) {
1300
- return KIND_OF_TYPE.get(type) ?? "unknown";
1301
- }
1302
- // packages/types/src/gateway.ts
1303
- var GatewayIntentBits = {
1304
- Guilds: 1 << 0,
1305
- GuildMembers: 1 << 1,
1306
- GuildModeration: 1 << 2,
1307
- GuildExpressions: 1 << 3,
1308
- GuildIntegrations: 1 << 4,
1309
- GuildWebhooks: 1 << 5,
1310
- GuildInvites: 1 << 6,
1311
- GuildVoiceStates: 1 << 7,
1312
- GuildPresences: 1 << 8,
1313
- GuildMessages: 1 << 9,
1314
- GuildMessageReactions: 1 << 10,
1315
- GuildMessageTyping: 1 << 11,
1316
- DirectMessages: 1 << 12,
1317
- DirectMessageReactions: 1 << 13,
1318
- DirectMessageTyping: 1 << 14,
1319
- MessageContent: 1 << 15,
1320
- GuildScheduledEvents: 1 << 16,
1321
- AutoModerationConfiguration: 1 << 20,
1322
- AutoModerationExecution: 1 << 21,
1323
- GuildMessagePolls: 1 << 24,
1324
- DirectMessagePolls: 1 << 25
1325
- };
1326
- var IntentBits = {
1327
- guild: 1 << 0,
1328
- guilds: 1 << 0,
1329
- guildMembers: 1 << 1,
1330
- guildModeration: 1 << 2,
1331
- guildBans: 1 << 2,
1332
- guildExpressions: 1 << 3,
1333
- guildEmojis: 1 << 3,
1334
- guildEmojisAndStickers: 1 << 3,
1335
- guildIntegrations: 1 << 4,
1336
- guildWebhooks: 1 << 5,
1337
- guildInvites: 1 << 6,
1338
- guildVoiceStates: 1 << 7,
1339
- guildPresences: 1 << 8,
1340
- guildMessages: 1 << 9,
1341
- guildMessage: 1 << 9,
1342
- guildMessageReactions: 1 << 10,
1343
- guildMessageTyping: 1 << 11,
1344
- directMessages: 1 << 12,
1345
- directMessageReactions: 1 << 13,
1346
- directMessageTyping: 1 << 14,
1347
- messageContent: 1 << 15,
1348
- guildScheduledEvents: 1 << 16,
1349
- autoModerationConfiguration: 1 << 20,
1350
- autoModerationExecution: 1 << 21,
1351
- guildMessagePolls: 1 << 24,
1352
- directMessagePolls: 1 << 25
1353
- };
1354
- // packages/structures/src/base.ts
1355
- class BaseStructure {
1356
- id;
1357
- constructor(id) {
1358
- if (!/^\d{1,20}$/.test(id))
1359
- throw new TypeError("A Discord structure requires a valid snowflake ID.");
1360
- this.id = id;
1361
- }
1362
- toString() {
1363
- return this.id;
1364
- }
1365
- get createdTimestamp() {
1366
- return Number((BigInt(this.id) >> 22n) + 1420070400000n);
1367
- }
1368
- get createdAt() {
1369
- return new Date(this.createdTimestamp);
1370
- }
1371
- }
1372
- var CDN_BASE = "https://cdn.discordapp.com";
1373
- function cdnURL(path, hash, options = {}) {
1374
- const isAnimated = hash.startsWith("a_") && !options.forceStatic;
1375
- const ext = options.extension ?? (isAnimated ? "gif" : "png");
1376
- const size = options.size ? `?size=${options.size}` : "";
1377
- return `${CDN_BASE}${path}/${encodeURIComponent(hash)}.${ext}${size}`;
1378
- }
1379
-
1380
- class User extends BaseStructure {
1381
- username;
1382
- globalName;
1383
- avatar;
1384
- bot;
1385
- system;
1386
- flags;
1387
- discriminator;
1388
- constructor(data) {
1389
- super(data.id);
1390
- if (!data.username)
1391
- throw new TypeError("A Discord user requires a username.");
1392
- this.username = data.username;
1393
- this.globalName = data.global_name ?? null;
1394
- this.avatar = data.avatar ?? null;
1395
- this.bot = data.bot ?? false;
1396
- this.system = data.system ?? false;
1397
- this.flags = data.public_flags ?? 0;
1398
- this.discriminator = data.discriminator && data.discriminator !== "0" ? data.discriminator : null;
1399
- }
1400
- get displayName() {
1401
- return this.globalName ?? this.username;
1402
- }
1403
- avatarURL(options = {}) {
1404
- if (!this.avatar)
1405
- return null;
1406
- return cdnURL(`/avatars/${this.id}`, this.avatar, options);
1407
- }
1408
- defaultAvatarURL() {
1409
- const index = this.discriminator ? Number(this.discriminator) % 5 : Number((BigInt(this.id) >> 22n) % 6n);
1410
- return `${CDN_BASE}/embed/avatars/${index}.png`;
1411
- }
1412
- displayAvatarURL(options = {}) {
1413
- return this.avatarURL(options) ?? this.defaultAvatarURL();
1414
- }
1415
- toString() {
1416
- return `<@${this.id}>`;
1417
- }
1418
- }
1419
-
1420
- class Channel extends BaseStructure {
1421
- type;
1422
- name;
1423
- guildId;
1424
- topic;
1425
- parentId;
1426
- nsfw;
1427
- rateLimitPerUser;
1428
- position;
1429
- permissionOverwrites;
1430
- partial;
1431
- #context;
1432
- constructor(data, context, options) {
1433
- super(data.id);
1434
- if (!Number.isInteger(data.type) || data.type < 0)
1435
- throw new RangeError("A Discord channel requires a valid channel type.");
1436
- this.type = data.type;
1437
- this.name = data.name;
1438
- this.guildId = data.guild_id;
1439
- this.topic = data.topic;
1440
- this.parentId = data.parent_id;
1441
- this.nsfw = data.nsfw;
1442
- this.rateLimitPerUser = data.rate_limit_per_user;
1443
- this.position = data.position;
1444
- this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
1445
- this.partial = options?.partial ?? false;
1446
- this.#context = context;
1447
- }
1448
- send(options) {
1449
- if (!this.#context)
1450
- throw new Error("This channel is not attached to a client.");
1451
- return this.#context.sendMessage(this.id, options);
1452
- }
1453
- edit(options) {
1454
- if (!this.#context?.editChannel)
1455
- throw new Error("This channel is not attached to a client.");
1456
- return this.#context.editChannel(this.id, options);
1457
- }
1458
- editName(name) {
1459
- if (!name.trim())
1460
- throw new TypeError("Channel name cannot be empty.");
1461
- return this.edit({ name });
1462
- }
1463
- editTopic(topic) {
1464
- return this.edit({ topic });
1465
- }
1466
- editPermissionOverwrite(targetId, changes, options) {
1467
- if (!this.#context?.editPermissionOverwrite)
1468
- throw new Error("This channel is not attached to a client.");
1469
- return this.#context.editPermissionOverwrite(this.id, targetId, changes, options);
1470
- }
1471
- editParent(parentId) {
1472
- return this.edit({ parent_id: parentId });
1473
- }
1474
- delete(reason) {
1475
- if (!this.#context?.deleteChannel)
1476
- throw new Error("This channel is not attached to a client.");
1477
- return this.#context.deleteChannel(this.id, reason);
1478
- }
1479
- update(options) {
1480
- return this.edit(options);
1481
- }
1482
- get kind() {
1483
- return channelKindOf(this.type);
1484
- }
1485
- is(...kinds) {
1486
- return kinds.includes(this.kind);
1487
- }
1488
- as(...kinds) {
1489
- if (!this.is(...kinds))
1490
- throw new TypeError(`Channel ${this.id} is a ${this.kind} channel, not ${kinds.join(" or ")}.`);
1491
- return this;
1492
- }
1493
- isThread() {
1494
- return this.type === 10 || this.type === 11 || this.type === 12;
1495
- }
1496
- isTextBased() {
1497
- return [0, 1, 2, 3, 5, 10, 11, 12, 13].includes(this.type);
1498
- }
1499
- isVoiceBased() {
1500
- return this.type === 2 || this.type === 13;
1501
- }
1502
- isDMBased() {
1503
- return this.type === 1 || this.type === 3;
1504
- }
1505
- toString() {
1506
- return `<#${this.id}>`;
1507
- }
1508
- }
1509
-
1510
- class Guild extends BaseStructure {
1511
- name;
1512
- icon;
1513
- splash;
1514
- banner;
1515
- description;
1516
- preferredLocale;
1517
- ownerId;
1518
- features;
1519
- verificationLevel;
1520
- premiumTier;
1521
- premiumSubscriptionCount;
1522
- memberCount;
1523
- approximateMemberCount;
1524
- approximatePresenceCount;
1525
- vanityUrlCode;
1526
- nsfwLevel;
1527
- discoverySplash;
1528
- rulesChannelId;
1529
- systemChannelId;
1530
- systemChannelFlags;
1531
- maxMembers;
1532
- mfaLevel;
1533
- explicitContentFilter;
1534
- defaultMessageNotifications;
1535
- afkChannelId;
1536
- afkTimeout;
1537
- widgetEnabled;
1538
- widgetChannelId;
1539
- applicationId;
1540
- publicUpdatesChannelId;
1541
- safetyAlertsChannelId;
1542
- maxPresences;
1543
- maxVideoChannelUsers;
1544
- premiumProgressBarEnabled;
1545
- constructor(data) {
1546
- super(data.id);
1547
- if (!data.name)
1548
- throw new TypeError("A Discord guild requires a name.");
1549
- this.name = data.name;
1550
- this.icon = data.icon ?? null;
1551
- this.splash = data.splash ?? null;
1552
- this.banner = data.banner ?? null;
1553
- this.description = data.description ?? null;
1554
- this.preferredLocale = data.preferred_locale ?? "en-US";
1555
- this.ownerId = data.owner_id;
1556
- this.features = data.features ?? [];
1557
- this.verificationLevel = data.verification_level ?? 0;
1558
- this.premiumTier = data.premium_tier ?? 0;
1559
- this.premiumSubscriptionCount = data.premium_subscription_count ?? 0;
1560
- this.memberCount = data.member_count ?? data.approximate_member_count;
1561
- this.approximateMemberCount = data.approximate_member_count;
1562
- this.approximatePresenceCount = data.approximate_presence_count;
1563
- this.vanityUrlCode = data.vanity_url_code ?? null;
1564
- this.nsfwLevel = data.nsfw_level ?? 0;
1565
- this.discoverySplash = data.discovery_splash ?? null;
1566
- this.rulesChannelId = data.rules_channel_id ?? null;
1567
- this.systemChannelId = data.system_channel_id ?? null;
1568
- this.systemChannelFlags = data.system_channel_flags ?? 0;
1569
- this.maxMembers = data.max_members ?? 0;
1570
- this.mfaLevel = data.mfa_level ?? 0;
1571
- this.explicitContentFilter = data.explicit_content_filter ?? 0;
1572
- this.defaultMessageNotifications = data.default_message_notifications ?? 0;
1573
- this.afkChannelId = data.afk_channel_id ?? null;
1574
- this.afkTimeout = data.afk_timeout;
1575
- this.widgetEnabled = data.widget_enabled ?? false;
1576
- this.widgetChannelId = data.widget_channel_id ?? null;
1577
- this.applicationId = data.application_id ?? null;
1578
- this.publicUpdatesChannelId = data.public_updates_channel_id ?? null;
1579
- this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
1580
- this.maxPresences = data.max_presences ?? null;
1581
- this.maxVideoChannelUsers = data.max_video_channel_users;
1582
- this.premiumProgressBarEnabled = data.premium_progress_bar_enabled ?? false;
1583
- }
1584
- iconURL(options = {}) {
1585
- if (!this.icon)
1586
- return null;
1587
- return cdnURL(`/icons/${this.id}`, this.icon, options);
1588
- }
1589
- splashURL(options = {}) {
1590
- if (!this.splash)
1591
- return null;
1592
- return cdnURL(`/splashes/${this.id}`, this.splash, options);
1593
- }
1594
- bannerURL(options = {}) {
1595
- if (!this.banner)
1596
- return null;
1597
- return cdnURL(`/banners/${this.id}`, this.banner, options);
1598
- }
1599
- discoverySplashURL(options = {}) {
1600
- if (!this.discoverySplash)
1601
- return null;
1602
- return cdnURL(`/discovery-splashes/${this.id}`, this.discoverySplash, options);
1603
- }
1604
- widgetImageURL(style = "shield") {
1605
- return `https://discord.com/api/guilds/${this.id}/widget.png?style=${style}`;
1606
- }
1607
- hasFeature(feature) {
1608
- return this.features.includes(feature);
1609
- }
1610
- get isCommunity() {
1611
- return this.hasFeature("COMMUNITY");
1612
- }
1613
- get isPartnered() {
1614
- return this.hasFeature("PARTNERED");
1615
- }
1616
- get isVerified() {
1617
- return this.hasFeature("VERIFIED");
1618
- }
1619
- get isBoosted() {
1620
- return this.premiumSubscriptionCount > 0;
1621
- }
1622
- get boostLevel() {
1623
- return this.premiumTier;
1624
- }
1625
- get hasVanityUrl() {
1626
- return this.vanityUrlCode !== null;
1627
- }
1628
- get vanityURL() {
1629
- return this.vanityUrlCode ? `https://discord.gg/${this.vanityUrlCode}` : null;
1630
- }
1631
- toString() {
1632
- return this.name;
1633
- }
1634
- }
1635
-
1636
- // packages/structures/src/permissions.ts
1637
- var Permission = {
1638
- createInstantInvite: 1n << 0n,
1639
- kickMembers: 1n << 1n,
1640
- banMembers: 1n << 2n,
1641
- administrator: 1n << 3n,
1642
- manageChannels: 1n << 4n,
1643
- manageGuild: 1n << 5n,
1644
- addReactions: 1n << 6n,
1645
- viewAuditLog: 1n << 7n,
1646
- prioritySpeaker: 1n << 8n,
1647
- stream: 1n << 9n,
1648
- viewChannel: 1n << 10n,
1649
- sendMessages: 1n << 11n,
1650
- sendTTSMessages: 1n << 12n,
1651
- manageMessages: 1n << 13n,
1652
- embedLinks: 1n << 14n,
1653
- attachFiles: 1n << 15n,
1654
- readMessageHistory: 1n << 16n,
1655
- mentionEveryone: 1n << 17n,
1656
- useExternalEmojis: 1n << 18n,
1657
- viewGuildInsights: 1n << 19n,
1658
- connect: 1n << 20n,
1659
- speak: 1n << 21n,
1660
- muteMembers: 1n << 22n,
1661
- deafenMembers: 1n << 23n,
1662
- moveMembers: 1n << 24n,
1663
- useVAD: 1n << 25n,
1664
- changeNickname: 1n << 26n,
1665
- manageNicknames: 1n << 27n,
1666
- manageRoles: 1n << 28n,
1667
- manageWebhooks: 1n << 29n,
1668
- manageGuildExpressions: 1n << 30n,
1669
- useApplicationCommands: 1n << 31n,
1670
- requestToSpeak: 1n << 32n,
1671
- manageEvents: 1n << 33n,
1672
- manageThreads: 1n << 34n,
1673
- createPublicThreads: 1n << 35n,
1674
- createPrivateThreads: 1n << 36n,
1675
- useExternalStickers: 1n << 37n,
1676
- sendMessagesInThreads: 1n << 38n,
1677
- useEmbeddedActivities: 1n << 39n,
1678
- moderateMembers: 1n << 40n,
1679
- viewCreatorMonetizationAnalytics: 1n << 41n,
1680
- useSoundboard: 1n << 42n,
1681
- createGuildExpressions: 1n << 43n,
1682
- createEvents: 1n << 44n,
1683
- useExternalSounds: 1n << 45n,
1684
- sendVoiceMessages: 1n << 46n,
1685
- setVoiceChannelStatus: 1n << 48n,
1686
- sendPolls: 1n << 49n,
1687
- useExternalApps: 1n << 50n,
1688
- pinMessages: 1n << 51n,
1689
- bypassSlowmode: 1n << 52n
1690
- };
1691
- var Permissions = {
1692
- CreateInstantInvite: 1n << 0n,
1693
- KickMembers: 1n << 1n,
1694
- BanMembers: 1n << 2n,
1695
- Administrator: 1n << 3n,
1696
- ManageChannels: 1n << 4n,
1697
- ManageGuild: 1n << 5n,
1698
- AddReactions: 1n << 6n,
1699
- ViewAuditLog: 1n << 7n,
1700
- PrioritySpeaker: 1n << 8n,
1701
- Stream: 1n << 9n,
1702
- ViewChannel: 1n << 10n,
1703
- SendMessages: 1n << 11n,
1704
- SendTTSMessages: 1n << 12n,
1705
- ManageMessages: 1n << 13n,
1706
- EmbedLinks: 1n << 14n,
1707
- AttachFiles: 1n << 15n,
1708
- ReadMessageHistory: 1n << 16n,
1709
- MentionEveryone: 1n << 17n,
1710
- UseExternalEmojis: 1n << 18n,
1711
- ViewGuildInsights: 1n << 19n,
1712
- Connect: 1n << 20n,
1713
- Speak: 1n << 21n,
1714
- MuteMembers: 1n << 22n,
1715
- DeafenMembers: 1n << 23n,
1716
- MoveMembers: 1n << 24n,
1717
- UseVAD: 1n << 25n,
1718
- ChangeNickname: 1n << 26n,
1719
- ManageNicknames: 1n << 27n,
1720
- ManageRoles: 1n << 28n,
1721
- ManageWebhooks: 1n << 29n,
1722
- ManageGuildExpressions: 1n << 30n,
1723
- UseApplicationCommands: 1n << 31n,
1724
- RequestToSpeak: 1n << 32n,
1725
- ManageEvents: 1n << 33n,
1726
- ManageThreads: 1n << 34n,
1727
- CreatePublicThreads: 1n << 35n,
1728
- CreatePrivateThreads: 1n << 36n,
1729
- UseExternalStickers: 1n << 37n,
1730
- SendMessagesInThreads: 1n << 38n,
1731
- UseEmbeddedActivities: 1n << 39n,
1732
- ModerateMembers: 1n << 40n,
1733
- ViewCreatorMonetizationAnalytics: 1n << 41n,
1734
- UseSoundboard: 1n << 42n,
1735
- CreateGuildExpressions: 1n << 43n,
1736
- CreateEvents: 1n << 44n,
1737
- UseExternalSounds: 1n << 45n,
1738
- SendVoiceMessages: 1n << 46n,
1739
- SetVoiceChannelStatus: 1n << 48n,
1740
- SendPolls: 1n << 49n,
1741
- UseExternalApps: 1n << 50n,
1742
- PinMessages: 1n << 51n,
1743
- BypassSlowmode: 1n << 52n
1744
- };
1745
- var PermissionFlagsBits = Permissions;
1746
-
1747
- class PermissionSet {
1748
- bitfield;
1749
- constructor(value = 0n) {
1750
- try {
1751
- if (Array.isArray(value)) {
1752
- let bit = 0n;
1753
- for (const item of value) {
1754
- bit |= this.#resolve(item);
1755
- }
1756
- this.bitfield = bit;
1757
- } else if (value instanceof PermissionSet) {
1758
- this.bitfield = value.bitfield;
1759
- } else {
1760
- const bitfield = this.#resolve(value);
1761
- if (bitfield < 0n)
1762
- throw new RangeError("Permission bitfield cannot be negative.");
1763
- this.bitfield = bitfield;
1764
- }
1765
- } catch (error) {
1766
- if (error instanceof RangeError)
1767
- throw error;
1768
- throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
1769
- }
1770
- }
1771
- get createInstantInvite() {
1772
- return (this.bitfield & Permission.createInstantInvite) === Permission.createInstantInvite;
1773
- }
1774
- get kickMembers() {
1775
- return (this.bitfield & Permission.kickMembers) === Permission.kickMembers;
1776
- }
1777
- get banMembers() {
1778
- return (this.bitfield & Permission.banMembers) === Permission.banMembers;
1779
- }
1780
- get administrator() {
1781
- return (this.bitfield & Permission.administrator) === Permission.administrator;
1782
- }
1783
- get manageChannels() {
1784
- return (this.bitfield & Permission.manageChannels) === Permission.manageChannels;
1785
- }
1786
- get manageGuild() {
1787
- return (this.bitfield & Permission.manageGuild) === Permission.manageGuild;
1788
- }
1789
- get addReactions() {
1790
- return (this.bitfield & Permission.addReactions) === Permission.addReactions;
1791
- }
1792
- get viewAuditLog() {
1793
- return (this.bitfield & Permission.viewAuditLog) === Permission.viewAuditLog;
1794
- }
1795
- get prioritySpeaker() {
1796
- return (this.bitfield & Permission.prioritySpeaker) === Permission.prioritySpeaker;
1797
- }
1798
- get stream() {
1799
- return (this.bitfield & Permission.stream) === Permission.stream;
1800
- }
1801
- get viewChannel() {
1802
- return (this.bitfield & Permission.viewChannel) === Permission.viewChannel;
1803
- }
1804
- get sendMessages() {
1805
- return (this.bitfield & Permission.sendMessages) === Permission.sendMessages;
1806
- }
1807
- get sendTTSMessages() {
1808
- return (this.bitfield & Permission.sendTTSMessages) === Permission.sendTTSMessages;
1809
- }
1810
- get manageMessages() {
1811
- return (this.bitfield & Permission.manageMessages) === Permission.manageMessages;
1812
- }
1813
- get embedLinks() {
1814
- return (this.bitfield & Permission.embedLinks) === Permission.embedLinks;
1815
- }
1816
- get attachFiles() {
1817
- return (this.bitfield & Permission.attachFiles) === Permission.attachFiles;
1818
- }
1819
- get readMessageHistory() {
1820
- return (this.bitfield & Permission.readMessageHistory) === Permission.readMessageHistory;
1821
- }
1822
- get mentionEveryone() {
1823
- return (this.bitfield & Permission.mentionEveryone) === Permission.mentionEveryone;
1824
- }
1825
- get useExternalEmojis() {
1826
- return (this.bitfield & Permission.useExternalEmojis) === Permission.useExternalEmojis;
1827
- }
1828
- get viewGuildInsights() {
1829
- return (this.bitfield & Permission.viewGuildInsights) === Permission.viewGuildInsights;
1830
- }
1831
- get connect() {
1832
- return (this.bitfield & Permission.connect) === Permission.connect;
1833
- }
1834
- get speak() {
1835
- return (this.bitfield & Permission.speak) === Permission.speak;
1836
- }
1837
- get muteMembers() {
1838
- return (this.bitfield & Permission.muteMembers) === Permission.muteMembers;
1839
- }
1840
- get deafenMembers() {
1841
- return (this.bitfield & Permission.deafenMembers) === Permission.deafenMembers;
1842
- }
1843
- get moveMembers() {
1844
- return (this.bitfield & Permission.moveMembers) === Permission.moveMembers;
1845
- }
1846
- get useVAD() {
1847
- return (this.bitfield & Permission.useVAD) === Permission.useVAD;
1848
- }
1849
- get changeNickname() {
1850
- return (this.bitfield & Permission.changeNickname) === Permission.changeNickname;
1851
- }
1852
- get manageNicknames() {
1853
- return (this.bitfield & Permission.manageNicknames) === Permission.manageNicknames;
1854
- }
1855
- get manageRoles() {
1856
- return (this.bitfield & Permission.manageRoles) === Permission.manageRoles;
1857
- }
1858
- get manageWebhooks() {
1859
- return (this.bitfield & Permission.manageWebhooks) === Permission.manageWebhooks;
1860
- }
1861
- get manageGuildExpressions() {
1862
- return (this.bitfield & Permission.manageGuildExpressions) === Permission.manageGuildExpressions;
1863
- }
1864
- get useApplicationCommands() {
1865
- return (this.bitfield & Permission.useApplicationCommands) === Permission.useApplicationCommands;
1866
- }
1867
- get requestToSpeak() {
1868
- return (this.bitfield & Permission.requestToSpeak) === Permission.requestToSpeak;
1869
- }
1870
- get manageEvents() {
1871
- return (this.bitfield & Permission.manageEvents) === Permission.manageEvents;
1872
- }
1873
- get manageThreads() {
1874
- return (this.bitfield & Permission.manageThreads) === Permission.manageThreads;
1875
- }
1876
- get createPublicThreads() {
1877
- return (this.bitfield & Permission.createPublicThreads) === Permission.createPublicThreads;
1878
- }
1879
- get createPrivateThreads() {
1880
- return (this.bitfield & Permission.createPrivateThreads) === Permission.createPrivateThreads;
1881
- }
1882
- get useExternalStickers() {
1883
- return (this.bitfield & Permission.useExternalStickers) === Permission.useExternalStickers;
1884
- }
1885
- get sendMessagesInThreads() {
1886
- return (this.bitfield & Permission.sendMessagesInThreads) === Permission.sendMessagesInThreads;
1887
- }
1888
- get useEmbeddedActivities() {
1889
- return (this.bitfield & Permission.useEmbeddedActivities) === Permission.useEmbeddedActivities;
1890
- }
1891
- get moderateMembers() {
1892
- return (this.bitfield & Permission.moderateMembers) === Permission.moderateMembers;
1893
- }
1894
- get viewCreatorMonetizationAnalytics() {
1895
- return (this.bitfield & Permission.viewCreatorMonetizationAnalytics) === Permission.viewCreatorMonetizationAnalytics;
1896
- }
1897
- get useSoundboard() {
1898
- return (this.bitfield & Permission.useSoundboard) === Permission.useSoundboard;
1899
- }
1900
- get createGuildExpressions() {
1901
- return (this.bitfield & Permission.createGuildExpressions) === Permission.createGuildExpressions;
1902
- }
1903
- get createEvents() {
1904
- return (this.bitfield & Permission.createEvents) === Permission.createEvents;
1905
- }
1906
- get useExternalSounds() {
1907
- return (this.bitfield & Permission.useExternalSounds) === Permission.useExternalSounds;
1908
- }
1909
- get sendVoiceMessages() {
1910
- return (this.bitfield & Permission.sendVoiceMessages) === Permission.sendVoiceMessages;
1911
- }
1912
- get sendPolls() {
1913
- return (this.bitfield & Permission.sendPolls) === Permission.sendPolls;
1914
- }
1915
- get useExternalApps() {
1916
- return (this.bitfield & Permission.useExternalApps) === Permission.useExternalApps;
1917
- }
1918
- get setVoiceChannelStatus() {
1919
- return (this.bitfield & Permission.setVoiceChannelStatus) === Permission.setVoiceChannelStatus;
1920
- }
1921
- get pinMessages() {
1922
- return (this.bitfield & Permission.pinMessages) === Permission.pinMessages;
1923
- }
1924
- get bypassSlowmode() {
1925
- return (this.bitfield & Permission.bypassSlowmode) === Permission.bypassSlowmode;
1926
- }
1927
- has(...permissions) {
1928
- if (permissions.length === 1) {
1929
- const p = permissions[0];
1930
- const bit = typeof p === "bigint" ? p : this.#resolve(p);
1931
- return (this.bitfield & bit) === bit;
1932
- }
1933
- for (let i = 0;i < permissions.length; i++) {
1934
- const p = permissions[i];
1935
- const bit = typeof p === "bigint" ? p : this.#resolve(p);
1936
- if ((this.bitfield & bit) !== bit)
1937
- return false;
1938
- }
1939
- return true;
1940
- }
1941
- any(...permissions) {
1942
- if (permissions.length === 1) {
1943
- const p = permissions[0];
1944
- const bit = typeof p === "bigint" ? p : this.#resolve(p);
1945
- return (this.bitfield & bit) !== 0n;
1946
- }
1947
- for (let i = 0;i < permissions.length; i++) {
1948
- const p = permissions[i];
1949
- const bit = typeof p === "bigint" ? p : this.#resolve(p);
1950
- if ((this.bitfield & bit) !== 0n)
1951
- return true;
1952
- }
1953
- return false;
1954
- }
1955
- missing(...permissions) {
1956
- const wanted = new PermissionSet(permissions);
1957
- return wanted.toArray().filter((name) => !this.has(name));
1958
- }
1959
- add(...permissions) {
1960
- let bitfield = this.bitfield;
1961
- for (let i = 0;i < permissions.length; i++) {
1962
- const p = permissions[i];
1963
- bitfield |= typeof p === "bigint" ? p : this.#resolve(p);
1964
- }
1965
- return new PermissionSet(bitfield);
1966
- }
1967
- remove(...permissions) {
1968
- let bitfield = this.bitfield;
1969
- for (let i = 0;i < permissions.length; i++) {
1970
- const p = permissions[i];
1971
- bitfield &= ~(typeof p === "bigint" ? p : this.#resolve(p));
1972
- }
1973
- return new PermissionSet(bitfield);
1974
- }
1975
- equals(other) {
1976
- return this.bitfield === (other instanceof PermissionSet ? other.bitfield : new PermissionSet(other).bitfield);
1977
- }
1978
- toString() {
1979
- return this.bitfield.toString();
1980
- }
1981
- toArray() {
1982
- return Object.keys(Permission).filter((permission) => this.has(permission));
1983
- }
1984
- static #renamed = {
1985
- ManageEmojisAndStickers: "ManageGuildExpressions",
1986
- ManageEmojis: "ManageGuildExpressions",
1987
- UseSlashCommands: "UseApplicationCommands"
1988
- };
1989
- #resolve(permission) {
1990
- if (typeof permission === "bigint")
1991
- return permission;
1992
- if (typeof permission === "number")
1993
- return BigInt(permission);
1994
- if (permission instanceof PermissionSet)
1995
- return permission.bitfield;
1996
- if (Array.isArray(permission)) {
1997
- let bit = 0n;
1998
- for (let i = 0;i < permission.length; i++)
1999
- bit |= this.#resolve(permission[i]);
2000
- return bit;
2001
- }
2002
- if (typeof permission === "string") {
2003
- const renamed = PermissionSet.#renamed[permission];
2004
- if (renamed)
2005
- return this.#resolve(renamed);
2006
- if (permission in Permission)
2007
- return Permission[permission];
2008
- if (permission in Permissions)
2009
- return Permissions[permission];
2010
- if (permission in PermissionFlagsBits)
2011
- return PermissionFlagsBits[permission];
2012
- const lower = permission.charAt(0).toLowerCase() + permission.slice(1);
2013
- if (lower in Permission)
2014
- return Permission[lower];
2015
- return BigInt(permission);
2016
- }
2017
- return 0n;
2018
- }
2019
- }
2020
-
2021
- class PermissionsBitField extends PermissionSet {
2022
- static Flags = PermissionFlagsBits;
2023
- static All = Permission;
2024
- constructor(value = 0n) {
2025
- super(value);
2026
- }
2027
- }
2028
- var ALL_PERMISSIONS = Object.values(Permission).reduce((bits, bit) => bits | bit, 0n);
2029
-
2030
- // packages/structures/src/resources.ts
2031
- function toDateOrNull(value) {
2032
- if (!value)
2033
- return null;
2034
- const date = new Date(value);
2035
- return Number.isNaN(date.getTime()) ? null : date;
2036
- }
2037
-
2038
- class GuildMember {
2039
- user;
2040
- guildId;
2041
- nickname;
2042
- roleIds;
2043
- pending;
2044
- joinedAt;
2045
- avatarHash;
2046
- premiumSince;
2047
- timedOutUntil;
2048
- flags;
2049
- #suppliedPermissions;
2050
- #context;
2051
- constructor(data, context) {
2052
- this.user = new User(data.user);
2053
- this.#context = context;
2054
- if (!/^\d{1,20}$/.test(data.guild_id))
2055
- throw new TypeError("Member guild_id must be a valid snowflake.");
2056
- this.guildId = data.guild_id;
2057
- this.nickname = data.nick ?? null;
2058
- this.roleIds = [...data.roles ?? []];
2059
- this.pending = data.pending ?? false;
2060
- this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
2061
- if (this.joinedAt?.toString() === "Invalid Date")
2062
- throw new RangeError("Member joined_at must be a valid date.");
2063
- if (data.permissions !== undefined)
2064
- this.#suppliedPermissions = new PermissionsBitField(data.permissions);
2065
- this.avatarHash = data.avatar ?? null;
2066
- this.premiumSince = toDateOrNull(data.premium_since);
2067
- this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
2068
- this.flags = data.flags ?? 0;
2069
- }
2070
- get permissions() {
2071
- if (this.#suppliedPermissions)
2072
- return this.#suppliedPermissions;
2073
- return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, undefined, this.timedOutUntil) ?? 0n);
2074
- }
2075
- permissionsIn(channelId) {
2076
- const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId, this.timedOutUntil);
2077
- return computed ? new PermissionsBitField(computed) : null;
2078
- }
2079
- #action(name) {
2080
- const action = this.#context?.[name];
2081
- if (!action)
2082
- throw new Error("This member is not attached to a client.");
2083
- return action;
2084
- }
2085
- kick(reason) {
2086
- return this.#action("kickMember")(this.guildId, this.user.id, reason);
2087
- }
2088
- ban(options = {}) {
2089
- return this.#action("banMember")(this.guildId, this.user.id, options);
2090
- }
2091
- edit(options, reason) {
2092
- return this.#action("editMember")(this.guildId, this.user.id, options, reason);
2093
- }
2094
- timeout(milliseconds, reason) {
2095
- if (milliseconds !== null && !(milliseconds > 0))
2096
- throw new RangeError("Timeout length must be a positive number of milliseconds.");
2097
- return this.edit({
2098
- communication_disabled_until: milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString()
2099
- }, reason);
2100
- }
2101
- setNickname(nickname, reason) {
2102
- return this.edit({ nick: nickname }, reason);
2103
- }
2104
- addRole(roleId, reason) {
2105
- return this.#action("addMemberRole")(this.guildId, this.user.id, roleId, reason);
2106
- }
2107
- removeRole(roleId, reason) {
2108
- return this.#action("removeMemberRole")(this.guildId, this.user.id, roleId, reason);
2109
- }
2110
- get displayName() {
2111
- return this.nickname ?? this.user.displayName;
2112
- }
2113
- get isTimedOut() {
2114
- return this.timedOutUntil !== null && this.timedOutUntil > new Date;
2115
- }
2116
- avatarURL(options = {}) {
2117
- if (this.avatarHash)
2118
- return cdnURL(`/guilds/${this.guildId}/users/${this.user.id}/avatars`, this.avatarHash, options);
2119
- return this.user.avatarURL(options);
2120
- }
2121
- displayAvatarURL(options = {}) {
2122
- return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
2123
- }
2124
- toString() {
2125
- return this.user.toString();
2126
- }
2127
- }
2128
-
2129
- class Role extends BaseStructure {
2130
- name;
2131
- color;
2132
- hoist;
2133
- permissions;
2134
- managed;
2135
- mentionable;
2136
- position;
2137
- unicodeEmoji;
2138
- iconHash;
2139
- colors;
2140
- tags;
2141
- constructor(data) {
2142
- super(data.id);
2143
- if (!data.name)
2144
- throw new TypeError("Role name cannot be empty.");
2145
- this.name = data.name;
2146
- this.color = data.color ?? 0;
2147
- this.hoist = data.hoist ?? false;
2148
- this.permissions = new PermissionsBitField(data.permissions ?? 0n);
2149
- this.managed = data.managed ?? false;
2150
- this.mentionable = data.mentionable ?? false;
2151
- this.position = data.position ?? 0;
2152
- this.unicodeEmoji = data.unicode_emoji ?? null;
2153
- this.colors = data.colors ? {
2154
- primary: data.colors.primary_color,
2155
- secondary: data.colors.secondary_color,
2156
- tertiary: data.colors.tertiary_color
2157
- } : null;
2158
- this.iconHash = data.icon ?? null;
2159
- this.tags = data.tags ?? null;
2160
- }
2161
- get colorHex() {
2162
- return `#${this.color.toString(16).padStart(6, "0").toUpperCase()}`;
2163
- }
2164
- iconURL(options = {}) {
2165
- if (!this.iconHash)
2166
- return null;
2167
- return cdnURL(`/role-icons/${this.id}`, this.iconHash, options);
2168
- }
2169
- isEveryone(guildId) {
2170
- return this.id === guildId;
2171
- }
2172
- toString() {
2173
- return `<@&${this.id}>`;
2174
- }
2175
- }
2176
-
2177
- class TextChannel extends Channel {
2178
- constructor(data, context) {
2179
- super(data, context);
2180
- }
2181
- toString() {
2182
- return `<#${this.id}>`;
2183
- }
2184
- }
2185
- class Emoji extends BaseStructure {
2186
- name;
2187
- roleIds;
2188
- user;
2189
- requireColons;
2190
- managed;
2191
- animated;
2192
- available;
2193
- constructor(data) {
2194
- super(data.id ?? "0");
2195
- if (data.id === null)
2196
- this.id = "unicode";
2197
- this.name = data.name;
2198
- this.roleIds = data.roles ?? [];
2199
- this.user = data.user ? new User(data.user) : null;
2200
- this.requireColons = data.require_colons ?? false;
2201
- this.managed = data.managed ?? false;
2202
- this.animated = data.animated ?? false;
2203
- this.available = data.available ?? true;
2204
- }
2205
- url(options = {}) {
2206
- if (!this.id || this.id === "unicode")
2207
- return null;
2208
- const ext = options.extension ?? (this.animated ? "gif" : "png");
2209
- const size = options.size ? `?size=${options.size}` : "";
2210
- return `${CDN_BASE}/emojis/${this.id}.${ext}${size}`;
2211
- }
2212
- toString() {
2213
- return this.id !== "unicode" ? `<${this.animated ? "a" : ""}:${this.name}:${this.id}>` : this.name ?? "";
2214
- }
2215
- }
2216
-
2217
- class AutoModerationRule extends BaseStructure {
2218
- guildId;
2219
- name;
2220
- creatorId;
2221
- eventType;
2222
- triggerType;
2223
- triggerMetadata;
2224
- actions;
2225
- enabled;
2226
- exemptRoles;
2227
- exemptChannels;
2228
- constructor(data) {
2229
- super(data.id);
2230
- if (!/^\d{1,20}$/.test(data.guild_id))
2231
- throw new TypeError("AutoModerationRule guild_id must be a valid snowflake.");
2232
- this.guildId = data.guild_id;
2233
- this.name = data.name;
2234
- this.creatorId = data.creator_id;
2235
- this.eventType = data.event_type;
2236
- this.triggerType = data.trigger_type;
2237
- this.triggerMetadata = data.trigger_metadata;
2238
- this.actions = data.actions;
2239
- this.enabled = data.enabled;
2240
- this.exemptRoles = data.exempt_roles;
2241
- this.exemptChannels = data.exempt_channels;
2242
- }
2243
- toJSON() {
2244
- return {
2245
- id: this.id,
2246
- guildId: this.guildId,
2247
- name: this.name,
2248
- creatorId: this.creatorId,
2249
- eventType: this.eventType,
2250
- triggerType: this.triggerType,
2251
- triggerMetadata: this.triggerMetadata,
2252
- actions: this.actions,
2253
- enabled: this.enabled,
2254
- exemptRoles: this.exemptRoles,
2255
- exemptChannels: this.exemptChannels
2256
- };
2257
- }
2258
- }
2259
- // packages/structures/src/channels.ts
2260
- class NewsChannel extends TextChannel {
2261
- }
2262
-
2263
- class DMChannel extends Channel {
2264
- recipients;
2265
- ownerId;
2266
- constructor(data, context) {
2267
- super(data, context);
2268
- this.recipients = (data.recipients ?? []).map((u) => new User(u));
2269
- this.ownerId = data.owner_id ?? null;
2270
- }
2271
- }
2272
-
2273
- class VoiceChannel extends Channel {
2274
- bitrate;
2275
- userLimit;
2276
- rtcRegion;
2277
- videoQualityMode;
2278
- constructor(data, context) {
2279
- super(data, context);
2280
- this.bitrate = data.bitrate ?? 64000;
2281
- this.userLimit = data.user_limit ?? 0;
2282
- this.rtcRegion = data.rtc_region ?? null;
2283
- this.videoQualityMode = data.video_quality_mode ?? 1;
2284
- }
2285
- }
2286
-
2287
- class StageChannel extends VoiceChannel {
2288
- }
2289
-
2290
- class CategoryChannel extends Channel {
2291
- }
2292
-
2293
- class ThreadChannel extends Channel {
2294
- ownerId;
2295
- messageCount;
2296
- memberCount;
2297
- metadata;
2298
- constructor(data, context) {
2299
- super(data, context);
2300
- this.ownerId = data.owner_id ?? null;
2301
- this.messageCount = data.message_count ?? 0;
2302
- this.memberCount = data.member_count ?? 0;
2303
- this.metadata = data.thread_metadata ?? null;
2304
- }
2305
- get archived() {
2306
- return this.metadata?.archived ?? false;
2307
- }
2308
- get locked() {
2309
- return this.metadata?.locked ?? false;
2310
- }
2311
- get autoArchiveDuration() {
2312
- return this.metadata?.auto_archive_duration ?? null;
2313
- }
2314
- }
2315
-
2316
- class ForumChannel extends Channel {
2317
- availableTags;
2318
- defaultReactionEmoji;
2319
- defaultThreadRateLimitPerUser;
2320
- defaultAutoArchiveDuration;
2321
- constructor(data, context) {
2322
- super(data, context);
2323
- this.availableTags = data.available_tags ?? [];
2324
- this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
2325
- this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? 0;
2326
- this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
2327
- }
2328
- }
2329
-
2330
- class MediaChannel extends ForumChannel {
2331
- }
2332
- function createChannel(data, context) {
2333
- switch (data.type) {
2334
- case 0:
2335
- return new TextChannel(data, context);
2336
- case 1:
2337
- case 3:
2338
- return new DMChannel(data, context);
2339
- case 2:
2340
- return new VoiceChannel(data, context);
2341
- case 4:
2342
- return new CategoryChannel(data, context);
2343
- case 5:
2344
- return new NewsChannel(data, context);
2345
- case 10:
2346
- case 11:
2347
- case 12:
2348
- return new ThreadChannel(data, context);
2349
- case 13:
2350
- return new StageChannel(data, context);
2351
- case 15:
2352
- return new ForumChannel(data, context);
2353
- case 16:
2354
- return new MediaChannel(data, context);
2355
- default:
2356
- return new Channel(data, context);
2357
- }
2358
- }
2359
- // packages/structures/src/interactions.ts
2360
- var TOKEN_LIFETIME_MS = 15 * 60000;
2361
- // packages/structures/src/audit-log.ts
2362
- function int(value) {
2363
- return Number(value ?? 0);
2364
- }
2365
- function parseInfo(type, options) {
2366
- if (!options)
2367
- return;
2368
- switch (type) {
2369
- case 13:
2370
- case 14:
2371
- case 15:
2372
- return {
2373
- id: options.id ?? "",
2374
- type: int(options.type),
2375
- roleName: options.role_name
2376
- };
2377
- case 21:
2378
- return {
2379
- deleteMemberDays: int(options.delete_member_days),
2380
- membersRemoved: int(options.members_removed)
2381
- };
2382
- case 26:
2383
- case 72:
2384
- return {
2385
- channelId: options.channel_id ?? "",
2386
- count: int(options.count)
2387
- };
2388
- case 27:
2389
- case 73:
2390
- return { count: int(options.count) };
2391
- case 74:
2392
- case 75:
2393
- return {
2394
- channelId: options.channel_id ?? "",
2395
- messageId: options.message_id ?? ""
2396
- };
2397
- case 83:
2398
- case 84:
2399
- case 85:
2400
- return { channelId: options.channel_id ?? "" };
2401
- case 121:
2402
- return { applicationId: options.app_id ?? "" };
2403
- case 143:
2404
- case 144:
2405
- case 145:
2406
- return {
2407
- ruleName: options.auto_moderation_rule_name ?? "",
2408
- ruleTriggerType: int(options.auto_moderation_rule_trigger_type),
2409
- channelId: options.channel_id
2410
- };
2411
- default:
2412
- return;
2413
- }
2414
- }
2415
-
2416
- class AuditLogEntry extends BaseStructure {
2417
- targetId;
2418
- userId;
2419
- actionType;
2420
- changes;
2421
- options;
2422
- info;
2423
- reason;
2424
- constructor(data) {
2425
- super(data.id);
2426
- this.targetId = data.target_id;
2427
- this.userId = data.user_id;
2428
- this.actionType = data.action_type;
2429
- this.info = parseInfo(data.action_type, data.options);
2430
- this.changes = data.changes ?? [];
2431
- this.options = data.options ?? null;
2432
- this.reason = data.reason ?? null;
2433
- }
2434
- is(type) {
2435
- return this.actionType === type;
2436
- }
2437
- change(key) {
2438
- const found = this.changes.find((change) => change.key === key);
2439
- return found && { old: found.old_value, new: found.new_value };
2440
- }
2441
- }
2442
-
2443
- class AuditLog {
2444
- entries;
2445
- constructor(data) {
2446
- this.entries = new Map;
2447
- for (const entryData of data.audit_log_entries) {
2448
- this.entries.set(entryData.id, new AuditLogEntry(entryData));
2449
- }
2450
- }
2451
- filter(query) {
2452
- const types = query.type === undefined ? undefined : Array.isArray(query.type) ? query.type : [query.type];
2453
- const since = query.since === undefined ? undefined : new Date(query.since).getTime();
2454
- const matches = [];
2455
- for (const entry of this.entries.values()) {
2456
- if (types && !types.includes(entry.actionType))
2457
- continue;
2458
- if (query.targetId !== undefined && entry.targetId !== query.targetId)
2459
- continue;
2460
- if (query.userId !== undefined && entry.userId !== query.userId)
2461
- continue;
2462
- if (since !== undefined && entry.createdAt.getTime() < since)
2463
- continue;
2464
- matches.push(entry);
2465
- }
2466
- return matches;
2467
- }
2468
- find(query) {
2469
- return this.filter(query)[0];
2470
- }
2471
- }
2472
-
2473
- // packages/structures/src/index.ts
2474
- var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
2475
- var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
2476
-
2477
- class Message extends BaseStructure {
2478
- content;
2479
- author;
2480
- channelId;
2481
- channel;
2482
- guildId;
2483
- flags;
2484
- timestamp;
2485
- attachments;
2486
- embeds;
2487
- mentions;
2488
- mentionRoles;
2489
- pinned;
2490
- mentionEveryone;
2491
- type;
2492
- reference;
2493
- components;
2494
- referencedMessage;
2495
- stickers;
2496
- poll;
2497
- messageSnapshots;
2498
- member;
2499
- #context;
2500
- constructor(data, context) {
2501
- super(data.id);
2502
- if (!/^\d{1,20}$/.test(data.channel_id))
2503
- throw new TypeError("Message channel_id must be a valid snowflake.");
2504
- this.content = data.content ?? "";
2505
- this.author = new User(data.author);
2506
- this.channelId = data.channel_id;
2507
- this.guildId = data.guild_id;
2508
- this.flags = data.flags ?? 0;
2509
- this.timestamp = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
2510
- this.attachments = data.attachments ?? [];
2511
- this.embeds = data.embeds ?? [];
2512
- this.components = data.components ?? [];
2513
- this.mentions = (data.mentions ?? []).map((user) => new User(user));
2514
- this.mentionRoles = data.mention_roles ?? [];
2515
- this.pinned = data.pinned ?? false;
2516
- this.mentionEveryone = data.mention_everyone ?? false;
2517
- this.type = data.type ?? 0;
2518
- this.reference = data.message_reference;
2519
- this.stickers = data.sticker_items ?? (data.stickers ?? []).map(({ id, name, format_type }) => ({
2520
- id,
2521
- name,
2522
- format_type
2523
- }));
2524
- this.poll = data.poll ?? null;
2525
- this.messageSnapshots = data.message_snapshots ?? [];
2526
- this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
2527
- this.#context = context;
2528
- this.member = data.member && data.guild_id ? new GuildMember({
2529
- ...data.member,
2530
- user: data.member.user ?? data.author,
2531
- guild_id: data.guild_id
2532
- }, context) : null;
2533
- this.channel = context?.cachedChannel?.(data.channel_id) ?? new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context, { partial: true });
2534
- }
2535
- get embedsSuppressed() {
2536
- return (this.flags & 4) !== 0;
2537
- }
2538
- get createdTimestamp() {
2539
- return this.timestamp.getTime();
2540
- }
2541
- get createdAt() {
2542
- return this.timestamp;
2543
- }
2544
- edit(options) {
2545
- if (!this.#context)
2546
- throw new Error("This message is not attached to a client.");
2547
- return this.#context.editMessage(this.channelId, this.id, options);
2548
- }
2549
- update(options) {
2550
- return this.edit(options);
2551
- }
2552
- delete(reason) {
2553
- if (!this.#context)
2554
- throw new Error("This message is not attached to a client.");
2555
- return this.#context.deleteMessage(this.channelId, this.id, reason);
2556
- }
2557
- reply(options) {
2558
- if (!this.#context)
2559
- throw new Error("This message is not attached to a client.");
2560
- const payload = typeof options === "string" ? { content: options } : { ...options };
2561
- payload.message_reference = {
2562
- message_id: this.id,
2563
- channel_id: this.channelId,
2564
- guild_id: this.guildId
2565
- };
2566
- return this.#context.sendMessage(this.channelId, payload);
2567
- }
2568
- crosspost() {
2569
- if (!this.#context)
2570
- throw new Error("This message is not attached to a client.");
2571
- return this.#context.crosspostMessage(this.channelId, this.id);
2572
- }
2573
- createComponentCollector(options = {}) {
2574
- const collect = this.#context?.collectInteractions;
2575
- if (!collect)
2576
- throw new Error("This message is not attached to a client.");
2577
- const { componentType, filter, ...rest } = options;
2578
- return collect({
2579
- ...rest,
2580
- time: rest.time ?? (rest.idle ? undefined : COMPONENT_COLLECTOR_DEFAULT_TIME),
2581
- filter: async (interaction) => interaction.isMessageComponent() && interaction.messageId === this.id && (componentType === undefined || interaction.componentType === componentType) && (filter ? await filter(interaction) : true)
2582
- });
2583
- }
2584
- awaitComponent(options = {}) {
2585
- return this.createComponentCollector({ ...options, max: 1 }).next();
2586
- }
2587
- react(emoji) {
2588
- if (!this.#context?.addReaction)
2589
- throw new Error("This message is not attached to a client.");
2590
- return this.#context.addReaction(this.channelId, this.id, emoji);
2591
- }
2592
- removeReaction(emoji, userId) {
2593
- if (!this.#context)
2594
- throw new Error("This message is not attached to a client.");
2595
- return userId ? this.#context.removeReaction?.(this.channelId, this.id, emoji, userId) ?? Promise.reject(new Error("Reaction operations are unavailable.")) : this.#context.removeOwnReaction?.(this.channelId, this.id, emoji) ?? Promise.reject(new Error("Reaction operations are unavailable."));
2596
- }
2597
- removeAllReactions() {
2598
- if (!this.#context?.removeAllReactions)
2599
- throw new Error("This message is not attached to a client.");
2600
- return this.#context.removeAllReactions(this.channelId, this.id);
2601
- }
2602
- pin(reason) {
2603
- if (!this.#context?.pinMessage)
2604
- throw new Error("This message is not attached to a client.");
2605
- return this.#context.pinMessage(this.channelId, this.id, reason);
2606
- }
2607
- unpin(reason) {
2608
- if (!this.#context?.unpinMessage)
2609
- throw new Error("This message is not attached to a client.");
2610
- return this.#context.unpinMessage(this.channelId, this.id, reason);
2611
- }
2612
- get isEphemeral() {
2613
- return (this.flags & 64) !== 0;
2614
- }
2615
- get isPinned() {
2616
- return this.pinned;
2617
- }
2618
- get isSystemMessage() {
2619
- return !NON_SYSTEM_MESSAGE_TYPES.has(this.type);
2620
- }
2621
- get isCrosspost() {
2622
- return (this.flags & 2) !== 0;
2623
- }
2624
- get hasAttachments() {
2625
- return this.attachments.length > 0;
2626
- }
2627
- get hasEmbeds() {
2628
- return this.embeds.length > 0;
2629
- }
2630
- get hasComponents() {
2631
- return this.components.length > 0;
2632
- }
2633
- suppressEmbeds() {
2634
- return this.edit({ flags: this.flags | 4 });
2635
- }
2636
- toJSON() {
2637
- return {
2638
- id: this.id,
2639
- content: this.content,
2640
- channelId: this.channelId,
2641
- guildId: this.guildId,
2642
- flags: this.flags,
2643
- pinned: this.pinned,
2644
- mentionEveryone: this.mentionEveryone,
2645
- type: this.type,
2646
- timestamp: this.timestamp.toISOString(),
2647
- author: { id: this.author.id, username: this.author.username },
2648
- attachments: [...this.attachments],
2649
- embeds: [...this.embeds],
2650
- components: [...this.components],
2651
- mentions: this.mentions.map((u) => u.id),
2652
- mentionRoles: [...this.mentionRoles],
2653
- reference: this.reference,
2654
- referencedMessage: this.referencedMessage ? this.referencedMessage.id : this.referencedMessage
2655
- };
2656
- }
2657
- }
2658
-
2659
- // packages/managers/src/message.ts
2660
- function toAttachments(files) {
2661
- return files.map((file) => ("toBuffer" in file) ? { name: file.name, data: file.toBuffer() } : {
2662
- name: file.name,
2663
- data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
2664
- contentType: file.contentType
2665
- });
2666
- }
2667
- function assertAllowedMentions(mentions) {
2668
- const parse = mentions.parse ?? [];
2669
- for (const kind of parse)
2670
- if (!["roles", "users", "everyone"].includes(kind))
2671
- throw new TypeError(`allowed_mentions.parse has unknown value "${String(kind)}".`);
2672
- for (const [kind, list] of [
2673
- ["users", mentions.users],
2674
- ["roles", mentions.roles]
2675
- ]) {
2676
- if (list === undefined)
2677
- continue;
2678
- if (!Array.isArray(list) || list.some((id) => typeof id !== "string"))
2679
- throw new TypeError(`allowed_mentions.${kind} must be an array of ID strings.`);
2680
- if (list.length > 100)
2681
- throw new RangeError(`allowed_mentions.${kind} holds at most 100 IDs.`);
2682
- if (list.length > 0 && parse.includes(kind))
2683
- throw new TypeError(`allowed_mentions cannot list ${kind} by ID and also parse "${kind}".`);
2684
- }
2685
- }
2686
- function toRequest(options, allowedMentions) {
2687
- const { files, ...body } = options;
2688
- if (allowedMentions !== undefined && body.allowed_mentions === undefined)
2689
- body.allowed_mentions = allowedMentions;
2690
- if (body.allowed_mentions)
2691
- assertAllowedMentions(body.allowed_mentions);
2692
- if (!files?.length)
2693
- return body;
2694
- if (body.attachments === undefined && files.some((f) => f.description))
2695
- body.attachments = files.map((file, id) => file.description ? { id, description: file.description } : { id });
2696
- return {
2697
- body,
2698
- files: toAttachments(files)
2699
- };
2700
- }
2701
-
2702
- class MessageManager {
2703
- cache;
2704
- #caching;
2705
- #rest;
2706
- #context;
2707
- #channelId;
2708
- #allowedMentions;
2709
- constructor(rest, context, channelId, cache, allowedMentions) {
2710
- if (!channelId)
2711
- throw new TypeError("Channel ID is required.");
2712
- this.#allowedMentions = allowedMentions;
2713
- this.#rest = rest;
2714
- this.#context = context;
2715
- this.#channelId = channelId;
2716
- this.#caching = cache !== undefined;
2717
- this.cache = new Collection(null, {
2718
- ttl: cache?.ttl,
2719
- maxSize: cache ? cache.maxSize ?? 100 : undefined
2720
- });
2721
- }
2722
- async resolve(messageId) {
2723
- return this.cache.get(messageId) ?? this.fetch(messageId);
2724
- }
2725
- async send(options) {
2726
- const data = await this.#rest.post(Routes.channelMessages(this.#channelId), toRequest(options, this.#allowedMentions));
2727
- return this.upsert(data);
2728
- }
2729
- async fetch(messageId) {
2730
- const data = await this.#rest.get(Routes.message(this.#channelId, messageId));
2731
- return this.upsert(data);
2732
- }
2733
- fetchMany(messageIds) {
2734
- return Promise.all(Array.from(messageIds, (messageId) => this.fetch(messageId)));
2735
- }
2736
- upsert(data) {
2737
- const existing = this.cache.peek(data.id);
2738
- const message = new Message(data, this.#context);
2739
- if (existing) {
2740
- assignFields(existing, message);
2741
- return existing;
2742
- }
2743
- if (this.#caching)
2744
- this.cache.set(message.id, message);
2745
- return message;
2746
- }
2747
- delete(messageId) {
2748
- return this.cache.delete(messageId);
2749
- }
2750
- }
2751
-
2752
- // packages/managers/src/thread.ts
2753
- class ThreadManager {
2754
- #rest;
2755
- #context;
2756
- #channelId;
2757
- #allowedMentions;
2758
- constructor(rest, context, channelId, allowedMentions) {
2759
- if (!channelId)
2760
- throw new TypeError("Channel ID is required.");
2761
- this.#rest = rest;
2762
- this.#context = context;
2763
- this.#channelId = channelId;
2764
- this.#allowedMentions = allowedMentions;
2765
- }
2766
- async createFromMessage(messageId, options) {
2767
- const data = await this.#rest.post(Routes.messageThread(this.#channelId, messageId), {
2768
- name: options.name,
2769
- auto_archive_duration: options.autoArchiveDuration,
2770
- rate_limit_per_user: options.rateLimitPerUser
2771
- });
2772
- return createChannel(data, this.#context);
2773
- }
2774
- async create(options) {
2775
- const data = await this.#rest.post(Routes.channelThreads(this.#channelId), {
2776
- name: options.name,
2777
- type: options.type ?? 12,
2778
- auto_archive_duration: options.autoArchiveDuration,
2779
- rate_limit_per_user: options.rateLimitPerUser,
2780
- invitable: options.invitable
2781
- }, { reason: options.reason });
2782
- return createChannel(data, this.#context);
2783
- }
2784
- async createForumPost(options) {
2785
- const { message, appliedTags, reason, ...thread } = options;
2786
- const request = toRequest(message, this.#allowedMentions);
2787
- const withFiles = "body" in request && "files" in request;
2788
- const content = withFiles ? request.body : request;
2789
- const files = withFiles ? request.files : undefined;
2790
- const data = await this.#rest.post(Routes.channelThreads(this.#channelId), {
2791
- name: thread.name,
2792
- auto_archive_duration: thread.autoArchiveDuration,
2793
- rate_limit_per_user: thread.rateLimitPerUser,
2794
- applied_tags: appliedTags,
2795
- message: content
2796
- }, { files, reason });
2797
- return createChannel(data, this.#context);
2798
- }
2799
- async fetchArchived(scope, options = {}) {
2800
- const route = scope === "public" ? Routes.channelPublicArchivedThreads(this.#channelId) : scope === "private" ? Routes.channelPrivateArchivedThreads(this.#channelId) : Routes.channelJoinedPrivateArchivedThreads(this.#channelId);
2801
- const params = new URLSearchParams;
2802
- if (options.before)
2803
- params.set("before", options.before);
2804
- if (options.limit !== undefined)
2805
- params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
2806
- const query = params.toString();
2807
- const page = await this.#rest.get(`${route}${query ? `?${query}` : ""}`);
2808
- return {
2809
- threads: page.threads.map((thread) => createChannel(thread, this.#context)),
2810
- members: page.members,
2811
- hasMore: page.has_more
2812
- };
2813
- }
2814
- async join(threadId) {
2815
- await this.#rest.put(Routes.threadMember(threadId, "@me"));
2816
- }
2817
- async leave(threadId) {
2818
- await this.#rest.delete(Routes.threadMember(threadId, "@me"));
2819
- }
2820
- async addMember(threadId, userId) {
2821
- await this.#rest.put(Routes.threadMember(threadId, userId));
2822
- }
2823
- async removeMember(threadId, userId) {
2824
- await this.#rest.delete(Routes.threadMember(threadId, userId));
2825
- }
2826
- async fetchMember(threadId, userId, query = {}) {
2827
- const suffix = query.withMember ? "?with_member=true" : "";
2828
- return this.#rest.get(`${Routes.threadMember(threadId, userId)}${suffix}`);
2829
- }
2830
- async fetchMembers(threadId, options = {}) {
2831
- const params = new URLSearchParams;
2832
- if (options.withMember)
2833
- params.set("with_member", "true");
2834
- if (options.after)
2835
- params.set("after", options.after);
2836
- if (options.limit !== undefined)
2837
- params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
2838
- const query = params.toString();
2839
- return this.#rest.get(`${Routes.threadMembers(threadId)}${query ? `?${query}` : ""}`);
2840
- }
2841
- }
2842
-
2843
- // packages/managers/src/user.ts
2844
- class UserManager extends ResourceManager {
2845
- #rest;
2846
- constructor(rest) {
2847
- super(async (id) => new User(await rest.get(Routes.userById(id))), (user) => user.id);
2848
- this.#rest = rest;
2849
- }
2850
- async fetchMe() {
2851
- const data = await this.#rest.get("/users/@me");
2852
- return this.upsert(new User(data));
2853
- }
2854
- async editMe(options) {
2855
- const data = await this.#rest.patch("/users/@me", options);
2856
- return this.upsert(new User(data));
2857
- }
2858
- async fetchGuilds(options = {}) {
2859
- const params = new URLSearchParams;
2860
- if (options.limit !== undefined)
2861
- params.set("limit", String(Math.min(200, Math.max(1, options.limit))));
2862
- if (options.before)
2863
- params.set("before", options.before);
2864
- if (options.after)
2865
- params.set("after", options.after);
2866
- if (options.withCounts)
2867
- params.set("with_counts", "true");
2868
- const query = params.toString();
2869
- return this.#rest.get(`${Routes.userGuilds()}${query ? `?${query}` : ""}`);
2870
- }
2871
- async leaveGuild(guildId) {
2872
- await this.#rest.delete(Routes.currentUserGuild(guildId));
2873
- }
2874
- async createDM(userId) {
2875
- return this.#rest.post("/users/@me/channels", {
2876
- recipient_id: userId
2877
- });
2878
- }
2879
- }
2880
- // packages/managers/src/emoji.ts
2881
- class EmojiManager extends Manager {
2882
- #rest;
2883
- #guildId;
2884
- constructor(rest, guildId) {
2885
- super();
2886
- this.#rest = rest;
2887
- this.#guildId = guildId;
2888
- }
2889
- fetch(emojiId) {
2890
- return this.fetchOnce(emojiId, async () => new Emoji(await this.#rest.get(Routes.guildEmoji(this.#guildId, emojiId))), (emoji) => this.#merge(emojiId, emoji));
2891
- }
2892
- async fetchAll() {
2893
- const data = await this.#rest.get(Routes.guildEmoji(this.#guildId));
2894
- return data.map((item) => this.upsert(item));
2895
- }
2896
- async create(options) {
2897
- const [payload, reason] = splitReason(options);
2898
- return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), payload, { reason }));
2899
- }
2900
- async edit(emojiId, options) {
2901
- const [payload, reason] = splitReason(options);
2902
- return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), payload, { reason }));
2903
- }
2904
- async remove(emojiId, reason) {
2905
- await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId), {
2906
- reason
2907
- });
2908
- this.delete(emojiId);
2909
- }
2910
- upsert(data) {
2911
- const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
2912
- return this.#merge(key, new Emoji(data));
2913
- }
2914
- #merge(key, emoji) {
2915
- const existing = this.get(key);
2916
- if (existing) {
2917
- assignFields(existing, emoji);
2918
- return existing;
2919
- }
2920
- this.set(key, emoji);
2921
- return emoji;
2922
- }
2923
- }
2924
-
2925
- // packages/managers/src/advanced.ts
2926
- function withQuery(path, query) {
2927
- const params = new URLSearchParams;
2928
- for (const [key, value] of Object.entries(query))
2929
- if (value !== undefined)
2930
- params.set(key, String(value));
2931
- const suffix = params.toString();
2932
- return suffix ? `${path}?${suffix}` : path;
2933
- }
2934
-
2935
- class GuildStickerManager extends Manager {
2936
- #rest;
2937
- guildId;
2938
- constructor(rest, guildId) {
2939
- super();
2940
- this.#rest = rest;
2941
- this.guildId = guildId;
2942
- }
2943
- #store(sticker) {
2944
- this.set(sticker.id, sticker);
2945
- return sticker;
2946
- }
2947
- async fetchAll() {
2948
- const stickers = await this.#rest.get(Routes.guildSticker(this.guildId));
2949
- this.clear();
2950
- return stickers.map((sticker) => this.#store(sticker));
2951
- }
2952
- async fetch(stickerId) {
2953
- return this.#store(await this.#rest.get(Routes.guildSticker(this.guildId, stickerId)));
2954
- }
2955
- async create(options) {
2956
- const form = new FormData;
2957
- form.set("name", options.name);
2958
- form.set("description", options.description);
2959
- form.set("tags", options.tags);
2960
- form.set("file", options.file);
2961
- return this.#store(await this.#rest.post(Routes.guildSticker(this.guildId), form, { reason: options.reason }));
2962
- }
2963
- async edit(stickerId, options) {
2964
- const { reason, ...body } = options;
2965
- return this.#store(await this.#rest.patch(Routes.guildSticker(this.guildId, stickerId), body, { reason }));
2966
- }
2967
- async remove(stickerId, reason) {
2968
- await this.#rest.delete(Routes.guildSticker(this.guildId, stickerId), {
2969
- reason
2970
- });
2971
- this.delete(stickerId);
2972
- }
2973
- sync(stickers) {
2974
- this.clear();
2975
- for (const sticker of stickers)
2976
- this.#store(sticker);
2977
- }
2978
- }
2979
-
2980
- class GuildSoundboardManager extends Manager {
2981
- #rest;
2982
- guildId;
2983
- constructor(rest, guildId) {
2984
- super();
2985
- this.#rest = rest;
2986
- this.guildId = guildId;
2987
- }
2988
- #store(sound) {
2989
- this.set(sound.sound_id, sound);
2990
- return sound;
2991
- }
2992
- async fetchAll() {
2993
- const { items } = await this.#rest.get(Routes.guildSoundboardSound(this.guildId));
2994
- this.clear();
2995
- return items.map((sound) => this.#store(sound));
2996
- }
2997
- async fetch(soundId) {
2998
- return this.#store(await this.#rest.get(Routes.guildSoundboardSound(this.guildId, soundId)));
2999
- }
3000
- async create(options) {
3001
- if (options.volume !== undefined && (options.volume < 0 || options.volume > 1))
3002
- throw new RangeError("Soundboard volume must be between 0 and 1.");
3003
- return this.#store(await this.#rest.post(Routes.guildSoundboardSound(this.guildId), {
3004
- name: options.name,
3005
- sound: options.sound,
3006
- volume: options.volume,
3007
- emoji_id: options.emojiId,
3008
- emoji_name: options.emojiName
3009
- }, { reason: options.reason }));
3010
- }
3011
- async edit(soundId, options) {
3012
- return this.#store(await this.#rest.patch(Routes.guildSoundboardSound(this.guildId, soundId), {
3013
- name: options.name,
3014
- volume: options.volume,
3015
- emoji_id: options.emojiId,
3016
- emoji_name: options.emojiName
3017
- }, { reason: options.reason }));
3018
- }
3019
- async remove(soundId, reason) {
3020
- await this.#rest.delete(Routes.guildSoundboardSound(this.guildId, soundId), { reason });
3021
- this.delete(soundId);
3022
- }
3023
- }
3024
-
3025
- class MonetizationManager extends Manager {
3026
- #rest;
3027
- applicationId;
3028
- constructor(rest, applicationId) {
3029
- super();
3030
- this.#rest = rest;
3031
- this.applicationId = applicationId;
3032
- }
3033
- fetchSkus() {
3034
- return this.#rest.get(Routes.applicationSkus(this.applicationId));
3035
- }
3036
- async fetchEntitlements(query = {}) {
3037
- if (query.limit !== undefined && (!Number.isInteger(query.limit) || query.limit < 1 || query.limit > 100))
3038
- throw new RangeError("Entitlement limit must be 1-100.");
3039
- const entitlements = await this.#rest.get(withQuery(Routes.applicationEntitlement(this.applicationId), {
3040
- user_id: query.userId,
3041
- sku_ids: query.skuIds?.join(","),
3042
- guild_id: query.guildId,
3043
- before: query.before,
3044
- after: query.after,
3045
- limit: query.limit,
3046
- exclude_ended: query.excludeEnded,
3047
- exclude_deleted: query.excludeDeleted
3048
- }));
3049
- for (const entitlement of entitlements)
3050
- this.set(entitlement.id, entitlement);
3051
- return entitlements;
3052
- }
3053
- async fetch(entitlementId) {
3054
- const entitlement = await this.#rest.get(Routes.applicationEntitlement(this.applicationId, entitlementId));
3055
- this.set(entitlement.id, entitlement);
3056
- return entitlement;
3057
- }
3058
- async consume(entitlementId) {
3059
- await this.#rest.post(Routes.consumeEntitlement(this.applicationId, entitlementId));
3060
- const cached = this.get(entitlementId);
3061
- if (cached)
3062
- cached.consumed = true;
3063
- }
3064
- async createTestEntitlement(options) {
3065
- const entitlement = await this.#rest.post(Routes.applicationEntitlement(this.applicationId), {
3066
- sku_id: options.skuId,
3067
- owner_id: options.ownerId,
3068
- owner_type: options.ownerType
3069
- });
3070
- this.set(entitlement.id, entitlement);
3071
- return entitlement;
3072
- }
3073
- async deleteTestEntitlement(entitlementId) {
3074
- await this.#rest.delete(Routes.applicationEntitlement(this.applicationId, entitlementId));
3075
- this.delete(entitlementId);
3076
- }
3077
- fetchSubscriptions(skuId, query = {}) {
3078
- return this.#rest.get(withQuery(Routes.skuSubscription(skuId), {
3079
- user_id: query.userId,
3080
- before: query.before,
3081
- after: query.after,
3082
- limit: query.limit
3083
- }));
3084
- }
3085
- fetchSubscription(skuId, subscriptionId) {
3086
- return this.#rest.get(Routes.skuSubscription(skuId, subscriptionId));
3087
- }
3088
- }
3089
-
3090
- class ApplicationEmojiManager extends Manager {
3091
- #rest;
3092
- applicationId;
3093
- constructor(rest, applicationId) {
3094
- super();
3095
- this.#rest = rest;
3096
- this.applicationId = applicationId;
3097
- }
3098
- #store(emoji) {
3099
- if (emoji.id)
3100
- this.set(emoji.id, emoji);
3101
- return emoji;
3102
- }
3103
- async fetchAll() {
3104
- const { items } = await this.#rest.get(Routes.applicationEmoji(this.applicationId));
3105
- this.clear();
3106
- return items.map((emoji) => this.#store(emoji));
3107
- }
3108
- async fetch(emojiId) {
3109
- return this.#store(await this.#rest.get(Routes.applicationEmoji(this.applicationId, emojiId)));
3110
- }
3111
- async create(options) {
3112
- return this.#store(await this.#rest.post(Routes.applicationEmoji(this.applicationId), options));
3113
- }
3114
- async edit(emojiId, options) {
3115
- return this.#store(await this.#rest.patch(Routes.applicationEmoji(this.applicationId, emojiId), options));
3116
- }
3117
- async remove(emojiId) {
3118
- await this.#rest.delete(Routes.applicationEmoji(this.applicationId, emojiId));
3119
- this.delete(emojiId);
3120
- }
3121
- }
3122
-
3123
- // packages/managers/src/member.ts
3124
- class GuildMemberManager extends ResourceManager {
3125
- #rest;
3126
- #context;
3127
- guildId;
3128
- constructor(guildId, rest, context = () => {
3129
- return;
3130
- }, maxSize) {
3131
- super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id, maxSize);
3132
- this.guildId = guildId;
3133
- this.#rest = rest;
3134
- this.#context = context;
3135
- }
3136
- async search(query, limit = 1) {
3137
- if (!query.trim())
3138
- throw new TypeError("A search query is required.");
3139
- const params = new URLSearchParams({
3140
- query,
3141
- limit: String(Math.min(1000, Math.max(1, limit)))
3142
- });
3143
- const found = await this.#rest.get(`${Routes.guildMembersSearch(this.guildId)}?${params}`);
3144
- return found.map((data) => {
3145
- const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
3146
- this.set(member.user.id, member);
3147
- return member;
3148
- });
3149
- }
3150
- async editMe(options) {
3151
- const [payload, reason] = splitReason(options);
3152
- const data = await this.#rest.patch(Routes.guildMemberMe(this.guildId), payload, { reason });
3153
- const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
3154
- this.set(member.user.id, member);
3155
- return member;
3156
- }
3157
- async kick(userId, reason) {
3158
- await this.#rest.delete(Routes.guildMember(this.guildId, userId), {
3159
- reason
3160
- });
3161
- this.delete(userId);
3162
- }
3163
- async ban(userId, options = {}) {
3164
- await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
3165
- this.delete(userId);
3166
- }
3167
- async unban(userId, reason) {
3168
- await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
3169
- reason
3170
- });
3171
- }
3172
- async edit(userId, options) {
3173
- const [payload, optionsReason] = splitReason(options);
3174
- const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), payload, {
3175
- reason: optionsReason
3176
- });
3177
- const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
3178
- this.set(member.user.id, member);
3179
- return member;
3180
- }
3181
- async addRole(userId, roleId, reason) {
3182
- await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId), undefined, { reason });
3183
- }
3184
- async removeRole(userId, roleId, reason) {
3185
- await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId), { reason });
3186
- }
3187
- async timeout(userId, milliseconds, reason) {
3188
- const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
3189
- return this.edit(userId, {
3190
- communication_disabled_until: timeoutDate,
3191
- reason
3192
- });
3193
- }
3194
- }
3195
-
3196
- // packages/managers/src/role.ts
3197
- class RoleManager extends ResourceManager {
3198
- #rest;
3199
- guildId;
3200
- constructor(guildId, rest) {
3201
- super((id) => rest.get(Routes.guildRole(guildId, id)).then((data) => new Role(data)), (role) => role.id);
3202
- this.guildId = guildId;
3203
- this.#rest = rest;
3204
- }
3205
- async fetchAll() {
3206
- const data = await this.#rest.get(Routes.guildRoles(this.guildId));
3207
- return data.map((item) => {
3208
- const role = new Role(item);
3209
- this.set(role.id, role);
3210
- return role;
3211
- });
3212
- }
3213
- async create(options) {
3214
- const { reason, ...payload } = options;
3215
- const data = await this.#rest.post(Routes.guildRoles(this.guildId), rolePayload(payload), { reason });
3216
- return this.#store(data);
3217
- }
3218
- async edit(roleId, options) {
3219
- const { reason, ...payload } = options;
3220
- const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), rolePayload(payload), { reason });
3221
- return this.#store(data);
3222
- }
3223
- #store(data) {
3224
- const role = new Role(data);
3225
- this.set(role.id, role);
3226
- return role;
3227
- }
3228
- async remove(roleId, reason) {
3229
- await this.#rest.delete(Routes.guildRole(this.guildId, roleId), {
3230
- reason
3231
- });
3232
- this.delete(roleId);
3233
- }
3234
- async setPositions(positions, reason) {
3235
- const data = await this.#rest.patch(Routes.guildRoles(this.guildId), positions.map(({ id, position }) => ({ id, position })), { reason });
3236
- return data.map((item) => {
3237
- const role = new Role(item);
3238
- this.set(role.id, role);
3239
- return role;
3240
- });
3241
- }
3242
- }
3243
- function rolePayload(options) {
3244
- const { permissions, colors, unicodeEmoji, ...rest } = options;
3245
- return {
3246
- ...rest,
3247
- permissions: permissions !== undefined ? String(permissions) : undefined,
3248
- colors: colors && {
3249
- primary_color: colors.primary,
3250
- secondary_color: colors.secondary ?? null,
3251
- tertiary_color: colors.tertiary ?? null
3252
- },
3253
- unicode_emoji: unicodeEmoji
3254
- };
3255
- }
3256
-
3257
- // packages/managers/src/guild-resources.ts
3258
- function withQuery2(path, params) {
3259
- const query = new URLSearchParams;
3260
- for (const [key, value] of Object.entries(params))
3261
- if (value !== undefined)
3262
- query.set(key, String(value));
3263
- const suffix = query.toString();
3264
- return suffix ? `${path}?${suffix}` : path;
3265
- }
3266
-
3267
- class GuildBanManager extends Manager {
3268
- #rest;
3269
- guildId;
3270
- constructor(rest, guildId) {
3271
- super();
3272
- this.#rest = rest;
3273
- this.guildId = guildId;
3274
- }
3275
- async fetch(userId) {
3276
- const ban = await this.#rest.get(Routes.guildBan(this.guildId, userId));
3277
- this.set(ban.user.id, ban);
3278
- return ban;
3279
- }
3280
- async fetchAll(options = {}) {
3281
- const limit = options.limit === undefined ? undefined : Math.min(1000, Math.max(1, options.limit));
3282
- const bans = await this.#rest.get(withQuery2(Routes.guildBans(this.guildId), {
3283
- limit,
3284
- before: options.before,
3285
- after: options.after
3286
- }));
3287
- for (const ban of bans)
3288
- this.set(ban.user.id, ban);
3289
- return bans;
3290
- }
3291
- async create(userId, options = {}) {
3292
- await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
3293
- }
3294
- async bulk(userIds, options = {}) {
3295
- if (userIds.length < 1 || userIds.length > 200)
3296
- throw new RangeError("Bulk ban takes 1 to 200 user IDs.");
3297
- const result = await this.#rest.post(Routes.guildBulkBan(this.guildId), {
3298
- user_ids: userIds,
3299
- delete_message_seconds: options.deleteMessageSeconds
3300
- }, { reason: options.reason });
3301
- return {
3302
- banned: result.banned_users ?? [],
3303
- failed: result.failed_users ?? []
3304
- };
3305
- }
3306
- async remove(userId, reason) {
3307
- await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
3308
- reason
3309
- });
3310
- this.delete(userId);
3311
- }
3312
- }
3313
-
3314
- class GuildScheduledEventManager extends Manager {
3315
- #rest;
3316
- guildId;
3317
- constructor(rest, guildId) {
3318
- super();
3319
- this.#rest = rest;
3320
- this.guildId = guildId;
3321
- }
3322
- #store(event) {
3323
- this.set(event.id, event);
3324
- return event;
3325
- }
3326
- async fetch(eventId, options = {}) {
3327
- return this.#store(await this.#rest.get(withQuery2(Routes.guildScheduledEvent(this.guildId, eventId), {
3328
- with_user_count: options.withUserCount
3329
- })));
3330
- }
3331
- async fetchAll(options = {}) {
3332
- const events = await this.#rest.get(withQuery2(Routes.guildScheduledEvents(this.guildId), {
3333
- with_user_count: options.withUserCount
3334
- }));
3335
- return events.map((event) => this.#store(event));
3336
- }
3337
- async create(options) {
3338
- const [payload, optionsReason] = splitReason(options);
3339
- return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason }));
3340
- }
3341
- async edit(eventId, options) {
3342
- const [payload, optionsReason] = splitReason(options);
3343
- return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason }));
3344
- }
3345
- async remove(eventId, reason) {
3346
- await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId), { reason });
3347
- this.delete(eventId);
3348
- }
3349
- async fetchSubscribers(eventId, options = {}) {
3350
- const limit = options.limit === undefined ? undefined : Math.min(100, Math.max(1, options.limit));
3351
- return this.#rest.get(withQuery2(Routes.guildScheduledEventUsers(this.guildId, eventId), {
3352
- limit,
3353
- with_member: options.withMember,
3354
- before: options.before,
3355
- after: options.after
3356
- }));
3357
- }
3358
- }
3359
-
3360
- class StageInstanceManager extends Manager {
3361
- #rest;
3362
- constructor(rest) {
3363
- super();
3364
- this.#rest = rest;
3365
- }
3366
- #store(stage) {
3367
- this.set(stage.channel_id, stage);
3368
- return stage;
3369
- }
3370
- async create(channelId, options) {
3371
- return this.#store(await this.#rest.post(Routes.stageInstances(), {
3372
- channel_id: channelId,
3373
- topic: options.topic,
3374
- privacy_level: options.privacyLevel,
3375
- send_start_notification: options.sendStartNotification,
3376
- guild_scheduled_event_id: options.guildScheduledEventId
3377
- }, { reason: options.reason }));
3378
- }
3379
- async fetch(channelId) {
3380
- return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
3381
- }
3382
- async edit(channelId, options) {
3383
- return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason }));
3384
- }
3385
- async remove(channelId, reason) {
3386
- await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
3387
- reason
3388
- });
3389
- this.delete(channelId);
3390
- }
3391
- }
3392
-
3393
- class PermissionOverwriteManager {
3394
- #rest;
3395
- #current;
3396
- channelId;
3397
- constructor(rest, channelId, current = () => {
3398
- return;
3399
- }) {
3400
- this.#rest = rest;
3401
- this.channelId = channelId;
3402
- this.#current = current;
3403
- }
3404
- async update(overwriteId, changes, options = {}) {
3405
- const overwrites = this.#current() ?? (await this.#rest.get(Routes.channel(this.channelId))).permission_overwrites ?? [];
3406
- const existing = overwrites.find((entry) => entry.id === overwriteId);
3407
- const type = existing?.type ?? options.type;
3408
- if (type !== 0 && type !== 1)
3409
- throw new TypeError("A new permission overwrite needs a type: 0 for a role, 1 for a member.");
3410
- const touched = (changes.allow ?? 0n) | (changes.deny ?? 0n) | (changes.inherit ?? 0n);
3411
- const allow = BigInt(existing?.allow ?? 0) & ~touched | (changes.allow ?? 0n);
3412
- const deny = BigInt(existing?.deny ?? 0) & ~touched | (changes.deny ?? 0n);
3413
- await this.edit(overwriteId, {
3414
- type,
3415
- allow,
3416
- deny,
3417
- reason: options.reason
3418
- });
3419
- }
3420
- async edit(overwriteId, options) {
3421
- await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
3422
- type: options.type,
3423
- allow: BigInt(options.allow ?? 0).toString(),
3424
- deny: BigInt(options.deny ?? 0).toString()
3425
- }, { reason: options.reason });
3426
- }
3427
- async remove(overwriteId, reason) {
3428
- await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
3429
- }
3430
- }
3431
-
3432
- // packages/managers/src/guild.ts
3433
- function withQuery3(path, params) {
3434
- const suffix = params.toString();
3435
- return suffix ? `${path}?${suffix}` : path;
3436
- }
3437
-
3438
- class GuildManager extends ResourceManager {
3439
- #rest;
3440
- #bans = new Map;
3441
- #scheduledEvents = new Map;
3442
- #members = new Map;
3443
- #roles = new Map;
3444
- #emojis = new Map;
3445
- #stickers = new Map;
3446
- #soundboard = new Map;
3447
- #voiceStates = new Map;
3448
- #autoModerationRules = new Map;
3449
- #presences = new Map;
3450
- #invites = new Map;
3451
- #context;
3452
- attachContext(context) {
3453
- this.#context = context;
3454
- }
3455
- #perGuild(map, guildId, create) {
3456
- let manager = map.get(guildId);
3457
- if (!manager)
3458
- map.set(guildId, manager = create());
3459
- return manager;
3460
- }
3461
- #maxMembers;
3462
- constructor(rest, options = {}) {
3463
- super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
3464
- this.#rest = rest;
3465
- this.#maxMembers = options.maxMembers;
3466
- }
3467
- bans(guildId) {
3468
- let manager = this.#bans.get(guildId);
3469
- if (!manager)
3470
- this.#bans.set(guildId, manager = new GuildBanManager(this.#rest, guildId));
3471
- return manager;
3472
- }
3473
- scheduledEvents(guildId) {
3474
- let manager = this.#scheduledEvents.get(guildId);
3475
- if (!manager)
3476
- this.#scheduledEvents.set(guildId, manager = new GuildScheduledEventManager(this.#rest, guildId));
3477
- return manager;
3478
- }
3479
- members(guildId) {
3480
- let manager = this.#members.get(guildId);
3481
- if (!manager)
3482
- this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context, this.#maxMembers));
3483
- return manager;
3484
- }
3485
- roles(guildId) {
3486
- let manager = this.#roles.get(guildId);
3487
- if (!manager)
3488
- this.#roles.set(guildId, manager = new RoleManager(guildId, this.#rest));
3489
- return manager;
3490
- }
3491
- emojis(guildId) {
3492
- let manager = this.#emojis.get(guildId);
3493
- if (!manager)
3494
- this.#emojis.set(guildId, manager = new EmojiManager(this.#rest, guildId));
3495
- return manager;
3496
- }
3497
- stickers(guildId) {
3498
- let manager = this.#stickers.get(guildId);
3499
- if (!manager)
3500
- this.#stickers.set(guildId, manager = new GuildStickerManager(this.#rest, guildId));
3501
- return manager;
3502
- }
3503
- soundboard(guildId) {
3504
- let manager = this.#soundboard.get(guildId);
3505
- if (!manager)
3506
- this.#soundboard.set(guildId, manager = new GuildSoundboardManager(this.#rest, guildId));
3507
- return manager;
3508
- }
3509
- voiceStates(guildId) {
3510
- return this.#perGuild(this.#voiceStates, guildId, () => new Manager);
3511
- }
3512
- presences(guildId) {
3513
- return this.#perGuild(this.#presences, guildId, () => new Manager);
3514
- }
3515
- autoModerationRules(guildId) {
3516
- return this.#perGuild(this.#autoModerationRules, guildId, () => new Manager);
3517
- }
3518
- invites(guildId) {
3519
- return this.#perGuild(this.#invites, guildId, () => new Manager);
3520
- }
3521
- patch(data) {
3522
- const guild = new Guild(data);
3523
- const existing = this.get(guild.id);
3524
- if (!existing)
3525
- return this.upsert(guild);
3526
- const from = guild;
3527
- const into = existing;
3528
- for (const key of Object.keys(from)) {
3529
- const value = from[key];
3530
- if (value !== undefined)
3531
- into[key] = value;
3532
- }
3533
- return existing;
3534
- }
3535
- delete(id) {
3536
- this.#bans.delete(id);
3537
- this.#scheduledEvents.delete(id);
3538
- this.#members.delete(id);
3539
- this.#roles.delete(id);
3540
- this.#emojis.delete(id);
3541
- this.#stickers.delete(id);
3542
- this.#soundboard.delete(id);
3543
- this.#voiceStates.delete(id);
3544
- this.#presences.delete(id);
3545
- this.#autoModerationRules.delete(id);
3546
- this.#invites.delete(id);
3547
- return super.delete(id);
3548
- }
3549
- async create(options) {
3550
- const data = await this.#rest.post("/guilds", options);
3551
- return this.upsert(new Guild(data));
3552
- }
3553
- async edit(id, options) {
3554
- const [payload, reason] = splitReason(options);
3555
- const data = await this.#rest.patch(Routes.guild(id), payload, { reason });
3556
- return this.upsert(new Guild(data));
3557
- }
3558
- async remove(id) {
3559
- await this.#rest.delete(Routes.guild(id));
3560
- }
3561
- async fetchPreview(id) {
3562
- return this.#rest.get(Routes.guildPreview(id));
3563
- }
3564
- async fetchWelcomeScreen(id) {
3565
- return this.#rest.get(Routes.guildWelcomeScreen(id));
3566
- }
3567
- async editWelcomeScreen(id, options) {
3568
- const { reason, welcomeChannels, ...rest } = options;
3569
- return this.#rest.patch(Routes.guildWelcomeScreen(id), { ...rest, welcome_channels: welcomeChannels }, { reason });
3570
- }
3571
- async fetchOnboarding(id) {
3572
- return this.#rest.get(Routes.guildOnboarding(id));
3573
- }
3574
- async editOnboarding(id, options) {
3575
- const { reason, defaultChannelIds, ...rest } = options;
3576
- return this.#rest.put(Routes.guildOnboarding(id), { ...rest, default_channel_ids: defaultChannelIds }, { reason });
3577
- }
3578
- async editVoiceState(id, userId, options) {
3579
- await this.#rest.patch(Routes.guildVoiceState(id, userId), {
3580
- channel_id: options.channelId,
3581
- suppress: options.suppress,
3582
- request_to_speak_timestamp: options.requestToSpeakTimestamp
3583
- });
3584
- }
3585
- async removeIntegration(id, integrationId, reason) {
3586
- await this.#rest.delete(Routes.guildIntegration(id, integrationId), {
3587
- reason
3588
- });
3589
- }
3590
- async fetchActiveThreads(id) {
3591
- return this.#rest.get(Routes.guildActiveThreads(id));
3592
- }
3593
- async fetchWebhooks(id) {
3594
- return this.#rest.get(Routes.guildWebhooks(id));
3595
- }
3596
- async fetchInvites(id) {
3597
- return this.#rest.get(Routes.guildInvites(id));
3598
- }
3599
- async fetchAuditLog(guildId, options = {}) {
3600
- const params = new URLSearchParams;
3601
- if (options.userId)
3602
- params.set("user_id", options.userId);
3603
- if (options.actionType !== undefined)
3604
- params.set("action_type", String(options.actionType));
3605
- if (options.before)
3606
- params.set("before", options.before);
3607
- if (options.after)
3608
- params.set("after", options.after);
3609
- if (options.limit !== undefined)
3610
- params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
3611
- return this.#rest.get(withQuery3(Routes.guildAuditLog(guildId), params));
3612
- }
3613
- async fetchAuditLogEntries(guildId, options = {}) {
3614
- return new AuditLog(await this.fetchAuditLog(guildId, options));
3615
- }
3616
- async fetchMembers(guildId, options = {}) {
3617
- const params = new URLSearchParams;
3618
- if (options.limit !== undefined)
3619
- params.set("limit", String(Math.min(1000, Math.max(1, options.limit))));
3620
- if (options.after)
3621
- params.set("after", options.after);
3622
- return this.#rest.get(withQuery3(Routes.guildMembers(guildId), params));
3623
- }
3624
- async fetchAutoModerationRules(guildId) {
3625
- const rules = await this.#rest.get(Routes.guildAutoModerationRules(guildId));
3626
- return rules.map((r) => new AutoModerationRule(r));
3627
- }
3628
- async fetchAutoModerationRule(guildId, ruleId) {
3629
- const rule = await this.#rest.get(Routes.guildAutoModerationRule(guildId, ruleId));
3630
- return new AutoModerationRule(rule);
3631
- }
3632
- async createAutoModerationRule(guildId, options) {
3633
- const [payload, reason] = splitReason(options);
3634
- const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), payload, { reason });
3635
- return new AutoModerationRule(rule);
3636
- }
3637
- async editAutoModerationRule(guildId, ruleId, options) {
3638
- const [payload, reason] = splitReason(options);
3639
- const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), payload, { reason });
3640
- return new AutoModerationRule(rule);
3641
- }
3642
- async deleteAutoModerationRule(guildId, ruleId, reason) {
3643
- await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { reason });
3644
- }
3645
- }
3646
- var AuditLogEvent = {
3647
- GuildUpdate: 1,
3648
- ChannelCreate: 10,
3649
- ChannelUpdate: 11,
3650
- ChannelDelete: 12,
3651
- ChannelOverwriteCreate: 13,
3652
- ChannelOverwriteUpdate: 14,
3653
- ChannelOverwriteDelete: 15,
3654
- MemberKick: 20,
3655
- MemberPrune: 21,
3656
- MemberBanAdd: 22,
3657
- MemberBanRemove: 23,
3658
- MemberUpdate: 24,
3659
- MemberRoleUpdate: 25,
3660
- MemberMove: 26,
3661
- MemberDisconnect: 27,
3662
- BotAdd: 28,
3663
- RoleCreate: 30,
3664
- RoleUpdate: 31,
3665
- RoleDelete: 32,
3666
- InviteCreate: 40,
3667
- InviteUpdate: 41,
3668
- InviteDelete: 42,
3669
- WebhookCreate: 50,
3670
- WebhookUpdate: 51,
3671
- WebhookDelete: 52,
3672
- EmojiCreate: 60,
3673
- EmojiUpdate: 61,
3674
- EmojiDelete: 62,
3675
- MessageDelete: 72,
3676
- MessageBulkDelete: 73,
3677
- MessagePin: 74,
3678
- MessageUnpin: 75,
3679
- IntegrationCreate: 80,
3680
- IntegrationUpdate: 81,
3681
- IntegrationDelete: 82,
3682
- StageInstanceCreate: 83,
3683
- StageInstanceUpdate: 84,
3684
- StageInstanceDelete: 85,
3685
- StickerCreate: 90,
3686
- StickerUpdate: 91,
3687
- StickerDelete: 92,
3688
- ScheduledEventCreate: 100,
3689
- ScheduledEventUpdate: 101,
3690
- ScheduledEventDelete: 102,
3691
- ThreadCreate: 110,
3692
- ThreadUpdate: 111,
3693
- ThreadDelete: 112,
3694
- AutoModerationRuleCreate: 140,
3695
- AutoModerationRuleUpdate: 141,
3696
- AutoModerationRuleDelete: 142,
3697
- AutoModerationBlockMessage: 143
3698
- };
3699
- // packages/managers/src/application.ts
3700
- function commandPayload(command) {
3701
- return "toJSON" in command && typeof command.toJSON === "function" ? command.toJSON() : command;
3702
- }
3703
-
3704
- class ApplicationCommandManager {
3705
- #rest;
3706
- #applicationId;
3707
- constructor(rest, applicationId) {
3708
- this.#rest = rest;
3709
- this.#applicationId = applicationId;
3710
- }
3711
- fetch() {
3712
- return this.#rest.get(Routes.applicationCommands(this.#applicationId));
3713
- }
3714
- create(data) {
3715
- return this.#rest.post(Routes.applicationCommands(this.#applicationId), commandPayload(data));
3716
- }
3717
- set(commands) {
3718
- return this.#rest.put(Routes.applicationCommands(this.#applicationId), commands.map(commandPayload));
3719
- }
3720
- edit(commandId, data) {
3721
- return this.#rest.patch(Routes.applicationCommand(this.#applicationId, commandId), commandPayload(data));
3722
- }
3723
- async delete(commandId) {
3724
- await this.#rest.delete(Routes.applicationCommand(this.#applicationId, commandId));
3725
- }
3726
- fetchGuild(guildId) {
3727
- return this.#rest.get(Routes.guildApplicationCommands(this.#applicationId, guildId));
3728
- }
3729
- createGuild(guildId, data) {
3730
- return this.#rest.post(Routes.guildApplicationCommands(this.#applicationId, guildId), commandPayload(data));
3731
- }
3732
- setGuild(guildId, commands) {
3733
- return this.#rest.put(Routes.guildApplicationCommands(this.#applicationId, guildId), commands.map(commandPayload));
3734
- }
3735
- editGuild(guildId, commandId, data) {
3736
- return this.#rest.patch(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId), commandPayload(data));
3737
- }
3738
- async deleteGuild(guildId, commandId) {
3739
- await this.#rest.delete(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId));
3740
- }
3741
- }
3742
-
3743
- // packages/managers/src/index.ts
3744
- var BULK_DELETE_MAX_AGE_MS = 14 * 24 * 60 * 60000;
3745
- function snowflakeTime(id) {
3746
- return Number((BigInt(id) >> 22n) + 1420070400000n);
3747
- }
3748
-
3749
- class ChannelManager extends Manager {
3750
- #rest;
3751
- #context;
3752
- #messageManagers = new Map;
3753
- #messageCache;
3754
- #allowedMentions;
3755
- constructor(rest, options = {}) {
3756
- super();
3757
- this.#rest = rest;
3758
- this.#messageCache = options.messageCache;
3759
- this.#allowedMentions = options.allowedMentions;
3760
- this.#context = {
3761
- sendMessage: (channelId, options) => this.send(channelId, options),
3762
- editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
3763
- deleteMessage: (channelId, messageId, reason) => this.deleteMessage(channelId, messageId, reason),
3764
- crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
3765
- editChannel: (channelId, options) => this.edit(channelId, options),
3766
- deleteChannel: (channelId, reason) => this.remove(channelId, reason),
3767
- addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
3768
- removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
3769
- removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
3770
- removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
3771
- pinMessage: (channelId, messageId, reason) => this.pinMessage(channelId, messageId, reason),
3772
- unpinMessage: (channelId, messageId, reason) => this.unpinMessage(channelId, messageId, reason)
3773
- };
3774
- }
3775
- messages(channelId) {
3776
- let manager = this.#messageManagers.get(channelId);
3777
- if (!manager) {
3778
- manager = new MessageManager(this.#rest, this.#context, channelId, this.#messageCache, this.#allowedMentions);
3779
- this.#messageManagers.set(channelId, manager);
3780
- }
3781
- return manager;
3782
- }
3783
- permissionOverwrites(channelId) {
3784
- return new PermissionOverwriteManager(this.#rest, channelId, () => {
3785
- const channel = this.get(channelId);
3786
- return channel && !channel.partial ? channel.permissionOverwrites : undefined;
3787
- });
3788
- }
3789
- threads(channelId) {
3790
- return new ThreadManager(this.#rest, this.#context, channelId, this.#allowedMentions);
3791
- }
3792
- fetch(channelId) {
3793
- return this.fetchOnce(channelId, async () => createChannel(await this.#rest.get(Routes.channel(channelId)), this.#context), (channel) => this.#merge(channel));
3794
- }
3795
- async resolve(channelId) {
3796
- return this.get(channelId) ?? this.fetch(channelId);
3797
- }
3798
- upsert(data) {
3799
- return this.#merge(createChannel(data, this.#context));
3800
- }
3801
- #merge(channel) {
3802
- const existing = this.get(channel.id);
3803
- if (existing && existing.type === channel.type) {
3804
- assignFields(existing, channel);
3805
- return existing;
3806
- }
3807
- this.set(channel.id, channel);
3808
- return channel;
3809
- }
3810
- update(channel) {
3811
- return this.set(channel.id, channel);
3812
- }
3813
- deleteGuildChannels(guildId) {
3814
- const ids = [];
3815
- this.cache.forEach((channel, id) => {
3816
- if (channel.guildId === guildId)
3817
- ids.push(id);
3818
- });
3819
- let removed = 0;
3820
- for (const id of ids)
3821
- if (this.delete(id))
3822
- removed++;
3823
- return removed;
3824
- }
3825
- async endPoll(channelId, messageId) {
3826
- return this.messages(channelId).upsert(await this.#rest.post(Routes.pollExpire(channelId, messageId)));
3827
- }
3828
- async fetchPollVoters(channelId, messageId, answerId, options = {}) {
3829
- if (options.limit !== undefined && (!Number.isInteger(options.limit) || options.limit < 1 || options.limit > 100))
3830
- throw new RangeError("Poll voter limit must be 1-100.");
3831
- const params = new URLSearchParams;
3832
- if (options.after)
3833
- params.set("after", options.after);
3834
- if (options.limit !== undefined)
3835
- params.set("limit", String(options.limit));
3836
- const suffix = params.toString();
3837
- const { users } = await this.#rest.get(`${Routes.pollAnswerVoters(channelId, messageId, answerId)}${suffix ? `?${suffix}` : ""}`);
3838
- return users.map((user) => new User(user));
3839
- }
3840
- async sendSoundboardSound(channelId, options) {
3841
- await this.#rest.post(Routes.sendSoundboardSound(channelId), {
3842
- sound_id: options.soundId,
3843
- source_guild_id: options.sourceGuildId
3844
- });
3845
- }
3846
- cachedMessages(channelId) {
3847
- return this.#messageManagers.get(channelId);
3848
- }
3849
- async create(guildId, options) {
3850
- const [payload, reason] = splitReason(options);
3851
- return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), payload, { reason }));
3852
- }
3853
- async edit(channelId, options) {
3854
- const [payload, reason] = splitReason(options);
3855
- return this.upsert(await this.#rest.patch(Routes.channel(channelId), payload, { reason }));
3856
- }
3857
- async remove(channelId, reason) {
3858
- await this.#rest.delete(Routes.channel(channelId), { reason });
3859
- this.delete(channelId);
3860
- }
3861
- delete(channelId) {
3862
- this.#messageManagers.delete(channelId);
3863
- return super.delete(channelId);
3864
- }
3865
- send(channelId, options) {
3866
- return this.messages(channelId).send(options);
3867
- }
3868
- async fetchMessage(channelId, messageId, options = {}) {
3869
- return this.messages(channelId).fetch(messageId);
3870
- }
3871
- fetchMessages(channelId, query) {
3872
- if (isMessageQuery(query)) {
3873
- const params = new URLSearchParams;
3874
- if (query.before)
3875
- params.set("before", query.before);
3876
- if (query.after)
3877
- params.set("after", query.after);
3878
- if (query.around)
3879
- params.set("around", query.around);
3880
- if (query.limit !== undefined)
3881
- params.set("limit", String(query.limit));
3882
- const suffix = params.toString();
3883
- return this.#rest.get(`${Routes.channelMessages(channelId)}${suffix ? `?${suffix}` : ""}`).then((data) => data.map((item) => this.messages(channelId).upsert(item)));
3884
- }
3885
- return this.messages(channelId).fetchMany(query);
3886
- }
3887
- upsertMessage(data) {
3888
- return this.messages(data.channel_id).upsert(data);
3889
- }
3890
- async editMessage(channelId, messageId, options) {
3891
- return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
3892
- }
3893
- async deleteMessage(channelId, messageId, reason) {
3894
- await this.#rest.delete(Routes.message(channelId, messageId), {
3895
- reason
3896
- });
3897
- this.messages(channelId).delete(messageId);
3898
- }
3899
- deleteCachedMessage(channelId, messageId) {
3900
- return this.messages(channelId).delete(messageId);
3901
- }
3902
- async crosspostMessage(channelId, messageId) {
3903
- return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
3904
- }
3905
- async bulkDeleteMessages(channelId, messageIds, reason) {
3906
- const ids = [...new Set(messageIds)];
3907
- if (ids.length < 1 || ids.length > 100)
3908
- throw new RangeError("bulkDelete requires between 1 and 100 message IDs.");
3909
- if (ids.length === 1)
3910
- return this.deleteMessage(channelId, ids[0], reason);
3911
- const cutoff = Date.now() - BULK_DELETE_MAX_AGE_MS;
3912
- const tooOld = ids.filter((id) => snowflakeTime(id) < cutoff);
3913
- if (tooOld.length)
3914
- throw new RangeError(`bulkDelete cannot delete messages older than 14 days: ${tooOld.join(", ")}`);
3915
- await this.#rest.post(Routes.channelBulkDelete(channelId), { messages: ids }, { reason });
3916
- for (const id of ids)
3917
- this.messages(channelId).delete(id);
3918
- }
3919
- async* iterateMessages(channelId, options = {}) {
3920
- let before = options.before;
3921
- let remaining = options.limit ?? Infinity;
3922
- while (remaining > 0) {
3923
- const page = await this.fetchMessages(channelId, {
3924
- before,
3925
- limit: Math.min(100, remaining)
3926
- });
3927
- for (const message of page)
3928
- yield message;
3929
- remaining -= page.length;
3930
- if (page.length < 100)
3931
- return;
3932
- before = page.at(-1).id;
3933
- }
3934
- }
3935
- async addReaction(channelId, messageId, emoji) {
3936
- await this.#rest.put(Routes.messageReactionMe(channelId, messageId, emoji));
3937
- }
3938
- async fetchReactions(channelId, messageId, emoji, options = {}) {
3939
- const params = new URLSearchParams;
3940
- if (options.limit !== undefined)
3941
- params.set("limit", String(options.limit));
3942
- if (options.after)
3943
- params.set("after", options.after);
3944
- const suffix = params.toString();
3945
- const data = await this.#rest.get(`${Routes.messageReactions(channelId, messageId, emoji)}${suffix ? `?${suffix}` : ""}`);
3946
- return data.map((user) => new User(user));
3947
- }
3948
- async removeOwnReaction(channelId, messageId, emoji) {
3949
- await this.#rest.delete(Routes.messageReactionMe(channelId, messageId, emoji));
3950
- }
3951
- async removeReaction(channelId, messageId, emoji, userId) {
3952
- await this.#rest.delete(Routes.messageReactionUser(channelId, messageId, emoji, userId));
3953
- }
3954
- async removeAllReactions(channelId, messageId) {
3955
- await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
3956
- }
3957
- async fetchPinnedMessages(channelId) {
3958
- const data = await this.#rest.get(Routes.channelMessagesPins(channelId));
3959
- return data.items.map((item) => this.messages(channelId).upsert(item.message));
3960
- }
3961
- async fetchPins(channelId, options = {}) {
3962
- const params = new URLSearchParams;
3963
- if (options.before)
3964
- params.set("before", options.before);
3965
- if (options.limit !== undefined)
3966
- params.set("limit", String(Math.min(50, Math.max(1, options.limit))));
3967
- const query = params.toString();
3968
- const data = await this.#rest.get(`${Routes.channelMessagesPins(channelId)}${query ? `?${query}` : ""}`);
3969
- return {
3970
- messages: data.items.map((item) => this.messages(channelId).upsert(item.message)),
3971
- hasMore: data.has_more
3972
- };
3973
- }
3974
- async triggerTyping(channelId) {
3975
- await this.#rest.post(Routes.channelTyping(channelId));
3976
- }
3977
- async createForumTag(channelId, tag, reason) {
3978
- const tags = await this.#forumTags(channelId);
3979
- return this.#saveForumTags(channelId, [...tags, tag], reason);
3980
- }
3981
- async editForumTag(channelId, tagId, changes, reason) {
3982
- const tags = await this.#forumTags(channelId);
3983
- if (!tags.some((tag) => tag.id === tagId))
3984
- throw new Error(`Channel ${channelId} has no tag ${tagId}.`);
3985
- return this.#saveForumTags(channelId, tags.map((tag) => tag.id === tagId ? { ...tag, ...changes } : tag), reason);
3986
- }
3987
- async removeForumTag(channelId, tagId, reason) {
3988
- const tags = await this.#forumTags(channelId);
3989
- if (!tags.some((tag) => tag.id === tagId))
3990
- throw new Error(`Channel ${channelId} has no tag ${tagId}.`);
3991
- return this.#saveForumTags(channelId, tags.filter((tag) => tag.id !== tagId), reason);
3992
- }
3993
- async#forumTags(channelId) {
3994
- const channel = await this.#rest.get(Routes.channel(channelId));
3995
- return channel.available_tags ?? [];
3996
- }
3997
- async#saveForumTags(channelId, tags, reason) {
3998
- const updated = await this.#rest.patch(Routes.channel(channelId), { available_tags: tags }, { reason });
3999
- return updated.available_tags ?? [];
4000
- }
4001
- async pinMessage(channelId, messageId, reason) {
4002
- await this.#rest.put(Routes.channelMessagesPin(channelId, messageId), undefined, { reason });
4003
- }
4004
- async unpinMessage(channelId, messageId, reason) {
4005
- await this.#rest.delete(Routes.channelMessagesPin(channelId, messageId), { reason });
4006
- }
4007
- async createWebhook(channelId, options) {
4008
- const [payload, reason] = splitReason(options);
4009
- return this.#rest.post(Routes.channelWebhooks(channelId), payload, {
4010
- reason
4011
- });
4012
- }
4013
- createThreadFromMessage(channelId, messageId, options) {
4014
- return this.threads(channelId).createFromMessage(messageId, options);
4015
- }
4016
- async fetchPage(channelId, options = {}) {
4017
- const limit = Math.min(100, Math.max(1, options.limit ?? 50));
4018
- const messages = await this.fetchMessages(channelId, {
4019
- ...options,
4020
- limit
4021
- });
4022
- return {
4023
- messages,
4024
- before: messages[0]?.id,
4025
- after: messages[messages.length - 1]?.id,
4026
- hasMore: messages.length === limit
4027
- };
4028
- }
4029
- clear() {
4030
- this.#messageManagers.clear();
4031
- super.clear();
4032
- }
4033
- }
4034
- function isMessageQuery(value) {
4035
- return typeof value === "object" && value !== null && !(Symbol.iterator in value);
4036
- }
2
+ import"../chunks/index-cnmsajvk.js";
3
+ import"../chunks/index-7fp2hvmg.js";
4
+ import"../chunks/index-gyvps8b9.js";
5
+ import"../chunks/index-57c5n3ms.js";
6
+ import {
7
+ Manager2,
8
+ ResourceManager2,
9
+ toRequest2,
10
+ MessageManager2,
11
+ ThreadManager2,
12
+ UserManager2,
13
+ EmojiManager2,
14
+ GuildStickerManager2,
15
+ GuildSoundboardManager2,
16
+ MonetizationManager2,
17
+ ApplicationEmojiManager2,
18
+ GuildMemberManager2,
19
+ RoleManager2,
20
+ GuildBanManager2,
21
+ GuildScheduledEventManager2,
22
+ StageInstanceManager2,
23
+ PermissionOverwriteManager2,
24
+ GuildManager2,
25
+ AuditLogEvent2,
26
+ ApplicationCommandManager2,
27
+ ChannelManager2
28
+ } from "../chunks/index-jzg4bh99.js";
4037
29
  export {
4038
- ApplicationCommandManager,
4039
- ApplicationEmojiManager,
4040
- AuditLogEvent,
4041
- ResourceManager as CachedManager,
4042
- ChannelManager,
4043
- EmojiManager,
4044
- GuildBanManager,
4045
- GuildManager,
4046
- GuildMemberManager,
4047
- GuildScheduledEventManager,
4048
- GuildSoundboardManager,
4049
- GuildStickerManager,
4050
- Manager,
4051
- MessageManager,
4052
- MonetizationManager,
4053
- PermissionOverwriteManager,
4054
- ResourceManager,
4055
- RoleManager,
4056
- StageInstanceManager,
4057
- ThreadManager,
4058
- UserManager,
4059
- toRequest
4060
- };
4061
-
4062
- //# debugId=2CD7EF31353EB8CE64756E2164756E21
30
+ ApplicationCommandManager2 as ApplicationCommandManager,
31
+ ApplicationEmojiManager2 as ApplicationEmojiManager,
32
+ AuditLogEvent2 as AuditLogEvent,
33
+ ChannelManager2 as ChannelManager,
34
+ EmojiManager2 as EmojiManager,
35
+ GuildBanManager2 as GuildBanManager,
36
+ GuildManager2 as GuildManager,
37
+ GuildMemberManager2 as GuildMemberManager,
38
+ GuildScheduledEventManager2 as GuildScheduledEventManager,
39
+ GuildSoundboardManager2 as GuildSoundboardManager,
40
+ GuildStickerManager2 as GuildStickerManager,
41
+ Manager2 as Manager,
42
+ MessageManager2 as MessageManager,
43
+ MonetizationManager2 as MonetizationManager,
44
+ PermissionOverwriteManager2 as PermissionOverwriteManager,
45
+ ResourceManager2 as ResourceManager,
46
+ RoleManager2 as RoleManager,
47
+ StageInstanceManager2 as StageInstanceManager,
48
+ ThreadManager2 as ThreadManager,
49
+ UserManager2 as UserManager,
50
+ toRequest2 as toRequest
51
+ };
52
+
53
+ //# debugId=2EE04BE069BF6B6A64756E2164756E21