lunibee 0.2.3 → 0.3.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.
- package/README.md +3 -3
- package/dist/builders/attachment.d.ts +8 -4
- package/dist/builders/commands.d.ts +122 -149
- package/dist/builders/components.d.ts +10 -150
- package/dist/builders/embed.d.ts +66 -37
- package/dist/builders/index.d.ts +0 -4
- package/dist/builders/index.js +112 -221
- package/dist/builders/index.js.map +10 -9
- package/dist/collection/cache.d.ts +15 -6
- package/dist/collection/index.d.ts +92 -17
- package/dist/collection/index.js +471 -279
- package/dist/collection/index.js.map +4 -4
- package/dist/core/api.d.ts +130 -0
- package/dist/core/channel-create.d.ts +72 -0
- package/dist/core/commands.d.ts +232 -0
- package/dist/core/events.d.ts +24 -7
- package/dist/core/handles.d.ts +157 -0
- package/dist/core/index.d.ts +68 -4
- package/dist/core/index.js +2639 -493
- package/dist/core/index.js.map +47 -37
- package/dist/core/permissions.d.ts +7 -7
- package/dist/formatters/index.js +9 -5
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js +5 -10
- package/dist/handlers/index.js.map +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9527 -7809
- package/dist/index.js.map +63 -53
- package/dist/managers/advanced.d.ts +29 -1
- package/dist/managers/base.d.ts +22 -14
- package/dist/managers/emoji.d.ts +0 -2
- package/dist/managers/guild-resources.d.ts +13 -5
- package/dist/managers/guild.d.ts +40 -4
- package/dist/managers/index.d.ts +21 -13
- package/dist/managers/index.js +969 -386
- package/dist/managers/index.js.map +30 -25
- package/dist/managers/member.d.ts +9 -2
- package/dist/managers/message.d.ts +10 -15
- package/dist/managers/role.d.ts +18 -10
- package/dist/managers/thread.d.ts +68 -0
- package/dist/managers/user.d.ts +18 -0
- package/dist/rest/errors.d.ts +14 -7
- package/dist/rest/index.d.ts +24 -12
- package/dist/rest/index.js +70 -20
- package/dist/rest/index.js.map +9 -9
- package/dist/rest/redis.d.ts +1 -1
- package/dist/rest/route.d.ts +8 -4
- package/dist/rest/routes.d.ts +122 -48
- package/dist/rest/transport.d.ts +10 -5
- package/dist/rest/webhook.d.ts +9 -5
- package/dist/sharding/bus.d.ts +47 -19
- package/dist/sharding/cluster.d.ts +11 -0
- package/dist/sharding/gateway-bot.d.ts +18 -0
- package/dist/sharding/index.d.ts +64 -25
- package/dist/sharding/index.js +439 -124
- package/dist/sharding/index.js.map +19 -14
- package/dist/sharding/supervisor.d.ts +32 -0
- package/dist/sharding/transport.d.ts +45 -0
- package/dist/structures/audit-log.d.ts +99 -2
- package/dist/structures/base.d.ts +40 -23
- package/dist/structures/channels.d.ts +45 -14
- package/dist/structures/index.d.ts +8 -12
- package/dist/structures/index.js +280 -132
- package/dist/structures/index.js.map +21 -15
- package/dist/structures/interactions.d.ts +91 -63
- package/dist/structures/resources.d.ts +99 -52
- package/dist/structures/sticker.d.ts +33 -0
- package/dist/types/channel-kind.d.ts +26 -0
- package/dist/types/gateway.d.ts +24 -12
- package/dist/types/index.d.ts +115 -113
- package/dist/types/index.js +53 -48
- package/dist/types/index.js.map +6 -5
- package/dist/voice/index.d.ts +12 -4
- package/dist/voice/index.js +14 -18
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/decoder.d.ts +6 -2
- package/dist/ws/dispatcher.d.ts +19 -0
- package/dist/ws/index.d.ts +61 -15
- package/dist/ws/index.js +194 -77
- package/dist/ws/index.js.map +13 -11
- package/dist/ws/protocol.d.ts +10 -2
- package/dist/ws/reconnect.d.ts +10 -0
- package/dist/ws/send-budget.d.ts +6 -2
- package/dist/ws/session.d.ts +14 -4
- package/dist/ws/state.d.ts +22 -11
- package/package.json +20 -16
package/dist/managers/index.js
CHANGED
|
@@ -1,66 +1,37 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/collection/src/index.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.#nodes.delete(key);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
clear() {
|
|
39
|
-
this.#nodes.clear();
|
|
40
|
-
this.#oldest = this.#newest = undefined;
|
|
41
|
-
}
|
|
42
|
-
#unlink(node) {
|
|
43
|
-
if (node.older)
|
|
44
|
-
node.older.newer = node.newer;
|
|
45
|
-
else
|
|
46
|
-
this.#oldest = node.newer;
|
|
47
|
-
if (node.newer)
|
|
48
|
-
node.newer.older = node.older;
|
|
49
|
-
else
|
|
50
|
-
this.#newest = node.older;
|
|
51
|
-
node.older = node.newer = undefined;
|
|
52
|
-
}
|
|
53
|
-
#moveNewest(node) {
|
|
54
|
-
if (node === this.#newest)
|
|
55
|
-
return;
|
|
56
|
-
this.#unlink(node);
|
|
57
|
-
node.older = this.#newest;
|
|
58
|
-
if (this.#newest)
|
|
59
|
-
this.#newest.newer = node;
|
|
60
|
-
else
|
|
61
|
-
this.#oldest = node;
|
|
62
|
-
this.#newest = node;
|
|
63
|
-
}
|
|
3
|
+
function newPolicy(options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
ttl: options.ttl,
|
|
6
|
+
jitter: options.jitter ?? 0,
|
|
7
|
+
maxSize: options.maxSize,
|
|
8
|
+
slide: options.slide ?? true,
|
|
9
|
+
onEvict: options.onEvict,
|
|
10
|
+
expired: 0,
|
|
11
|
+
evicted: 0,
|
|
12
|
+
entries: new Map,
|
|
13
|
+
oldest: undefined,
|
|
14
|
+
newest: undefined,
|
|
15
|
+
lruSize: 0,
|
|
16
|
+
heap: [],
|
|
17
|
+
armedFor: Infinity
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function peekOf(collection, key) {
|
|
21
|
+
return collection instanceof Map ? Map.prototype.get.call(collection, key) : collection.get(key);
|
|
22
|
+
}
|
|
23
|
+
var mapGet = Map.prototype.get;
|
|
24
|
+
var mapHas = Map.prototype.has;
|
|
25
|
+
function sample(items, amount) {
|
|
26
|
+
if (!Number.isInteger(amount) || amount < 0)
|
|
27
|
+
throw new RangeError("amount must be a non-negative integer.");
|
|
28
|
+
const count = Math.min(amount, items.length);
|
|
29
|
+
for (let i = 0;i < count; i++) {
|
|
30
|
+
const j = i + Math.floor(Math.random() * (items.length - i));
|
|
31
|
+
[items[i], items[j]] = [items[j], items[i]];
|
|
32
|
+
}
|
|
33
|
+
items.length = count;
|
|
34
|
+
return items;
|
|
64
35
|
}
|
|
65
36
|
function assertTTL(ttl) {
|
|
66
37
|
if (ttl !== undefined && (!Number.isFinite(ttl) || ttl <= 0))
|
|
@@ -68,81 +39,95 @@ function assertTTL(ttl) {
|
|
|
68
39
|
}
|
|
69
40
|
|
|
70
41
|
class Collection extends Map {
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#expiry = new Map;
|
|
75
|
-
#lru = new RecencyList;
|
|
76
|
-
#stats = {
|
|
77
|
-
hits: 0,
|
|
78
|
-
misses: 0,
|
|
79
|
-
expired: 0,
|
|
80
|
-
evicted: 0
|
|
81
|
-
};
|
|
82
|
-
#heap = [];
|
|
83
|
-
#timer;
|
|
84
|
-
#armedFor = Infinity;
|
|
42
|
+
#policy;
|
|
43
|
+
#hits = 0;
|
|
44
|
+
#misses = 0;
|
|
85
45
|
constructor(entries, options = {}) {
|
|
86
46
|
super();
|
|
87
47
|
assertTTL(options.ttl);
|
|
48
|
+
if (options.jitter !== undefined && !(options.jitter >= 0 && options.jitter <= 1))
|
|
49
|
+
throw new RangeError("jitter must be between 0 and 1.");
|
|
88
50
|
if (options.maxSize !== undefined && (!Number.isInteger(options.maxSize) || options.maxSize <= 0))
|
|
89
51
|
throw new RangeError("maxSize must be a positive integer.");
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.#onEvict = options.onEvict;
|
|
52
|
+
if (options.ttl !== undefined || options.jitter !== undefined || options.maxSize !== undefined || options.slide !== undefined || options.onEvict !== undefined)
|
|
53
|
+
this.#policy = newPolicy(options);
|
|
93
54
|
if (entries)
|
|
94
55
|
for (const [key, value] of entries)
|
|
95
56
|
this.set(key, value);
|
|
96
57
|
}
|
|
97
58
|
set(key, value, ttl) {
|
|
59
|
+
if (ttl === undefined && this.#policy === undefined)
|
|
60
|
+
return super.set(key, value);
|
|
98
61
|
assertTTL(ttl);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
super.set(key, value);
|
|
62
|
+
let window = ttl ?? this.#policy?.ttl;
|
|
63
|
+
const jitter = this.#policy?.jitter ?? 0;
|
|
64
|
+
if (window !== undefined && jitter > 0)
|
|
65
|
+
window = Math.max(1, window * (1 - jitter * Math.random()));
|
|
104
66
|
if (window !== undefined)
|
|
105
|
-
this.#
|
|
106
|
-
|
|
107
|
-
|
|
67
|
+
this.#policy ??= newPolicy();
|
|
68
|
+
if (!this.#policy)
|
|
69
|
+
return super.set(key, value);
|
|
70
|
+
const before = super.size;
|
|
71
|
+
super.set(key, value);
|
|
72
|
+
this.#track(key, value, window, super.size !== before);
|
|
108
73
|
this.#enforceCap();
|
|
109
74
|
return this;
|
|
110
75
|
}
|
|
111
76
|
setWithoutTTL(key, value) {
|
|
112
|
-
if (this.#
|
|
113
|
-
this.#
|
|
114
|
-
if (this.#lru.size > 0)
|
|
115
|
-
this.#lru.delete(key);
|
|
77
|
+
if (this.#policy)
|
|
78
|
+
this.#forget(key);
|
|
116
79
|
super.set(key, value);
|
|
117
80
|
return this;
|
|
118
81
|
}
|
|
119
82
|
get(key) {
|
|
120
|
-
|
|
121
|
-
|
|
83
|
+
const policy = this.#policy;
|
|
84
|
+
const entry = policy?.entries.get(key);
|
|
85
|
+
if (entry === undefined) {
|
|
86
|
+
const value = mapGet.call(this, key);
|
|
87
|
+
if (value !== undefined || mapHas.call(this, key)) {
|
|
88
|
+
this.#hits++;
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
this.#misses++;
|
|
122
92
|
return;
|
|
123
93
|
}
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
94
|
+
const timed = entry.window !== 0;
|
|
95
|
+
const now = timed ? Date.now() : 0;
|
|
96
|
+
if (timed && entry.deadline <= now) {
|
|
97
|
+
this.#expire(entry);
|
|
98
|
+
this.#misses++;
|
|
127
99
|
return;
|
|
128
100
|
}
|
|
129
|
-
this.#
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return value;
|
|
101
|
+
this.#hits++;
|
|
102
|
+
if (timed && policy.slide)
|
|
103
|
+
entry.deadline = now + entry.window;
|
|
104
|
+
if (entry.inLru)
|
|
105
|
+
this.#promote(policy, entry);
|
|
106
|
+
return entry.value;
|
|
107
|
+
}
|
|
108
|
+
ensure(key, factory, ttl) {
|
|
109
|
+
const existing = this.get(key);
|
|
110
|
+
if (existing !== undefined || super.has(key))
|
|
111
|
+
return existing;
|
|
112
|
+
const created = factory(key, this);
|
|
113
|
+
this.set(key, created, ttl);
|
|
114
|
+
return created;
|
|
135
115
|
}
|
|
136
116
|
peek(key) {
|
|
137
117
|
if (!this.#expireIfDue(key) && super.has(key)) {
|
|
138
|
-
this.#
|
|
118
|
+
this.#hits++;
|
|
139
119
|
return super.get(key);
|
|
140
120
|
}
|
|
141
|
-
this.#
|
|
121
|
+
this.#misses++;
|
|
142
122
|
return;
|
|
143
123
|
}
|
|
144
124
|
get stats() {
|
|
145
|
-
return {
|
|
125
|
+
return {
|
|
126
|
+
hits: this.#hits,
|
|
127
|
+
misses: this.#misses,
|
|
128
|
+
expired: this.#policy?.expired ?? 0,
|
|
129
|
+
evicted: this.#policy?.evicted ?? 0
|
|
130
|
+
};
|
|
146
131
|
}
|
|
147
132
|
has(key) {
|
|
148
133
|
return !this.#expireIfDue(key) && super.has(key);
|
|
@@ -150,19 +135,23 @@ class Collection extends Map {
|
|
|
150
135
|
delete(key) {
|
|
151
136
|
if (this.#expireIfDue(key))
|
|
152
137
|
return false;
|
|
153
|
-
this.#
|
|
154
|
-
|
|
138
|
+
if (this.#policy)
|
|
139
|
+
this.#forget(key);
|
|
155
140
|
return super.delete(key);
|
|
156
141
|
}
|
|
157
142
|
clear() {
|
|
158
143
|
super.clear();
|
|
159
|
-
this.#
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
144
|
+
const policy = this.#policy;
|
|
145
|
+
if (!policy)
|
|
146
|
+
return;
|
|
147
|
+
policy.entries.clear();
|
|
148
|
+
policy.oldest = policy.newest = undefined;
|
|
149
|
+
policy.lruSize = 0;
|
|
150
|
+
policy.heap.length = 0;
|
|
151
|
+
if (policy.timer)
|
|
152
|
+
clearTimeout(policy.timer);
|
|
153
|
+
policy.timer = undefined;
|
|
154
|
+
policy.armedFor = Infinity;
|
|
166
155
|
}
|
|
167
156
|
get size() {
|
|
168
157
|
this.purge();
|
|
@@ -190,11 +179,11 @@ class Collection extends Map {
|
|
|
190
179
|
ttlRemaining(key) {
|
|
191
180
|
if (this.#expireIfDue(key))
|
|
192
181
|
return;
|
|
193
|
-
const
|
|
194
|
-
return
|
|
182
|
+
const entry = this.#policy?.entries.get(key);
|
|
183
|
+
return entry && entry.window !== 0 ? Math.max(0, entry.deadline - Date.now()) : undefined;
|
|
195
184
|
}
|
|
196
185
|
purge() {
|
|
197
|
-
if (this.#
|
|
186
|
+
if (!this.#policy || this.#policy.heap.length === 0)
|
|
198
187
|
return 0;
|
|
199
188
|
const now = Date.now();
|
|
200
189
|
let removed = 0;
|
|
@@ -205,133 +194,255 @@ class Collection extends Map {
|
|
|
205
194
|
this.#remove(due.key);
|
|
206
195
|
removed++;
|
|
207
196
|
}
|
|
208
|
-
this.#
|
|
197
|
+
this.#policy.expired += removed;
|
|
209
198
|
this.#rearm();
|
|
210
199
|
for (const [key, value] of dropped)
|
|
211
200
|
this.#notify(key, value, "expired");
|
|
212
201
|
return removed;
|
|
213
202
|
}
|
|
214
203
|
#expireIfDue(key) {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
204
|
+
const entry = this.#policy?.entries.get(key);
|
|
205
|
+
if (!entry || entry.window === 0 || entry.deadline > Date.now())
|
|
217
206
|
return false;
|
|
218
|
-
|
|
219
|
-
this.#remove(key);
|
|
220
|
-
this.#stats.expired++;
|
|
221
|
-
this.#notify(key, value, "expired");
|
|
207
|
+
this.#expire(entry);
|
|
222
208
|
return true;
|
|
223
209
|
}
|
|
210
|
+
#expire(entry) {
|
|
211
|
+
const value = super.get(entry.key);
|
|
212
|
+
this.#remove(entry.key);
|
|
213
|
+
this.#policy.expired++;
|
|
214
|
+
this.#notify(entry.key, value, "expired");
|
|
215
|
+
}
|
|
224
216
|
#remove(key) {
|
|
225
|
-
this.#
|
|
226
|
-
this.#lru.delete(key);
|
|
217
|
+
this.#forget(key);
|
|
227
218
|
super.delete(key);
|
|
228
219
|
}
|
|
220
|
+
#forget(key) {
|
|
221
|
+
const policy = this.#policy;
|
|
222
|
+
const entry = policy.entries.get(key);
|
|
223
|
+
if (!entry)
|
|
224
|
+
return;
|
|
225
|
+
if (entry.inLru)
|
|
226
|
+
this.#unlink(policy, entry);
|
|
227
|
+
policy.entries.delete(key);
|
|
228
|
+
}
|
|
229
|
+
#track(key, value, window, isNew) {
|
|
230
|
+
const policy = this.#policy;
|
|
231
|
+
const lru = policy.maxSize !== undefined;
|
|
232
|
+
let entry = isNew ? undefined : policy.entries.get(key);
|
|
233
|
+
if (entry)
|
|
234
|
+
entry.value = value;
|
|
235
|
+
if (window === undefined) {
|
|
236
|
+
if (entry && entry.window !== 0) {
|
|
237
|
+
if (lru)
|
|
238
|
+
entry = this.#replace(policy, entry, 0, 0);
|
|
239
|
+
else {
|
|
240
|
+
this.#forget(key);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!entry && lru) {
|
|
245
|
+
entry = this.#create(key, value, 0, 0);
|
|
246
|
+
policy.entries.set(key, entry);
|
|
247
|
+
}
|
|
248
|
+
if (entry)
|
|
249
|
+
this.#promote(policy, entry);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const deadline = Date.now() + window;
|
|
253
|
+
if (entry && entry.window !== 0) {
|
|
254
|
+
entry.deadline = deadline;
|
|
255
|
+
entry.window = window;
|
|
256
|
+
if (deadline < entry.filed)
|
|
257
|
+
entry = this.#replace(policy, entry, window, deadline);
|
|
258
|
+
else {
|
|
259
|
+
if (entry.inLru)
|
|
260
|
+
this.#promote(policy, entry);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
} else if (entry) {
|
|
264
|
+
entry.window = window;
|
|
265
|
+
entry.deadline = entry.filed = deadline;
|
|
266
|
+
} else {
|
|
267
|
+
entry = this.#create(key, value, window, deadline);
|
|
268
|
+
policy.entries.set(key, entry);
|
|
269
|
+
}
|
|
270
|
+
if (lru)
|
|
271
|
+
this.#promote(policy, entry);
|
|
272
|
+
this.#heapPush(entry);
|
|
273
|
+
if (policy.heap.length > 2 * policy.entries.size + 8)
|
|
274
|
+
this.#compact();
|
|
275
|
+
if (policy.timer === undefined || deadline < policy.armedFor)
|
|
276
|
+
this.#rearm();
|
|
277
|
+
}
|
|
278
|
+
#create(key, value, window, deadline) {
|
|
279
|
+
return {
|
|
280
|
+
key,
|
|
281
|
+
value,
|
|
282
|
+
older: undefined,
|
|
283
|
+
newer: undefined,
|
|
284
|
+
inLru: false,
|
|
285
|
+
window,
|
|
286
|
+
deadline,
|
|
287
|
+
filed: deadline
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
#replace(policy, old, window, deadline) {
|
|
291
|
+
const entry = {
|
|
292
|
+
...old,
|
|
293
|
+
window,
|
|
294
|
+
deadline,
|
|
295
|
+
filed: deadline
|
|
296
|
+
};
|
|
297
|
+
if (old.inLru) {
|
|
298
|
+
if (old.older)
|
|
299
|
+
old.older.newer = entry;
|
|
300
|
+
else
|
|
301
|
+
policy.oldest = entry;
|
|
302
|
+
if (old.newer)
|
|
303
|
+
old.newer.older = entry;
|
|
304
|
+
else
|
|
305
|
+
policy.newest = entry;
|
|
306
|
+
}
|
|
307
|
+
policy.entries.set(old.key, entry);
|
|
308
|
+
return entry;
|
|
309
|
+
}
|
|
310
|
+
#promote(policy, entry) {
|
|
311
|
+
if (entry === policy.newest)
|
|
312
|
+
return;
|
|
313
|
+
if (entry.inLru)
|
|
314
|
+
this.#unlink(policy, entry, true);
|
|
315
|
+
else {
|
|
316
|
+
entry.inLru = true;
|
|
317
|
+
policy.lruSize++;
|
|
318
|
+
}
|
|
319
|
+
entry.older = policy.newest;
|
|
320
|
+
entry.newer = undefined;
|
|
321
|
+
if (policy.newest)
|
|
322
|
+
policy.newest.newer = entry;
|
|
323
|
+
else
|
|
324
|
+
policy.oldest = entry;
|
|
325
|
+
policy.newest = entry;
|
|
326
|
+
}
|
|
327
|
+
#unlink(policy, entry, keepCount = false) {
|
|
328
|
+
if (entry.older)
|
|
329
|
+
entry.older.newer = entry.newer;
|
|
330
|
+
else
|
|
331
|
+
policy.oldest = entry.newer;
|
|
332
|
+
if (entry.newer)
|
|
333
|
+
entry.newer.older = entry.older;
|
|
334
|
+
else
|
|
335
|
+
policy.newest = entry.older;
|
|
336
|
+
entry.older = entry.newer = undefined;
|
|
337
|
+
if (!keepCount) {
|
|
338
|
+
entry.inLru = false;
|
|
339
|
+
policy.lruSize--;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
#derived() {
|
|
343
|
+
const Species = this.constructor[Symbol.species] ?? Collection;
|
|
344
|
+
return new Species;
|
|
345
|
+
}
|
|
229
346
|
#notify(key, value, reason) {
|
|
230
|
-
|
|
347
|
+
const onEvict = this.#policy?.onEvict;
|
|
348
|
+
if (!onEvict)
|
|
231
349
|
return;
|
|
232
350
|
try {
|
|
233
|
-
|
|
351
|
+
onEvict(key, value, reason);
|
|
234
352
|
} catch {}
|
|
235
353
|
}
|
|
236
354
|
#enforceCap() {
|
|
237
|
-
|
|
355
|
+
const policy = this.#policy;
|
|
356
|
+
const max = policy.maxSize;
|
|
357
|
+
if (max === undefined)
|
|
238
358
|
return;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.#
|
|
359
|
+
if (policy.lruSize > max && policy.heap.length > 0 && policy.heap[0].filed <= Date.now())
|
|
360
|
+
this.purge();
|
|
361
|
+
while (policy.lruSize > max) {
|
|
362
|
+
const oldest = policy.oldest;
|
|
363
|
+
const value = policy.onEvict ? super.get(oldest.key) : undefined;
|
|
364
|
+
this.#unlink(policy, oldest);
|
|
365
|
+
policy.entries.delete(oldest.key);
|
|
366
|
+
super.delete(oldest.key);
|
|
367
|
+
policy.evicted++;
|
|
368
|
+
this.#notify(oldest.key, value, "evicted");
|
|
245
369
|
}
|
|
246
370
|
}
|
|
247
|
-
#schedule(key, window) {
|
|
248
|
-
const deadline = Date.now() + window;
|
|
249
|
-
const expiry = this.#expiry.get(key);
|
|
250
|
-
if (expiry) {
|
|
251
|
-
expiry.deadline = deadline;
|
|
252
|
-
expiry.window = window;
|
|
253
|
-
if (deadline >= expiry.filed)
|
|
254
|
-
return;
|
|
255
|
-
expiry.filed = deadline;
|
|
256
|
-
} else
|
|
257
|
-
this.#expiry.set(key, { deadline, window, filed: deadline });
|
|
258
|
-
this.#heapPush({ key, deadline });
|
|
259
|
-
if (this.#heap.length > 2 * this.#expiry.size + 8)
|
|
260
|
-
this.#compact();
|
|
261
|
-
this.#rearm();
|
|
262
|
-
}
|
|
263
371
|
#nextDeadline() {
|
|
372
|
+
const policy = this.#policy;
|
|
264
373
|
for (;; ) {
|
|
265
|
-
const top =
|
|
374
|
+
const top = policy.heap[0];
|
|
266
375
|
if (top === undefined)
|
|
267
376
|
return Infinity;
|
|
268
|
-
|
|
269
|
-
if (!expiry || expiry.filed !== top.deadline) {
|
|
377
|
+
if (policy.entries.get(top.key) !== top) {
|
|
270
378
|
this.#heapPop();
|
|
271
379
|
continue;
|
|
272
380
|
}
|
|
273
|
-
if (
|
|
274
|
-
return top.
|
|
381
|
+
if (top.deadline === top.filed)
|
|
382
|
+
return top.filed;
|
|
275
383
|
this.#heapPop();
|
|
276
|
-
|
|
277
|
-
this.#heapPush(
|
|
384
|
+
top.filed = top.deadline;
|
|
385
|
+
this.#heapPush(top);
|
|
278
386
|
}
|
|
279
387
|
}
|
|
280
388
|
#compact() {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
389
|
+
const policy = this.#policy;
|
|
390
|
+
const live = policy.heap.filter((entry) => policy.entries.get(entry.key) === entry);
|
|
391
|
+
policy.heap.length = 0;
|
|
392
|
+
for (const entry of live)
|
|
393
|
+
this.#heapPush(entry);
|
|
285
394
|
}
|
|
286
395
|
#rearm() {
|
|
396
|
+
const p = this.#policy;
|
|
287
397
|
const deadline = this.#nextDeadline();
|
|
288
|
-
if (
|
|
398
|
+
if (p.timer !== undefined && deadline >= p.armedFor)
|
|
289
399
|
return;
|
|
290
|
-
if (
|
|
291
|
-
clearTimeout(
|
|
292
|
-
|
|
293
|
-
|
|
400
|
+
if (p.timer)
|
|
401
|
+
clearTimeout(p.timer);
|
|
402
|
+
p.timer = undefined;
|
|
403
|
+
p.armedFor = deadline;
|
|
294
404
|
if (deadline === Infinity)
|
|
295
405
|
return;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
406
|
+
p.timer = setTimeout(() => {
|
|
407
|
+
p.timer = undefined;
|
|
408
|
+
p.armedFor = Infinity;
|
|
299
409
|
this.purge();
|
|
300
410
|
}, Math.max(0, deadline - Date.now()));
|
|
301
|
-
|
|
411
|
+
p.timer.unref?.();
|
|
302
412
|
}
|
|
303
|
-
#heapPush(
|
|
304
|
-
const heap = this.#heap;
|
|
305
|
-
heap.
|
|
306
|
-
|
|
413
|
+
#heapPush(entry) {
|
|
414
|
+
const heap = this.#policy.heap;
|
|
415
|
+
let i = heap.length;
|
|
416
|
+
heap.push(entry);
|
|
307
417
|
while (i > 0) {
|
|
308
418
|
const parent = i - 1 >> 1;
|
|
309
|
-
|
|
419
|
+
const above = heap[parent];
|
|
420
|
+
if (above.filed <= entry.filed)
|
|
310
421
|
break;
|
|
311
|
-
|
|
422
|
+
heap[i] = above;
|
|
312
423
|
i = parent;
|
|
313
424
|
}
|
|
425
|
+
heap[i] = entry;
|
|
314
426
|
}
|
|
315
427
|
#heapPop() {
|
|
316
|
-
const heap = this.#heap;
|
|
428
|
+
const heap = this.#policy.heap;
|
|
317
429
|
const top = heap[0];
|
|
318
430
|
const last = heap.pop();
|
|
319
431
|
if (top === undefined || heap.length === 0)
|
|
320
432
|
return top;
|
|
321
|
-
|
|
322
|
-
for (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
smallest = right;
|
|
330
|
-
if (smallest === i)
|
|
433
|
+
let i = 0;
|
|
434
|
+
for (;; ) {
|
|
435
|
+
let child = 2 * i + 1;
|
|
436
|
+
if (child >= heap.length)
|
|
437
|
+
break;
|
|
438
|
+
if (child + 1 < heap.length && heap[child + 1].filed < heap[child].filed)
|
|
439
|
+
child++;
|
|
440
|
+
if (heap[child].filed >= last.filed)
|
|
331
441
|
break;
|
|
332
|
-
|
|
333
|
-
i =
|
|
442
|
+
heap[i] = heap[child];
|
|
443
|
+
i = child;
|
|
334
444
|
}
|
|
445
|
+
heap[i] = last;
|
|
335
446
|
return top;
|
|
336
447
|
}
|
|
337
448
|
first() {
|
|
@@ -363,19 +474,35 @@ class Collection extends Map {
|
|
|
363
474
|
}
|
|
364
475
|
return;
|
|
365
476
|
}
|
|
477
|
+
findLast(predicate) {
|
|
478
|
+
const keys = this.keyArray();
|
|
479
|
+
const values = this.array();
|
|
480
|
+
for (let i = values.length - 1;i >= 0; i--)
|
|
481
|
+
if (predicate(values[i], keys[i], this))
|
|
482
|
+
return values[i];
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
findLastKey(predicate) {
|
|
486
|
+
const keys = this.keyArray();
|
|
487
|
+
const values = this.array();
|
|
488
|
+
for (let i = values.length - 1;i >= 0; i--)
|
|
489
|
+
if (predicate(values[i], keys[i], this))
|
|
490
|
+
return keys[i];
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
366
493
|
filter(predicate) {
|
|
367
|
-
const result =
|
|
368
|
-
|
|
494
|
+
const result = this.#derived();
|
|
495
|
+
this.forEach((value, key) => {
|
|
369
496
|
if (predicate(value, key, this))
|
|
370
497
|
result.set(key, value);
|
|
371
|
-
}
|
|
498
|
+
});
|
|
372
499
|
return result;
|
|
373
500
|
}
|
|
374
501
|
map(transform) {
|
|
375
502
|
const result = [];
|
|
376
|
-
|
|
503
|
+
this.forEach((value, key) => {
|
|
377
504
|
result.push(transform(value, key, this));
|
|
378
|
-
}
|
|
505
|
+
});
|
|
379
506
|
return result;
|
|
380
507
|
}
|
|
381
508
|
some(predicate) {
|
|
@@ -393,9 +520,9 @@ class Collection extends Map {
|
|
|
393
520
|
return true;
|
|
394
521
|
}
|
|
395
522
|
each(callback) {
|
|
396
|
-
|
|
523
|
+
this.forEach((value, key) => {
|
|
397
524
|
callback(value, key, this);
|
|
398
|
-
}
|
|
525
|
+
});
|
|
399
526
|
return this;
|
|
400
527
|
}
|
|
401
528
|
array() {
|
|
@@ -408,9 +535,10 @@ class Collection extends Map {
|
|
|
408
535
|
return [...this.entries()];
|
|
409
536
|
}
|
|
410
537
|
clone() {
|
|
411
|
-
const copy =
|
|
412
|
-
|
|
538
|
+
const copy = this.#derived();
|
|
539
|
+
this.forEach((value, key) => {
|
|
413
540
|
copy.set(key, value);
|
|
541
|
+
});
|
|
414
542
|
return copy;
|
|
415
543
|
}
|
|
416
544
|
hasAll(...keys) {
|
|
@@ -463,7 +591,7 @@ class Collection extends Map {
|
|
|
463
591
|
return result;
|
|
464
592
|
}
|
|
465
593
|
intersection(other) {
|
|
466
|
-
const result =
|
|
594
|
+
const result = this.#derived();
|
|
467
595
|
for (const [key, value] of this) {
|
|
468
596
|
if (other.has(key))
|
|
469
597
|
result.set(key, value);
|
|
@@ -471,7 +599,7 @@ class Collection extends Map {
|
|
|
471
599
|
return result;
|
|
472
600
|
}
|
|
473
601
|
difference(other) {
|
|
474
|
-
const result =
|
|
602
|
+
const result = this.#derived();
|
|
475
603
|
for (const [key, value] of this) {
|
|
476
604
|
if (!other.has(key))
|
|
477
605
|
result.set(key, value);
|
|
@@ -479,8 +607,8 @@ class Collection extends Map {
|
|
|
479
607
|
return result;
|
|
480
608
|
}
|
|
481
609
|
partition(predicate) {
|
|
482
|
-
const pass =
|
|
483
|
-
const fail =
|
|
610
|
+
const pass = this.#derived();
|
|
611
|
+
const fail = this.#derived();
|
|
484
612
|
for (const [key, value] of this) {
|
|
485
613
|
if (predicate(value, key, this))
|
|
486
614
|
pass.set(key, value);
|
|
@@ -489,6 +617,81 @@ class Collection extends Map {
|
|
|
489
617
|
}
|
|
490
618
|
return [pass, fail];
|
|
491
619
|
}
|
|
620
|
+
symmetricDifference(other) {
|
|
621
|
+
const result = this.#derived();
|
|
622
|
+
for (const [key, value] of this)
|
|
623
|
+
if (!other.has(key))
|
|
624
|
+
result.set(key, value);
|
|
625
|
+
for (const [key, value] of other)
|
|
626
|
+
if (!this.has(key))
|
|
627
|
+
result.set(key, value);
|
|
628
|
+
return result;
|
|
629
|
+
}
|
|
630
|
+
concat(...collections) {
|
|
631
|
+
const result = this.clone();
|
|
632
|
+
for (const collection of collections)
|
|
633
|
+
for (const [key, value] of collection)
|
|
634
|
+
result.set(key, value);
|
|
635
|
+
return result;
|
|
636
|
+
}
|
|
637
|
+
merge(other, whenInSelf, whenInOther, whenInBoth) {
|
|
638
|
+
const result = this.#derived();
|
|
639
|
+
const decide = (key, kept) => {
|
|
640
|
+
if (kept.keep)
|
|
641
|
+
result.set(key, kept.value);
|
|
642
|
+
};
|
|
643
|
+
for (const [key, value] of this) {
|
|
644
|
+
decide(key, other.has(key) ? whenInBoth(value, peekOf(other, key), key) : whenInSelf(value, key));
|
|
645
|
+
}
|
|
646
|
+
for (const [key, value] of other)
|
|
647
|
+
if (!this.has(key))
|
|
648
|
+
decide(key, whenInOther(value, key));
|
|
649
|
+
return result;
|
|
650
|
+
}
|
|
651
|
+
equals(other) {
|
|
652
|
+
if (!other)
|
|
653
|
+
return false;
|
|
654
|
+
if (other === this)
|
|
655
|
+
return true;
|
|
656
|
+
if (this.size !== other.size)
|
|
657
|
+
return false;
|
|
658
|
+
for (const [key, value] of this) {
|
|
659
|
+
if (!other.has(key))
|
|
660
|
+
return false;
|
|
661
|
+
if (value !== peekOf(other, key))
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
mapValues(transform) {
|
|
667
|
+
const result = this.#derived();
|
|
668
|
+
for (const [key, value] of this)
|
|
669
|
+
result.set(key, transform(value, key, this));
|
|
670
|
+
return result;
|
|
671
|
+
}
|
|
672
|
+
toReversed() {
|
|
673
|
+
const result = this.#derived();
|
|
674
|
+
const entries = [...this];
|
|
675
|
+
for (let i = entries.length - 1;i >= 0; i--)
|
|
676
|
+
result.set(entries[i][0], entries[i][1]);
|
|
677
|
+
return result;
|
|
678
|
+
}
|
|
679
|
+
toSorted(comparator) {
|
|
680
|
+
return this.sorted(comparator);
|
|
681
|
+
}
|
|
682
|
+
static groupBy(items, keySelector) {
|
|
683
|
+
const groups = new Collection;
|
|
684
|
+
let index = 0;
|
|
685
|
+
for (const item of items)
|
|
686
|
+
groups.ensure(keySelector(item, index++), () => []).push(item);
|
|
687
|
+
return groups;
|
|
688
|
+
}
|
|
689
|
+
static combineEntries(entries, combine) {
|
|
690
|
+
const result = new Collection;
|
|
691
|
+
for (const [key, value] of entries)
|
|
692
|
+
result.set(key, result.has(key) ? combine(result.get(key), value, key) : value);
|
|
693
|
+
return result;
|
|
694
|
+
}
|
|
492
695
|
tap(fn) {
|
|
493
696
|
fn(this);
|
|
494
697
|
return this;
|
|
@@ -507,6 +710,13 @@ class Collection extends Map {
|
|
|
507
710
|
acc = fn(acc, value, key, this);
|
|
508
711
|
return acc;
|
|
509
712
|
}
|
|
713
|
+
reduceRight(fn, initialValue) {
|
|
714
|
+
const entries = [...this];
|
|
715
|
+
let acc = initialValue;
|
|
716
|
+
for (let i = entries.length - 1;i >= 0; i--)
|
|
717
|
+
acc = fn(acc, entries[i][1], entries[i][0], this);
|
|
718
|
+
return acc;
|
|
719
|
+
}
|
|
510
720
|
sorted(comparator) {
|
|
511
721
|
const decorated = [...this.entries()].map((entry, index) => ({
|
|
512
722
|
entry,
|
|
@@ -517,32 +727,52 @@ class Collection extends Map {
|
|
|
517
727
|
const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
|
|
518
728
|
return comparison !== 0 ? comparison : x.index - y.index;
|
|
519
729
|
});
|
|
520
|
-
const result =
|
|
730
|
+
const result = this.#derived();
|
|
521
731
|
for (const { entry } of decorated)
|
|
522
732
|
result.set(entry[0], entry[1]);
|
|
523
733
|
return result;
|
|
524
734
|
}
|
|
525
|
-
random() {
|
|
526
|
-
|
|
527
|
-
|
|
735
|
+
random(amount) {
|
|
736
|
+
if (amount !== undefined)
|
|
737
|
+
return sample([...this.values()], amount);
|
|
738
|
+
const size = this.size;
|
|
739
|
+
if (size === 0)
|
|
528
740
|
return;
|
|
529
|
-
|
|
741
|
+
let index = Math.floor(Math.random() * size);
|
|
742
|
+
for (const value of this.values())
|
|
743
|
+
if (index-- === 0)
|
|
744
|
+
return value;
|
|
745
|
+
return;
|
|
530
746
|
}
|
|
531
|
-
randomKey() {
|
|
532
|
-
|
|
533
|
-
|
|
747
|
+
randomKey(amount) {
|
|
748
|
+
if (amount !== undefined)
|
|
749
|
+
return sample([...this.keys()], amount);
|
|
750
|
+
const size = this.size;
|
|
751
|
+
if (size === 0)
|
|
534
752
|
return;
|
|
535
|
-
|
|
753
|
+
let index = Math.floor(Math.random() * size);
|
|
754
|
+
for (const key of this.keys())
|
|
755
|
+
if (index-- === 0)
|
|
756
|
+
return key;
|
|
757
|
+
return;
|
|
536
758
|
}
|
|
537
759
|
at(index) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
760
|
+
let remaining = index < 0 ? this.size + index : index;
|
|
761
|
+
if (remaining < 0)
|
|
762
|
+
return;
|
|
763
|
+
for (const value of this.values())
|
|
764
|
+
if (remaining-- === 0)
|
|
765
|
+
return value;
|
|
766
|
+
return;
|
|
541
767
|
}
|
|
542
768
|
keyAt(index) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
769
|
+
let remaining = index < 0 ? this.size + index : index;
|
|
770
|
+
if (remaining < 0)
|
|
771
|
+
return;
|
|
772
|
+
for (const key of this.keys())
|
|
773
|
+
if (remaining-- === 0)
|
|
774
|
+
return key;
|
|
775
|
+
return;
|
|
546
776
|
}
|
|
547
777
|
toJSON() {
|
|
548
778
|
return [...this.entries()];
|
|
@@ -656,7 +886,7 @@ class ResourceManager extends Manager {
|
|
|
656
886
|
// packages/rest/package.json
|
|
657
887
|
var package_default = {
|
|
658
888
|
name: "@lunibee/rest",
|
|
659
|
-
version: "0.
|
|
889
|
+
version: "0.3.0",
|
|
660
890
|
type: "module",
|
|
661
891
|
module: "./src/index.ts",
|
|
662
892
|
types: "./src/index.ts",
|
|
@@ -673,6 +903,9 @@ var Routes = {
|
|
|
673
903
|
user: () => "/users/@me",
|
|
674
904
|
userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
|
|
675
905
|
guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
|
|
906
|
+
currentUserGuild: (guildId) => `/users/@me/guilds/${snowflake(guildId, "Guild ID")}`,
|
|
907
|
+
sticker: (stickerId) => `/stickers/${snowflake(stickerId, "Sticker ID")}`,
|
|
908
|
+
messageReactionUser: (channelId, messageId, emoji, userId) => `${Routes.messageReactions(channelId, messageId, emoji)}/${snowflake(userId, "User ID")}`,
|
|
676
909
|
guildPreview: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/preview`,
|
|
677
910
|
guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
|
|
678
911
|
guildWebhooks: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/webhooks`,
|
|
@@ -689,11 +922,10 @@ var Routes = {
|
|
|
689
922
|
message: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/${snowflake(messageId, "Message ID")}`,
|
|
690
923
|
crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
|
|
691
924
|
messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
|
|
925
|
+
messageReactionMe: (channelId, messageId, emoji) => `${Routes.messageReactions(channelId, messageId, emoji)}/@me`,
|
|
692
926
|
messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
|
|
693
927
|
channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
|
|
694
928
|
channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
|
|
695
|
-
channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
|
|
696
|
-
channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
|
|
697
929
|
messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
|
|
698
930
|
channelBulkDelete: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/bulk-delete`,
|
|
699
931
|
channelWebhooks: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/webhooks`,
|
|
@@ -708,6 +940,10 @@ var Routes = {
|
|
|
708
940
|
interactionOriginalResponse: (applicationId, token) => `/webhooks/${snowflake(applicationId, "Application ID")}/${encodeURIComponent(token)}/messages/@original`,
|
|
709
941
|
channelPublicArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/public`,
|
|
710
942
|
channelPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/private`,
|
|
943
|
+
channelJoinedPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/users/@me/threads/archived/private`,
|
|
944
|
+
threadMember: (threadId, userId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members/${userOrMe(userId)}`,
|
|
945
|
+
channelTyping: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/typing`,
|
|
946
|
+
channelThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads`,
|
|
711
947
|
threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
|
|
712
948
|
guildScheduledEvents: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events`,
|
|
713
949
|
guildScheduledEvent: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}`,
|
|
@@ -720,6 +956,13 @@ var Routes = {
|
|
|
720
956
|
gatewayBot: () => "/gateway/bot",
|
|
721
957
|
guildAuditLog: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/audit-logs`,
|
|
722
958
|
guildMembers: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members`,
|
|
959
|
+
guildMembersSearch: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/search`,
|
|
960
|
+
guildMemberMe: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/@me`,
|
|
961
|
+
guildBulkBan: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/bulk-ban`,
|
|
962
|
+
guildVoiceState: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/voice-states/${userOrMe(userId)}`,
|
|
963
|
+
guildIntegration: (guildId, integrationId) => `/guilds/${snowflake(guildId, "Guild ID")}/integrations/${snowflake(integrationId, "Integration ID")}`,
|
|
964
|
+
userGuilds: () => "/users/@me/guilds",
|
|
965
|
+
stickerPacks: (packId) => packId ? `/sticker-packs/${snowflake(packId, "Sticker pack ID")}` : "/sticker-packs",
|
|
723
966
|
guildWelcomeScreen: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/welcome-screen`,
|
|
724
967
|
guildOnboarding: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/onboarding`,
|
|
725
968
|
guildPrune: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/prune`,
|
|
@@ -740,6 +983,9 @@ var Routes = {
|
|
|
740
983
|
consumeEntitlement: (applicationId, entitlementId) => `/applications/${snowflake(applicationId, "Application ID")}/entitlements/${snowflake(entitlementId, "Entitlement ID")}/consume`,
|
|
741
984
|
skuSubscription: (skuId, subscriptionId) => subscriptionId ? `/skus/${snowflake(skuId, "SKU ID")}/subscriptions/${snowflake(subscriptionId, "Subscription ID")}` : `/skus/${snowflake(skuId, "SKU ID")}/subscriptions`
|
|
742
985
|
};
|
|
986
|
+
function userOrMe(value) {
|
|
987
|
+
return value === "@me" ? value : snowflake(value, "User ID");
|
|
988
|
+
}
|
|
743
989
|
function integer(value, field) {
|
|
744
990
|
if (!Number.isInteger(value) || value < 0)
|
|
745
991
|
throw new TypeError(`${field} must be a non-negative integer.`);
|
|
@@ -765,6 +1011,76 @@ var REQUEST_DATA_KEYS = new Set([
|
|
|
765
1011
|
"signal"
|
|
766
1012
|
]);
|
|
767
1013
|
|
|
1014
|
+
// packages/types/src/channel-kind.ts
|
|
1015
|
+
var ChannelKinds = {
|
|
1016
|
+
text: [0],
|
|
1017
|
+
dm: [1],
|
|
1018
|
+
voice: [2],
|
|
1019
|
+
"group-dm": [3],
|
|
1020
|
+
category: [4],
|
|
1021
|
+
announcement: [5],
|
|
1022
|
+
thread: [10, 11, 12],
|
|
1023
|
+
stage: [13],
|
|
1024
|
+
directory: [14],
|
|
1025
|
+
forum: [15],
|
|
1026
|
+
media: [16]
|
|
1027
|
+
};
|
|
1028
|
+
var KIND_OF_TYPE = new Map(Object.keys(ChannelKinds).flatMap((kind) => ChannelKinds[kind].map((type) => [type, kind])));
|
|
1029
|
+
function channelKindOf(type) {
|
|
1030
|
+
return KIND_OF_TYPE.get(type) ?? "unknown";
|
|
1031
|
+
}
|
|
1032
|
+
// packages/types/src/gateway.ts
|
|
1033
|
+
var GatewayIntentBits = {
|
|
1034
|
+
Guilds: 1 << 0,
|
|
1035
|
+
GuildMembers: 1 << 1,
|
|
1036
|
+
GuildModeration: 1 << 2,
|
|
1037
|
+
GuildExpressions: 1 << 3,
|
|
1038
|
+
GuildIntegrations: 1 << 4,
|
|
1039
|
+
GuildWebhooks: 1 << 5,
|
|
1040
|
+
GuildInvites: 1 << 6,
|
|
1041
|
+
GuildVoiceStates: 1 << 7,
|
|
1042
|
+
GuildPresences: 1 << 8,
|
|
1043
|
+
GuildMessages: 1 << 9,
|
|
1044
|
+
GuildMessageReactions: 1 << 10,
|
|
1045
|
+
GuildMessageTyping: 1 << 11,
|
|
1046
|
+
DirectMessages: 1 << 12,
|
|
1047
|
+
DirectMessageReactions: 1 << 13,
|
|
1048
|
+
DirectMessageTyping: 1 << 14,
|
|
1049
|
+
MessageContent: 1 << 15,
|
|
1050
|
+
GuildScheduledEvents: 1 << 16,
|
|
1051
|
+
AutoModerationConfiguration: 1 << 20,
|
|
1052
|
+
AutoModerationExecution: 1 << 21,
|
|
1053
|
+
GuildMessagePolls: 1 << 24,
|
|
1054
|
+
DirectMessagePolls: 1 << 25
|
|
1055
|
+
};
|
|
1056
|
+
var IntentBits = {
|
|
1057
|
+
guild: 1 << 0,
|
|
1058
|
+
guilds: 1 << 0,
|
|
1059
|
+
guildMembers: 1 << 1,
|
|
1060
|
+
guildModeration: 1 << 2,
|
|
1061
|
+
guildBans: 1 << 2,
|
|
1062
|
+
guildExpressions: 1 << 3,
|
|
1063
|
+
guildEmojis: 1 << 3,
|
|
1064
|
+
guildEmojisAndStickers: 1 << 3,
|
|
1065
|
+
guildIntegrations: 1 << 4,
|
|
1066
|
+
guildWebhooks: 1 << 5,
|
|
1067
|
+
guildInvites: 1 << 6,
|
|
1068
|
+
guildVoiceStates: 1 << 7,
|
|
1069
|
+
guildPresences: 1 << 8,
|
|
1070
|
+
guildMessages: 1 << 9,
|
|
1071
|
+
guildMessage: 1 << 9,
|
|
1072
|
+
guildMessageReactions: 1 << 10,
|
|
1073
|
+
guildMessageTyping: 1 << 11,
|
|
1074
|
+
directMessages: 1 << 12,
|
|
1075
|
+
directMessageReactions: 1 << 13,
|
|
1076
|
+
directMessageTyping: 1 << 14,
|
|
1077
|
+
messageContent: 1 << 15,
|
|
1078
|
+
guildScheduledEvents: 1 << 16,
|
|
1079
|
+
autoModerationConfiguration: 1 << 20,
|
|
1080
|
+
autoModerationExecution: 1 << 21,
|
|
1081
|
+
guildMessagePolls: 1 << 24,
|
|
1082
|
+
directMessagePolls: 1 << 25
|
|
1083
|
+
};
|
|
768
1084
|
// packages/structures/src/base.ts
|
|
769
1085
|
class BaseStructure {
|
|
770
1086
|
id;
|
|
@@ -776,8 +1092,11 @@ class BaseStructure {
|
|
|
776
1092
|
toString() {
|
|
777
1093
|
return this.id;
|
|
778
1094
|
}
|
|
1095
|
+
get createdTimestamp() {
|
|
1096
|
+
return Number((BigInt(this.id) >> 22n) + 1420070400000n);
|
|
1097
|
+
}
|
|
779
1098
|
get createdAt() {
|
|
780
|
-
return new Date(
|
|
1099
|
+
return new Date(this.createdTimestamp);
|
|
781
1100
|
}
|
|
782
1101
|
}
|
|
783
1102
|
var CDN_BASE = "https://cdn.discordapp.com";
|
|
@@ -785,7 +1104,7 @@ function cdnURL(path, hash, options = {}) {
|
|
|
785
1104
|
const isAnimated = hash.startsWith("a_") && !options.forceStatic;
|
|
786
1105
|
const ext = options.extension ?? (isAnimated ? "gif" : "png");
|
|
787
1106
|
const size = options.size ? `?size=${options.size}` : "";
|
|
788
|
-
return `${CDN_BASE}${path}/${hash}.${ext}${size}`;
|
|
1107
|
+
return `${CDN_BASE}${path}/${encodeURIComponent(hash)}.${ext}${size}`;
|
|
789
1108
|
}
|
|
790
1109
|
|
|
791
1110
|
class User extends BaseStructure {
|
|
@@ -859,9 +1178,6 @@ class Channel extends BaseStructure {
|
|
|
859
1178
|
throw new Error("This channel is not attached to a client.");
|
|
860
1179
|
return this.#context.sendMessage(this.id, options);
|
|
861
1180
|
}
|
|
862
|
-
sendMessage(options) {
|
|
863
|
-
return this.send(options);
|
|
864
|
-
}
|
|
865
1181
|
edit(options) {
|
|
866
1182
|
if (!this.#context?.editChannel)
|
|
867
1183
|
throw new Error("This channel is not attached to a client.");
|
|
@@ -891,6 +1207,17 @@ class Channel extends BaseStructure {
|
|
|
891
1207
|
update(options) {
|
|
892
1208
|
return this.edit(options);
|
|
893
1209
|
}
|
|
1210
|
+
get kind() {
|
|
1211
|
+
return channelKindOf(this.type);
|
|
1212
|
+
}
|
|
1213
|
+
is(...kinds) {
|
|
1214
|
+
return kinds.includes(this.kind);
|
|
1215
|
+
}
|
|
1216
|
+
as(...kinds) {
|
|
1217
|
+
if (!this.is(...kinds))
|
|
1218
|
+
throw new TypeError(`Channel ${this.id} is a ${this.kind} channel, not ${kinds.join(" or ")}.`);
|
|
1219
|
+
return this;
|
|
1220
|
+
}
|
|
894
1221
|
isThread() {
|
|
895
1222
|
return this.type === 10 || this.type === 11 || this.type === 12;
|
|
896
1223
|
}
|
|
@@ -942,6 +1269,7 @@ class Guild extends BaseStructure {
|
|
|
942
1269
|
safetyAlertsChannelId;
|
|
943
1270
|
maxPresences;
|
|
944
1271
|
maxVideoChannelUsers;
|
|
1272
|
+
premiumProgressBarEnabled;
|
|
945
1273
|
constructor(data) {
|
|
946
1274
|
super(data.id);
|
|
947
1275
|
if (!data.name)
|
|
@@ -979,6 +1307,7 @@ class Guild extends BaseStructure {
|
|
|
979
1307
|
this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
|
|
980
1308
|
this.maxPresences = data.max_presences ?? null;
|
|
981
1309
|
this.maxVideoChannelUsers = data.max_video_channel_users;
|
|
1310
|
+
this.premiumProgressBarEnabled = data.premium_progress_bar_enabled ?? false;
|
|
982
1311
|
}
|
|
983
1312
|
iconURL(options = {}) {
|
|
984
1313
|
if (!this.icon)
|
|
@@ -1141,60 +1470,7 @@ var Permissions = {
|
|
|
1141
1470
|
PinMessages: 1n << 51n,
|
|
1142
1471
|
BypassSlowmode: 1n << 52n
|
|
1143
1472
|
};
|
|
1144
|
-
var PermissionFlagsBits =
|
|
1145
|
-
CreateInstantInvite: 1n << 0n,
|
|
1146
|
-
KickMembers: 1n << 1n,
|
|
1147
|
-
BanMembers: 1n << 2n,
|
|
1148
|
-
Administrator: 1n << 3n,
|
|
1149
|
-
ManageChannels: 1n << 4n,
|
|
1150
|
-
ManageGuild: 1n << 5n,
|
|
1151
|
-
AddReactions: 1n << 6n,
|
|
1152
|
-
ViewAuditLog: 1n << 7n,
|
|
1153
|
-
PrioritySpeaker: 1n << 8n,
|
|
1154
|
-
Stream: 1n << 9n,
|
|
1155
|
-
ViewChannel: 1n << 10n,
|
|
1156
|
-
SendMessages: 1n << 11n,
|
|
1157
|
-
SendTTSMessages: 1n << 12n,
|
|
1158
|
-
ManageMessages: 1n << 13n,
|
|
1159
|
-
EmbedLinks: 1n << 14n,
|
|
1160
|
-
AttachFiles: 1n << 15n,
|
|
1161
|
-
ReadMessageHistory: 1n << 16n,
|
|
1162
|
-
MentionEveryone: 1n << 17n,
|
|
1163
|
-
UseExternalEmojis: 1n << 18n,
|
|
1164
|
-
ViewGuildInsights: 1n << 19n,
|
|
1165
|
-
Connect: 1n << 20n,
|
|
1166
|
-
Speak: 1n << 21n,
|
|
1167
|
-
MuteMembers: 1n << 22n,
|
|
1168
|
-
DeafenMembers: 1n << 23n,
|
|
1169
|
-
MoveMembers: 1n << 24n,
|
|
1170
|
-
UseVAD: 1n << 25n,
|
|
1171
|
-
ChangeNickname: 1n << 26n,
|
|
1172
|
-
ManageNicknames: 1n << 27n,
|
|
1173
|
-
ManageRoles: 1n << 28n,
|
|
1174
|
-
ManageWebhooks: 1n << 29n,
|
|
1175
|
-
ManageGuildExpressions: 1n << 30n,
|
|
1176
|
-
UseApplicationCommands: 1n << 31n,
|
|
1177
|
-
RequestToSpeak: 1n << 32n,
|
|
1178
|
-
ManageEvents: 1n << 33n,
|
|
1179
|
-
ManageThreads: 1n << 34n,
|
|
1180
|
-
CreatePublicThreads: 1n << 35n,
|
|
1181
|
-
CreatePrivateThreads: 1n << 36n,
|
|
1182
|
-
UseExternalStickers: 1n << 37n,
|
|
1183
|
-
SendMessagesInThreads: 1n << 38n,
|
|
1184
|
-
UseEmbeddedActivities: 1n << 39n,
|
|
1185
|
-
ModerateMembers: 1n << 40n,
|
|
1186
|
-
ViewCreatorMonetizationAnalytics: 1n << 41n,
|
|
1187
|
-
UseSoundboard: 1n << 42n,
|
|
1188
|
-
CreateGuildExpressions: 1n << 43n,
|
|
1189
|
-
CreateEvents: 1n << 44n,
|
|
1190
|
-
UseExternalSounds: 1n << 45n,
|
|
1191
|
-
SendVoiceMessages: 1n << 46n,
|
|
1192
|
-
SetVoiceChannelStatus: 1n << 48n,
|
|
1193
|
-
SendPolls: 1n << 49n,
|
|
1194
|
-
UseExternalApps: 1n << 50n,
|
|
1195
|
-
PinMessages: 1n << 51n,
|
|
1196
|
-
BypassSlowmode: 1n << 52n
|
|
1197
|
-
};
|
|
1473
|
+
var PermissionFlagsBits = Permissions;
|
|
1198
1474
|
|
|
1199
1475
|
class PermissionSet {
|
|
1200
1476
|
bitfield;
|
|
@@ -1469,58 +1745,29 @@ class PermissionsBitField extends PermissionSet {
|
|
|
1469
1745
|
}
|
|
1470
1746
|
}
|
|
1471
1747
|
var ALL_PERMISSIONS = Object.values(Permission).reduce((bits, bit) => bits | bit, 0n);
|
|
1472
|
-
// packages/
|
|
1473
|
-
var
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
};
|
|
1496
|
-
var IntentBits = {
|
|
1497
|
-
guild: 1 << 0,
|
|
1498
|
-
guilds: 1 << 0,
|
|
1499
|
-
guildMembers: 1 << 1,
|
|
1500
|
-
guildModeration: 1 << 2,
|
|
1501
|
-
guildBans: 1 << 2,
|
|
1502
|
-
guildExpressions: 1 << 3,
|
|
1503
|
-
guildEmojis: 1 << 3,
|
|
1504
|
-
guildEmojisAndStickers: 1 << 3,
|
|
1505
|
-
guildIntegrations: 1 << 4,
|
|
1506
|
-
guildWebhooks: 1 << 5,
|
|
1507
|
-
guildInvites: 1 << 6,
|
|
1508
|
-
guildVoiceStates: 1 << 7,
|
|
1509
|
-
guildPresences: 1 << 8,
|
|
1510
|
-
guildMessages: 1 << 9,
|
|
1511
|
-
guildMessage: 1 << 9,
|
|
1512
|
-
guildMessageReactions: 1 << 10,
|
|
1513
|
-
guildMessageTyping: 1 << 11,
|
|
1514
|
-
directMessages: 1 << 12,
|
|
1515
|
-
directMessageReactions: 1 << 13,
|
|
1516
|
-
directMessageTyping: 1 << 14,
|
|
1517
|
-
messageContent: 1 << 15,
|
|
1518
|
-
guildScheduledEvents: 1 << 16,
|
|
1519
|
-
autoModerationConfiguration: 1 << 20,
|
|
1520
|
-
autoModerationExecution: 1 << 21,
|
|
1521
|
-
guildMessagePolls: 1 << 24,
|
|
1522
|
-
directMessagePolls: 1 << 25
|
|
1523
|
-
};
|
|
1748
|
+
// packages/builders/src/components.ts
|
|
1749
|
+
var IS_COMPONENTS_V2 = 1 << 15;
|
|
1750
|
+
// packages/builders/src/commands.ts
|
|
1751
|
+
var MAX_SAFE = Number.MAX_SAFE_INTEGER;
|
|
1752
|
+
// packages/utils/src/args.ts
|
|
1753
|
+
var TRUE_WORDS = new Set([
|
|
1754
|
+
"true",
|
|
1755
|
+
"yes",
|
|
1756
|
+
"y",
|
|
1757
|
+
"on",
|
|
1758
|
+
"1",
|
|
1759
|
+
"enable",
|
|
1760
|
+
"enabled"
|
|
1761
|
+
]);
|
|
1762
|
+
var FALSE_WORDS = new Set([
|
|
1763
|
+
"false",
|
|
1764
|
+
"no",
|
|
1765
|
+
"n",
|
|
1766
|
+
"off",
|
|
1767
|
+
"0",
|
|
1768
|
+
"disable",
|
|
1769
|
+
"disabled"
|
|
1770
|
+
]);
|
|
1524
1771
|
// packages/ws/src/close-codes.ts
|
|
1525
1772
|
var GatewayCloseCodes = {
|
|
1526
1773
|
UnknownError: 4000,
|
|
@@ -1595,10 +1842,10 @@ class GuildMember {
|
|
|
1595
1842
|
get permissions() {
|
|
1596
1843
|
if (this.#suppliedPermissions)
|
|
1597
1844
|
return this.#suppliedPermissions;
|
|
1598
|
-
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds) ?? 0n);
|
|
1845
|
+
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, undefined, this.timedOutUntil) ?? 0n);
|
|
1599
1846
|
}
|
|
1600
1847
|
permissionsIn(channelId) {
|
|
1601
|
-
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId);
|
|
1848
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId, this.timedOutUntil);
|
|
1602
1849
|
return computed ? new PermissionsBitField(computed) : null;
|
|
1603
1850
|
}
|
|
1604
1851
|
#action(name) {
|
|
@@ -1661,6 +1908,7 @@ class Role extends BaseStructure {
|
|
|
1661
1908
|
position;
|
|
1662
1909
|
unicodeEmoji;
|
|
1663
1910
|
iconHash;
|
|
1911
|
+
colors;
|
|
1664
1912
|
tags;
|
|
1665
1913
|
constructor(data) {
|
|
1666
1914
|
super(data.id);
|
|
@@ -1674,6 +1922,11 @@ class Role extends BaseStructure {
|
|
|
1674
1922
|
this.mentionable = data.mentionable ?? false;
|
|
1675
1923
|
this.position = data.position ?? 0;
|
|
1676
1924
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
1925
|
+
this.colors = data.colors ? {
|
|
1926
|
+
primary: data.colors.primary_color,
|
|
1927
|
+
secondary: data.colors.secondary_color,
|
|
1928
|
+
tertiary: data.colors.tertiary_color
|
|
1929
|
+
} : null;
|
|
1677
1930
|
this.iconHash = data.icon ?? null;
|
|
1678
1931
|
this.tags = data.tags ?? null;
|
|
1679
1932
|
}
|
|
@@ -1877,6 +2130,117 @@ function createChannel(data, context) {
|
|
|
1877
2130
|
}
|
|
1878
2131
|
// packages/structures/src/interactions.ts
|
|
1879
2132
|
var TOKEN_LIFETIME_MS = 15 * 60000;
|
|
2133
|
+
// packages/structures/src/audit-log.ts
|
|
2134
|
+
function int(value) {
|
|
2135
|
+
return Number(value ?? 0);
|
|
2136
|
+
}
|
|
2137
|
+
function parseInfo(type, options) {
|
|
2138
|
+
if (!options)
|
|
2139
|
+
return;
|
|
2140
|
+
switch (type) {
|
|
2141
|
+
case 13:
|
|
2142
|
+
case 14:
|
|
2143
|
+
case 15:
|
|
2144
|
+
return {
|
|
2145
|
+
id: options.id ?? "",
|
|
2146
|
+
type: int(options.type),
|
|
2147
|
+
roleName: options.role_name
|
|
2148
|
+
};
|
|
2149
|
+
case 21:
|
|
2150
|
+
return {
|
|
2151
|
+
deleteMemberDays: int(options.delete_member_days),
|
|
2152
|
+
membersRemoved: int(options.members_removed)
|
|
2153
|
+
};
|
|
2154
|
+
case 26:
|
|
2155
|
+
case 72:
|
|
2156
|
+
return {
|
|
2157
|
+
channelId: options.channel_id ?? "",
|
|
2158
|
+
count: int(options.count)
|
|
2159
|
+
};
|
|
2160
|
+
case 27:
|
|
2161
|
+
case 73:
|
|
2162
|
+
return { count: int(options.count) };
|
|
2163
|
+
case 74:
|
|
2164
|
+
case 75:
|
|
2165
|
+
return {
|
|
2166
|
+
channelId: options.channel_id ?? "",
|
|
2167
|
+
messageId: options.message_id ?? ""
|
|
2168
|
+
};
|
|
2169
|
+
case 83:
|
|
2170
|
+
case 84:
|
|
2171
|
+
case 85:
|
|
2172
|
+
return { channelId: options.channel_id ?? "" };
|
|
2173
|
+
case 121:
|
|
2174
|
+
return { applicationId: options.app_id ?? "" };
|
|
2175
|
+
case 143:
|
|
2176
|
+
case 144:
|
|
2177
|
+
case 145:
|
|
2178
|
+
return {
|
|
2179
|
+
ruleName: options.auto_moderation_rule_name ?? "",
|
|
2180
|
+
ruleTriggerType: int(options.auto_moderation_rule_trigger_type),
|
|
2181
|
+
channelId: options.channel_id
|
|
2182
|
+
};
|
|
2183
|
+
default:
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
class AuditLogEntry extends BaseStructure {
|
|
2189
|
+
targetId;
|
|
2190
|
+
userId;
|
|
2191
|
+
actionType;
|
|
2192
|
+
changes;
|
|
2193
|
+
options;
|
|
2194
|
+
info;
|
|
2195
|
+
reason;
|
|
2196
|
+
constructor(data) {
|
|
2197
|
+
super(data.id);
|
|
2198
|
+
this.targetId = data.target_id;
|
|
2199
|
+
this.userId = data.user_id;
|
|
2200
|
+
this.actionType = data.action_type;
|
|
2201
|
+
this.info = parseInfo(data.action_type, data.options);
|
|
2202
|
+
this.changes = data.changes ?? [];
|
|
2203
|
+
this.options = data.options ?? null;
|
|
2204
|
+
this.reason = data.reason ?? null;
|
|
2205
|
+
}
|
|
2206
|
+
is(type) {
|
|
2207
|
+
return this.actionType === type;
|
|
2208
|
+
}
|
|
2209
|
+
change(key) {
|
|
2210
|
+
const found = this.changes.find((change) => change.key === key);
|
|
2211
|
+
return found && { old: found.old_value, new: found.new_value };
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
class AuditLog {
|
|
2216
|
+
entries;
|
|
2217
|
+
constructor(data) {
|
|
2218
|
+
this.entries = new Map;
|
|
2219
|
+
for (const entryData of data.audit_log_entries) {
|
|
2220
|
+
this.entries.set(entryData.id, new AuditLogEntry(entryData));
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
filter(query) {
|
|
2224
|
+
const types = query.type === undefined ? undefined : Array.isArray(query.type) ? query.type : [query.type];
|
|
2225
|
+
const since = query.since === undefined ? undefined : new Date(query.since).getTime();
|
|
2226
|
+
const matches = [];
|
|
2227
|
+
for (const entry of this.entries.values()) {
|
|
2228
|
+
if (types && !types.includes(entry.actionType))
|
|
2229
|
+
continue;
|
|
2230
|
+
if (query.targetId !== undefined && entry.targetId !== query.targetId)
|
|
2231
|
+
continue;
|
|
2232
|
+
if (query.userId !== undefined && entry.userId !== query.userId)
|
|
2233
|
+
continue;
|
|
2234
|
+
if (since !== undefined && entry.createdAt.getTime() < since)
|
|
2235
|
+
continue;
|
|
2236
|
+
matches.push(entry);
|
|
2237
|
+
}
|
|
2238
|
+
return matches;
|
|
2239
|
+
}
|
|
2240
|
+
find(query) {
|
|
2241
|
+
return this.filter(query)[0];
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
1880
2244
|
|
|
1881
2245
|
// packages/structures/src/index.ts
|
|
1882
2246
|
var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
|
|
@@ -2065,6 +2429,13 @@ class Message extends BaseStructure {
|
|
|
2065
2429
|
}
|
|
2066
2430
|
|
|
2067
2431
|
// packages/managers/src/message.ts
|
|
2432
|
+
function toAttachments(files) {
|
|
2433
|
+
return files.map((file) => ({
|
|
2434
|
+
name: file.name,
|
|
2435
|
+
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
2436
|
+
contentType: file.contentType
|
|
2437
|
+
}));
|
|
2438
|
+
}
|
|
2068
2439
|
function toRequest(options, allowedMentions) {
|
|
2069
2440
|
const { files, ...body } = options;
|
|
2070
2441
|
if (allowedMentions !== undefined && body.allowed_mentions === undefined)
|
|
@@ -2073,11 +2444,7 @@ function toRequest(options, allowedMentions) {
|
|
|
2073
2444
|
return body;
|
|
2074
2445
|
return {
|
|
2075
2446
|
body,
|
|
2076
|
-
files: files
|
|
2077
|
-
name: file.name,
|
|
2078
|
-
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
2079
|
-
contentType: file.contentType
|
|
2080
|
-
}))
|
|
2447
|
+
files: toAttachments(files)
|
|
2081
2448
|
};
|
|
2082
2449
|
}
|
|
2083
2450
|
|
|
@@ -2151,6 +2518,70 @@ class ThreadManager {
|
|
|
2151
2518
|
});
|
|
2152
2519
|
return createChannel(data, this.#context);
|
|
2153
2520
|
}
|
|
2521
|
+
async create(options) {
|
|
2522
|
+
const data = await this.#rest.post(Routes.channelThreads(this.#channelId), {
|
|
2523
|
+
name: options.name,
|
|
2524
|
+
type: options.type ?? 12,
|
|
2525
|
+
auto_archive_duration: options.autoArchiveDuration,
|
|
2526
|
+
rate_limit_per_user: options.rateLimitPerUser,
|
|
2527
|
+
invitable: options.invitable
|
|
2528
|
+
}, { reason: options.reason });
|
|
2529
|
+
return createChannel(data, this.#context);
|
|
2530
|
+
}
|
|
2531
|
+
async createForumPost(options) {
|
|
2532
|
+
const { message, appliedTags, reason, ...thread } = options;
|
|
2533
|
+
const { files, ...content } = message;
|
|
2534
|
+
const data = await this.#rest.post(Routes.channelThreads(this.#channelId), {
|
|
2535
|
+
name: thread.name,
|
|
2536
|
+
auto_archive_duration: thread.autoArchiveDuration,
|
|
2537
|
+
rate_limit_per_user: thread.rateLimitPerUser,
|
|
2538
|
+
applied_tags: appliedTags,
|
|
2539
|
+
message: content
|
|
2540
|
+
}, { files: files?.length ? toAttachments(files) : undefined, reason });
|
|
2541
|
+
return createChannel(data, this.#context);
|
|
2542
|
+
}
|
|
2543
|
+
async fetchArchived(scope, options = {}) {
|
|
2544
|
+
const route = scope === "public" ? Routes.channelPublicArchivedThreads(this.#channelId) : scope === "private" ? Routes.channelPrivateArchivedThreads(this.#channelId) : Routes.channelJoinedPrivateArchivedThreads(this.#channelId);
|
|
2545
|
+
const params = new URLSearchParams;
|
|
2546
|
+
if (options.before)
|
|
2547
|
+
params.set("before", options.before);
|
|
2548
|
+
if (options.limit !== undefined)
|
|
2549
|
+
params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
|
|
2550
|
+
const query = params.toString();
|
|
2551
|
+
const page = await this.#rest.get(`${route}${query ? `?${query}` : ""}`);
|
|
2552
|
+
return {
|
|
2553
|
+
threads: page.threads.map((thread) => createChannel(thread, this.#context)),
|
|
2554
|
+
members: page.members,
|
|
2555
|
+
hasMore: page.has_more
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
async join(threadId) {
|
|
2559
|
+
await this.#rest.put(Routes.threadMember(threadId, "@me"));
|
|
2560
|
+
}
|
|
2561
|
+
async leave(threadId) {
|
|
2562
|
+
await this.#rest.delete(Routes.threadMember(threadId, "@me"));
|
|
2563
|
+
}
|
|
2564
|
+
async addMember(threadId, userId) {
|
|
2565
|
+
await this.#rest.put(Routes.threadMember(threadId, userId));
|
|
2566
|
+
}
|
|
2567
|
+
async removeMember(threadId, userId) {
|
|
2568
|
+
await this.#rest.delete(Routes.threadMember(threadId, userId));
|
|
2569
|
+
}
|
|
2570
|
+
async fetchMember(threadId, userId, query = {}) {
|
|
2571
|
+
const suffix = query.withMember ? "?with_member=true" : "";
|
|
2572
|
+
return this.#rest.get(`${Routes.threadMember(threadId, userId)}${suffix}`);
|
|
2573
|
+
}
|
|
2574
|
+
async fetchMembers(threadId, options = {}) {
|
|
2575
|
+
const params = new URLSearchParams;
|
|
2576
|
+
if (options.withMember)
|
|
2577
|
+
params.set("with_member", "true");
|
|
2578
|
+
if (options.after)
|
|
2579
|
+
params.set("after", options.after);
|
|
2580
|
+
if (options.limit !== undefined)
|
|
2581
|
+
params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
|
|
2582
|
+
const query = params.toString();
|
|
2583
|
+
return this.#rest.get(`${Routes.threadMembers(threadId)}${query ? `?${query}` : ""}`);
|
|
2584
|
+
}
|
|
2154
2585
|
}
|
|
2155
2586
|
|
|
2156
2587
|
// packages/managers/src/user.ts
|
|
@@ -2168,8 +2599,21 @@ class UserManager extends ResourceManager {
|
|
|
2168
2599
|
const data = await this.#rest.patch("/users/@me", options);
|
|
2169
2600
|
return this.upsert(new User(data));
|
|
2170
2601
|
}
|
|
2602
|
+
async fetchGuilds(options = {}) {
|
|
2603
|
+
const params = new URLSearchParams;
|
|
2604
|
+
if (options.limit !== undefined)
|
|
2605
|
+
params.set("limit", String(Math.min(200, Math.max(1, options.limit))));
|
|
2606
|
+
if (options.before)
|
|
2607
|
+
params.set("before", options.before);
|
|
2608
|
+
if (options.after)
|
|
2609
|
+
params.set("after", options.after);
|
|
2610
|
+
if (options.withCounts)
|
|
2611
|
+
params.set("with_counts", "true");
|
|
2612
|
+
const query = params.toString();
|
|
2613
|
+
return this.#rest.get(`${Routes.userGuilds()}${query ? `?${query}` : ""}`);
|
|
2614
|
+
}
|
|
2171
2615
|
async leaveGuild(guildId) {
|
|
2172
|
-
await this.#rest.delete(
|
|
2616
|
+
await this.#rest.delete(Routes.currentUserGuild(guildId));
|
|
2173
2617
|
}
|
|
2174
2618
|
async createDM(userId) {
|
|
2175
2619
|
return this.#rest.post("/users/@me/channels", {
|
|
@@ -2207,9 +2651,6 @@ class EmojiManager extends Manager {
|
|
|
2207
2651
|
});
|
|
2208
2652
|
this.delete(emojiId);
|
|
2209
2653
|
}
|
|
2210
|
-
deleteEmoji(emojiId) {
|
|
2211
|
-
return this.remove(emojiId);
|
|
2212
|
-
}
|
|
2213
2654
|
upsert(data) {
|
|
2214
2655
|
const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
|
|
2215
2656
|
return this.#merge(key, new Emoji2(data));
|
|
@@ -2390,6 +2831,39 @@ class MonetizationManager extends Manager {
|
|
|
2390
2831
|
}
|
|
2391
2832
|
}
|
|
2392
2833
|
|
|
2834
|
+
class ApplicationEmojiManager extends Manager {
|
|
2835
|
+
#rest;
|
|
2836
|
+
applicationId;
|
|
2837
|
+
constructor(rest, applicationId) {
|
|
2838
|
+
super();
|
|
2839
|
+
this.#rest = rest;
|
|
2840
|
+
this.applicationId = applicationId;
|
|
2841
|
+
}
|
|
2842
|
+
#store(emoji) {
|
|
2843
|
+
if (emoji.id)
|
|
2844
|
+
this.set(emoji.id, emoji);
|
|
2845
|
+
return emoji;
|
|
2846
|
+
}
|
|
2847
|
+
async fetchAll() {
|
|
2848
|
+
const { items } = await this.#rest.get(Routes.applicationEmoji(this.applicationId));
|
|
2849
|
+
this.clear();
|
|
2850
|
+
return items.map((emoji) => this.#store(emoji));
|
|
2851
|
+
}
|
|
2852
|
+
async fetch(emojiId) {
|
|
2853
|
+
return this.#store(await this.#rest.get(Routes.applicationEmoji(this.applicationId, emojiId)));
|
|
2854
|
+
}
|
|
2855
|
+
async create(options) {
|
|
2856
|
+
return this.#store(await this.#rest.post(Routes.applicationEmoji(this.applicationId), options));
|
|
2857
|
+
}
|
|
2858
|
+
async edit(emojiId, options) {
|
|
2859
|
+
return this.#store(await this.#rest.patch(Routes.applicationEmoji(this.applicationId, emojiId), options));
|
|
2860
|
+
}
|
|
2861
|
+
async remove(emojiId) {
|
|
2862
|
+
await this.#rest.delete(Routes.applicationEmoji(this.applicationId, emojiId));
|
|
2863
|
+
this.delete(emojiId);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2393
2867
|
// packages/managers/src/member.ts
|
|
2394
2868
|
class GuildMemberManager extends ResourceManager {
|
|
2395
2869
|
#rest;
|
|
@@ -2403,6 +2877,27 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2403
2877
|
this.#rest = rest;
|
|
2404
2878
|
this.#context = context;
|
|
2405
2879
|
}
|
|
2880
|
+
async search(query, limit = 1) {
|
|
2881
|
+
if (!query.trim())
|
|
2882
|
+
throw new TypeError("A search query is required.");
|
|
2883
|
+
const params = new URLSearchParams({
|
|
2884
|
+
query,
|
|
2885
|
+
limit: String(Math.min(1000, Math.max(1, limit)))
|
|
2886
|
+
});
|
|
2887
|
+
const found = await this.#rest.get(`${Routes.guildMembersSearch(this.guildId)}?${params}`);
|
|
2888
|
+
return found.map((data) => {
|
|
2889
|
+
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
2890
|
+
this.set(member.user.id, member);
|
|
2891
|
+
return member;
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
async editMe(options) {
|
|
2895
|
+
const [payload, reason] = splitReason(options);
|
|
2896
|
+
const data = await this.#rest.patch(Routes.guildMemberMe(this.guildId), payload, { reason });
|
|
2897
|
+
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
2898
|
+
this.set(member.user.id, member);
|
|
2899
|
+
return member;
|
|
2900
|
+
}
|
|
2406
2901
|
async kick(userId, reason) {
|
|
2407
2902
|
await this.#rest.delete(Routes.guildMember(this.guildId, userId), {
|
|
2408
2903
|
reason
|
|
@@ -2418,10 +2913,10 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2418
2913
|
reason
|
|
2419
2914
|
});
|
|
2420
2915
|
}
|
|
2421
|
-
async edit(userId, options
|
|
2916
|
+
async edit(userId, options) {
|
|
2422
2917
|
const [payload, optionsReason] = splitReason(options);
|
|
2423
2918
|
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), payload, {
|
|
2424
|
-
reason: optionsReason
|
|
2919
|
+
reason: optionsReason
|
|
2425
2920
|
});
|
|
2426
2921
|
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
2427
2922
|
this.set(member.user.id, member);
|
|
@@ -2435,7 +2930,10 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2435
2930
|
}
|
|
2436
2931
|
async timeout(userId, milliseconds, reason) {
|
|
2437
2932
|
const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
|
|
2438
|
-
return this.edit(userId, {
|
|
2933
|
+
return this.edit(userId, {
|
|
2934
|
+
communication_disabled_until: timeoutDate,
|
|
2935
|
+
reason
|
|
2936
|
+
});
|
|
2439
2937
|
}
|
|
2440
2938
|
}
|
|
2441
2939
|
|
|
@@ -2458,20 +2956,15 @@ class RoleManager extends ResourceManager {
|
|
|
2458
2956
|
}
|
|
2459
2957
|
async create(options) {
|
|
2460
2958
|
const { reason, ...payload } = options;
|
|
2461
|
-
const data = await this.#rest.post(Routes.guildRoles(this.guildId), {
|
|
2462
|
-
|
|
2463
|
-
permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
|
|
2464
|
-
}, { reason });
|
|
2465
|
-
const role = new Role(data);
|
|
2466
|
-
this.set(role.id, role);
|
|
2467
|
-
return role;
|
|
2959
|
+
const data = await this.#rest.post(Routes.guildRoles(this.guildId), rolePayload(payload), { reason });
|
|
2960
|
+
return this.#store(data);
|
|
2468
2961
|
}
|
|
2469
2962
|
async edit(roleId, options) {
|
|
2470
2963
|
const { reason, ...payload } = options;
|
|
2471
|
-
const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), {
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2964
|
+
const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), rolePayload(payload), { reason });
|
|
2965
|
+
return this.#store(data);
|
|
2966
|
+
}
|
|
2967
|
+
#store(data) {
|
|
2475
2968
|
const role = new Role(data);
|
|
2476
2969
|
this.set(role.id, role);
|
|
2477
2970
|
return role;
|
|
@@ -2490,9 +2983,19 @@ class RoleManager extends ResourceManager {
|
|
|
2490
2983
|
return role;
|
|
2491
2984
|
});
|
|
2492
2985
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
}
|
|
2986
|
+
}
|
|
2987
|
+
function rolePayload(options) {
|
|
2988
|
+
const { permissions, colors, unicodeEmoji, ...rest } = options;
|
|
2989
|
+
return {
|
|
2990
|
+
...rest,
|
|
2991
|
+
permissions: permissions !== undefined ? String(permissions) : undefined,
|
|
2992
|
+
colors: colors && {
|
|
2993
|
+
primary_color: colors.primary,
|
|
2994
|
+
secondary_color: colors.secondary ?? null,
|
|
2995
|
+
tertiary_color: colors.tertiary ?? null
|
|
2996
|
+
},
|
|
2997
|
+
unicode_emoji: unicodeEmoji
|
|
2998
|
+
};
|
|
2496
2999
|
}
|
|
2497
3000
|
|
|
2498
3001
|
// packages/managers/src/guild-resources.ts
|
|
@@ -2532,6 +3035,18 @@ class GuildBanManager extends Manager {
|
|
|
2532
3035
|
async create(userId, options = {}) {
|
|
2533
3036
|
await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
|
|
2534
3037
|
}
|
|
3038
|
+
async bulk(userIds, options = {}) {
|
|
3039
|
+
if (userIds.length < 1 || userIds.length > 200)
|
|
3040
|
+
throw new RangeError("Bulk ban takes 1 to 200 user IDs.");
|
|
3041
|
+
const result = await this.#rest.post(Routes.guildBulkBan(this.guildId), {
|
|
3042
|
+
user_ids: userIds,
|
|
3043
|
+
delete_message_seconds: options.deleteMessageSeconds
|
|
3044
|
+
}, { reason: options.reason });
|
|
3045
|
+
return {
|
|
3046
|
+
banned: result.banned_users ?? [],
|
|
3047
|
+
failed: result.failed_users ?? []
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
2535
3050
|
async remove(userId, reason) {
|
|
2536
3051
|
await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
|
|
2537
3052
|
reason
|
|
@@ -2563,13 +3078,13 @@ class GuildScheduledEventManager extends Manager {
|
|
|
2563
3078
|
}));
|
|
2564
3079
|
return events.map((event) => this.#store(event));
|
|
2565
3080
|
}
|
|
2566
|
-
async create(options
|
|
3081
|
+
async create(options) {
|
|
2567
3082
|
const [payload, optionsReason] = splitReason(options);
|
|
2568
|
-
return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason
|
|
3083
|
+
return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason }));
|
|
2569
3084
|
}
|
|
2570
|
-
async edit(eventId, options
|
|
3085
|
+
async edit(eventId, options) {
|
|
2571
3086
|
const [payload, optionsReason] = splitReason(options);
|
|
2572
|
-
return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason
|
|
3087
|
+
return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason }));
|
|
2573
3088
|
}
|
|
2574
3089
|
async remove(eventId, reason) {
|
|
2575
3090
|
await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId), { reason });
|
|
@@ -2596,20 +3111,20 @@ class StageInstanceManager extends Manager {
|
|
|
2596
3111
|
this.set(stage.channel_id, stage);
|
|
2597
3112
|
return stage;
|
|
2598
3113
|
}
|
|
2599
|
-
async create(channelId, options
|
|
3114
|
+
async create(channelId, options) {
|
|
2600
3115
|
return this.#store(await this.#rest.post(Routes.stageInstances(), {
|
|
2601
3116
|
channel_id: channelId,
|
|
2602
3117
|
topic: options.topic,
|
|
2603
3118
|
privacy_level: options.privacyLevel,
|
|
2604
3119
|
send_start_notification: options.sendStartNotification,
|
|
2605
3120
|
guild_scheduled_event_id: options.guildScheduledEventId
|
|
2606
|
-
}, { reason: options.reason
|
|
3121
|
+
}, { reason: options.reason }));
|
|
2607
3122
|
}
|
|
2608
3123
|
async fetch(channelId) {
|
|
2609
3124
|
return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
|
|
2610
3125
|
}
|
|
2611
|
-
async edit(channelId, options
|
|
2612
|
-
return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason
|
|
3126
|
+
async edit(channelId, options) {
|
|
3127
|
+
return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason }));
|
|
2613
3128
|
}
|
|
2614
3129
|
async remove(channelId, reason) {
|
|
2615
3130
|
await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
|
|
@@ -2639,14 +3154,19 @@ class PermissionOverwriteManager {
|
|
|
2639
3154
|
const touched = (changes.allow ?? 0n) | (changes.deny ?? 0n) | (changes.inherit ?? 0n);
|
|
2640
3155
|
const allow = BigInt(existing?.allow ?? 0) & ~touched | (changes.allow ?? 0n);
|
|
2641
3156
|
const deny = BigInt(existing?.deny ?? 0) & ~touched | (changes.deny ?? 0n);
|
|
2642
|
-
await this.edit(overwriteId, {
|
|
3157
|
+
await this.edit(overwriteId, {
|
|
3158
|
+
type,
|
|
3159
|
+
allow,
|
|
3160
|
+
deny,
|
|
3161
|
+
reason: options.reason
|
|
3162
|
+
});
|
|
2643
3163
|
}
|
|
2644
|
-
async edit(overwriteId, options
|
|
3164
|
+
async edit(overwriteId, options) {
|
|
2645
3165
|
await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
|
|
2646
3166
|
type: options.type,
|
|
2647
3167
|
allow: BigInt(options.allow ?? 0).toString(),
|
|
2648
3168
|
deny: BigInt(options.deny ?? 0).toString()
|
|
2649
|
-
}, { reason: options.reason
|
|
3169
|
+
}, { reason: options.reason });
|
|
2650
3170
|
}
|
|
2651
3171
|
async remove(overwriteId, reason) {
|
|
2652
3172
|
await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
|
|
@@ -2670,6 +3190,7 @@ class GuildManager extends ResourceManager {
|
|
|
2670
3190
|
#soundboard = new Map;
|
|
2671
3191
|
#voiceStates = new Map;
|
|
2672
3192
|
#autoModerationRules = new Map;
|
|
3193
|
+
#presences = new Map;
|
|
2673
3194
|
#invites = new Map;
|
|
2674
3195
|
#context;
|
|
2675
3196
|
attachContext(context) {
|
|
@@ -2730,6 +3251,9 @@ class GuildManager extends ResourceManager {
|
|
|
2730
3251
|
voiceStates(guildId) {
|
|
2731
3252
|
return this.#perGuild(this.#voiceStates, guildId, () => new Manager);
|
|
2732
3253
|
}
|
|
3254
|
+
presences(guildId) {
|
|
3255
|
+
return this.#perGuild(this.#presences, guildId, () => new Manager);
|
|
3256
|
+
}
|
|
2733
3257
|
autoModerationRules(guildId) {
|
|
2734
3258
|
return this.#perGuild(this.#autoModerationRules, guildId, () => new Manager);
|
|
2735
3259
|
}
|
|
@@ -2755,6 +3279,7 @@ class GuildManager extends ResourceManager {
|
|
|
2755
3279
|
this.#stickers.delete(id);
|
|
2756
3280
|
this.#soundboard.delete(id);
|
|
2757
3281
|
this.#voiceStates.delete(id);
|
|
3282
|
+
this.#presences.delete(id);
|
|
2758
3283
|
this.#autoModerationRules.delete(id);
|
|
2759
3284
|
this.#invites.delete(id);
|
|
2760
3285
|
return super.delete(id);
|
|
@@ -2771,12 +3296,35 @@ class GuildManager extends ResourceManager {
|
|
|
2771
3296
|
async remove(id) {
|
|
2772
3297
|
await this.#rest.delete(Routes.guild(id));
|
|
2773
3298
|
}
|
|
2774
|
-
deleteGuild(id) {
|
|
2775
|
-
return this.remove(id);
|
|
2776
|
-
}
|
|
2777
3299
|
async fetchPreview(id) {
|
|
2778
3300
|
return this.#rest.get(Routes.guildPreview(id));
|
|
2779
3301
|
}
|
|
3302
|
+
async fetchWelcomeScreen(id) {
|
|
3303
|
+
return this.#rest.get(Routes.guildWelcomeScreen(id));
|
|
3304
|
+
}
|
|
3305
|
+
async editWelcomeScreen(id, options) {
|
|
3306
|
+
const { reason, welcomeChannels, ...rest } = options;
|
|
3307
|
+
return this.#rest.patch(Routes.guildWelcomeScreen(id), { ...rest, welcome_channels: welcomeChannels }, { reason });
|
|
3308
|
+
}
|
|
3309
|
+
async fetchOnboarding(id) {
|
|
3310
|
+
return this.#rest.get(Routes.guildOnboarding(id));
|
|
3311
|
+
}
|
|
3312
|
+
async editOnboarding(id, options) {
|
|
3313
|
+
const { reason, defaultChannelIds, ...rest } = options;
|
|
3314
|
+
return this.#rest.put(Routes.guildOnboarding(id), { ...rest, default_channel_ids: defaultChannelIds }, { reason });
|
|
3315
|
+
}
|
|
3316
|
+
async editVoiceState(id, userId, options) {
|
|
3317
|
+
await this.#rest.patch(Routes.guildVoiceState(id, userId), {
|
|
3318
|
+
channel_id: options.channelId,
|
|
3319
|
+
suppress: options.suppress,
|
|
3320
|
+
request_to_speak_timestamp: options.requestToSpeakTimestamp
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
async removeIntegration(id, integrationId, reason) {
|
|
3324
|
+
await this.#rest.delete(Routes.guildIntegration(id, integrationId), {
|
|
3325
|
+
reason
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
2780
3328
|
async fetchActiveThreads(id) {
|
|
2781
3329
|
return this.#rest.get(Routes.guildActiveThreads(id));
|
|
2782
3330
|
}
|
|
@@ -2800,6 +3348,9 @@ class GuildManager extends ResourceManager {
|
|
|
2800
3348
|
params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
|
|
2801
3349
|
return this.#rest.get(withQuery3(Routes.guildAuditLog(guildId), params));
|
|
2802
3350
|
}
|
|
3351
|
+
async fetchAuditLogEntries(guildId, options = {}) {
|
|
3352
|
+
return new AuditLog(await this.fetchAuditLog(guildId, options));
|
|
3353
|
+
}
|
|
2803
3354
|
async fetchMembers(guildId, options = {}) {
|
|
2804
3355
|
const params = new URLSearchParams;
|
|
2805
3356
|
if (options.limit !== undefined)
|
|
@@ -3033,9 +3584,6 @@ class ChannelManager extends Manager {
|
|
|
3033
3584
|
await this.#rest.delete(Routes.channel(channelId), { reason });
|
|
3034
3585
|
this.delete(channelId);
|
|
3035
3586
|
}
|
|
3036
|
-
deleteChannel(channelId) {
|
|
3037
|
-
return this.remove(channelId);
|
|
3038
|
-
}
|
|
3039
3587
|
delete(channelId) {
|
|
3040
3588
|
this.#messageManagers.delete(channelId);
|
|
3041
3589
|
return super.delete(channelId);
|
|
@@ -3043,9 +3591,6 @@ class ChannelManager extends Manager {
|
|
|
3043
3591
|
send(channelId, options) {
|
|
3044
3592
|
return this.messages(channelId).send(options);
|
|
3045
3593
|
}
|
|
3046
|
-
sendMessage(channelId, options) {
|
|
3047
|
-
return this.send(channelId, options);
|
|
3048
|
-
}
|
|
3049
3594
|
async fetchMessage(channelId, messageId, options = {}) {
|
|
3050
3595
|
return this.messages(channelId).fetch(messageId);
|
|
3051
3596
|
}
|
|
@@ -3114,7 +3659,7 @@ class ChannelManager extends Manager {
|
|
|
3114
3659
|
}
|
|
3115
3660
|
}
|
|
3116
3661
|
async addReaction(channelId, messageId, emoji) {
|
|
3117
|
-
await this.#rest.put(
|
|
3662
|
+
await this.#rest.put(Routes.messageReactionMe(channelId, messageId, emoji));
|
|
3118
3663
|
}
|
|
3119
3664
|
async fetchReactions(channelId, messageId, emoji, options = {}) {
|
|
3120
3665
|
const params = new URLSearchParams;
|
|
@@ -3127,10 +3672,10 @@ class ChannelManager extends Manager {
|
|
|
3127
3672
|
return data.map((user) => new User(user));
|
|
3128
3673
|
}
|
|
3129
3674
|
async removeOwnReaction(channelId, messageId, emoji) {
|
|
3130
|
-
await this.#rest.delete(
|
|
3675
|
+
await this.#rest.delete(Routes.messageReactionMe(channelId, messageId, emoji));
|
|
3131
3676
|
}
|
|
3132
3677
|
async removeReaction(channelId, messageId, emoji, userId) {
|
|
3133
|
-
await this.#rest.delete(
|
|
3678
|
+
await this.#rest.delete(Routes.messageReactionUser(channelId, messageId, emoji, userId));
|
|
3134
3679
|
}
|
|
3135
3680
|
async removeAllReactions(channelId, messageId) {
|
|
3136
3681
|
await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
|
|
@@ -3139,6 +3684,46 @@ class ChannelManager extends Manager {
|
|
|
3139
3684
|
const data = await this.#rest.get(Routes.channelMessagesPins(channelId));
|
|
3140
3685
|
return data.items.map((item) => this.messages(channelId).upsert(item.message));
|
|
3141
3686
|
}
|
|
3687
|
+
async fetchPins(channelId, options = {}) {
|
|
3688
|
+
const params = new URLSearchParams;
|
|
3689
|
+
if (options.before)
|
|
3690
|
+
params.set("before", options.before);
|
|
3691
|
+
if (options.limit !== undefined)
|
|
3692
|
+
params.set("limit", String(Math.min(50, Math.max(1, options.limit))));
|
|
3693
|
+
const query = params.toString();
|
|
3694
|
+
const data = await this.#rest.get(`${Routes.channelMessagesPins(channelId)}${query ? `?${query}` : ""}`);
|
|
3695
|
+
return {
|
|
3696
|
+
messages: data.items.map((item) => this.messages(channelId).upsert(item.message)),
|
|
3697
|
+
hasMore: data.has_more
|
|
3698
|
+
};
|
|
3699
|
+
}
|
|
3700
|
+
async triggerTyping(channelId) {
|
|
3701
|
+
await this.#rest.post(Routes.channelTyping(channelId));
|
|
3702
|
+
}
|
|
3703
|
+
async createForumTag(channelId, tag, reason) {
|
|
3704
|
+
const tags = await this.#forumTags(channelId);
|
|
3705
|
+
return this.#saveForumTags(channelId, [...tags, tag], reason);
|
|
3706
|
+
}
|
|
3707
|
+
async editForumTag(channelId, tagId, changes, reason) {
|
|
3708
|
+
const tags = await this.#forumTags(channelId);
|
|
3709
|
+
if (!tags.some((tag) => tag.id === tagId))
|
|
3710
|
+
throw new Error(`Channel ${channelId} has no tag ${tagId}.`);
|
|
3711
|
+
return this.#saveForumTags(channelId, tags.map((tag) => tag.id === tagId ? { ...tag, ...changes } : tag), reason);
|
|
3712
|
+
}
|
|
3713
|
+
async removeForumTag(channelId, tagId, reason) {
|
|
3714
|
+
const tags = await this.#forumTags(channelId);
|
|
3715
|
+
if (!tags.some((tag) => tag.id === tagId))
|
|
3716
|
+
throw new Error(`Channel ${channelId} has no tag ${tagId}.`);
|
|
3717
|
+
return this.#saveForumTags(channelId, tags.filter((tag) => tag.id !== tagId), reason);
|
|
3718
|
+
}
|
|
3719
|
+
async#forumTags(channelId) {
|
|
3720
|
+
const channel = await this.#rest.get(Routes.channel(channelId));
|
|
3721
|
+
return channel.available_tags ?? [];
|
|
3722
|
+
}
|
|
3723
|
+
async#saveForumTags(channelId, tags, reason) {
|
|
3724
|
+
const updated = await this.#rest.patch(Routes.channel(channelId), { available_tags: tags }, { reason });
|
|
3725
|
+
return updated.available_tags ?? [];
|
|
3726
|
+
}
|
|
3142
3727
|
async pinMessage(channelId, messageId, reason) {
|
|
3143
3728
|
await this.#rest.put(Routes.channelMessagesPin(channelId, messageId), undefined, { reason });
|
|
3144
3729
|
}
|
|
@@ -3167,9 +3752,6 @@ class ChannelManager extends Manager {
|
|
|
3167
3752
|
hasMore: messages.length === limit
|
|
3168
3753
|
};
|
|
3169
3754
|
}
|
|
3170
|
-
bulkDelete(channelId, messageIds) {
|
|
3171
|
-
return this.bulkDeleteMessages(channelId, messageIds);
|
|
3172
|
-
}
|
|
3173
3755
|
clear() {
|
|
3174
3756
|
this.#messageManagers.clear();
|
|
3175
3757
|
super.clear();
|
|
@@ -3180,6 +3762,7 @@ function isMessageQuery(value) {
|
|
|
3180
3762
|
}
|
|
3181
3763
|
export {
|
|
3182
3764
|
ApplicationCommandManager,
|
|
3765
|
+
ApplicationEmojiManager,
|
|
3183
3766
|
AuditLogEvent,
|
|
3184
3767
|
ResourceManager as CachedManager,
|
|
3185
3768
|
ChannelManager,
|
|
@@ -3202,4 +3785,4 @@ export {
|
|
|
3202
3785
|
toRequest
|
|
3203
3786
|
};
|
|
3204
3787
|
|
|
3205
|
-
//# debugId=
|
|
3788
|
+
//# debugId=857DC05BD7F0D60E64756E2164756E21
|