lunibee 0.2.2 → 0.2.4
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/LICENSE +21 -21
- package/README.md +225 -225
- package/dist/builders/attachment.d.ts +10 -2
- package/dist/builders/commands.d.ts +161 -101
- package/dist/builders/components.d.ts +54 -75
- package/dist/builders/embed.d.ts +68 -35
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +108 -133
- package/dist/builders/index.js.map +8 -8
- package/dist/collection/cache.d.ts +13 -6
- package/dist/collection/index.d.ts +90 -17
- package/dist/collection/index.js +442 -266
- package/dist/collection/index.js.map +4 -4
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +791 -436
- package/dist/core/index.js.map +47 -47
- package/dist/core/permissions.d.ts +9 -5
- 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.js +1010 -679
- package/dist/index.js.map +66 -65
- package/dist/managers/base.d.ts +26 -14
- package/dist/managers/emoji.d.ts +7 -1
- package/dist/managers/guild-resources.d.ts +11 -3
- package/dist/managers/guild.d.ts +13 -5
- package/dist/managers/index.d.ts +28 -14
- package/dist/managers/index.js +580 -340
- package/dist/managers/index.js.map +26 -26
- package/dist/managers/member.d.ts +5 -3
- package/dist/managers/message.d.ts +7 -3
- package/dist/managers/role.d.ts +13 -1
- package/dist/rest/error-codes.d.ts +48 -0
- package/dist/rest/errors.d.ts +14 -6
- package/dist/rest/index.d.ts +25 -12
- package/dist/rest/index.js +105 -18
- package/dist/rest/index.js.map +15 -14
- package/dist/rest/redis.d.ts +1 -1
- package/dist/rest/route.d.ts +8 -4
- package/dist/rest/routes.d.ts +102 -46
- package/dist/rest/transport.d.ts +10 -5
- package/dist/rest/webhook.d.ts +9 -5
- package/dist/sharding/bus.d.ts +34 -17
- package/dist/sharding/index.d.ts +34 -17
- package/dist/sharding/index.js +68 -36
- package/dist/sharding/index.js.map +17 -17
- package/dist/structures/base.d.ts +28 -10
- package/dist/structures/channels.d.ts +28 -14
- package/dist/structures/index.d.ts +6 -6
- package/dist/structures/index.js +81 -99
- package/dist/structures/index.js.map +19 -18
- package/dist/structures/interactions.d.ts +98 -50
- package/dist/structures/resources.d.ts +90 -46
- package/dist/types/gateway.d.ts +1 -1
- package/dist/types/index.d.ts +43 -18
- package/dist/types/index.js +20 -22
- package/dist/types/index.js.map +4 -4
- package/dist/utils/index.js.map +2 -2
- package/dist/voice/index.d.ts +12 -4
- package/dist/voice/index.js +17 -20
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/decoder.d.ts +6 -2
- package/dist/ws/index.d.ts +25 -13
- package/dist/ws/index.js +63 -31
- package/dist/ws/index.js.map +14 -14
- package/dist/ws/protocol.d.ts +10 -2
- package/dist/ws/session.d.ts +14 -4
- package/dist/ws/state.d.ts +22 -11
- package/package.json +16 -15
package/dist/managers/index.js
CHANGED
|
@@ -1,66 +1,36 @@
|
|
|
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
|
-
this.#unlink(node);
|
|
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
|
+
maxSize: options.maxSize,
|
|
7
|
+
slide: options.slide ?? true,
|
|
8
|
+
onEvict: options.onEvict,
|
|
9
|
+
expired: 0,
|
|
10
|
+
evicted: 0,
|
|
11
|
+
entries: new Map,
|
|
12
|
+
oldest: undefined,
|
|
13
|
+
newest: undefined,
|
|
14
|
+
lruSize: 0,
|
|
15
|
+
heap: [],
|
|
16
|
+
armedFor: Infinity
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function peekOf(collection, key) {
|
|
20
|
+
return collection instanceof Map ? Map.prototype.get.call(collection, key) : collection.get(key);
|
|
21
|
+
}
|
|
22
|
+
var mapGet = Map.prototype.get;
|
|
23
|
+
var mapHas = Map.prototype.has;
|
|
24
|
+
function sample(items, amount) {
|
|
25
|
+
if (!Number.isInteger(amount) || amount < 0)
|
|
26
|
+
throw new RangeError("amount must be a non-negative integer.");
|
|
27
|
+
const count = Math.min(amount, items.length);
|
|
28
|
+
for (let i = 0;i < count; i++) {
|
|
29
|
+
const j = i + Math.floor(Math.random() * (items.length - i));
|
|
30
|
+
[items[i], items[j]] = [items[j], items[i]];
|
|
31
|
+
}
|
|
32
|
+
items.length = count;
|
|
33
|
+
return items;
|
|
64
34
|
}
|
|
65
35
|
function assertTTL(ttl) {
|
|
66
36
|
if (ttl !== undefined && (!Number.isFinite(ttl) || ttl <= 0))
|
|
@@ -68,81 +38,90 @@ function assertTTL(ttl) {
|
|
|
68
38
|
}
|
|
69
39
|
|
|
70
40
|
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;
|
|
41
|
+
#policy;
|
|
42
|
+
#hits = 0;
|
|
43
|
+
#misses = 0;
|
|
85
44
|
constructor(entries, options = {}) {
|
|
86
45
|
super();
|
|
87
46
|
assertTTL(options.ttl);
|
|
88
47
|
if (options.maxSize !== undefined && (!Number.isInteger(options.maxSize) || options.maxSize <= 0))
|
|
89
48
|
throw new RangeError("maxSize must be a positive integer.");
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.#onEvict = options.onEvict;
|
|
49
|
+
if (options.ttl !== undefined || options.maxSize !== undefined || options.slide !== undefined || options.onEvict !== undefined)
|
|
50
|
+
this.#policy = newPolicy(options);
|
|
93
51
|
if (entries)
|
|
94
52
|
for (const [key, value] of entries)
|
|
95
53
|
this.set(key, value);
|
|
96
54
|
}
|
|
97
55
|
set(key, value, ttl) {
|
|
56
|
+
if (ttl === undefined && this.#policy === undefined)
|
|
57
|
+
return super.set(key, value);
|
|
98
58
|
assertTTL(ttl);
|
|
99
|
-
const window = ttl ?? this.#ttl;
|
|
100
|
-
if (this.#maxSize !== undefined) {
|
|
101
|
-
this.#lru.touch(key);
|
|
102
|
-
}
|
|
103
|
-
super.set(key, value);
|
|
59
|
+
const window = ttl ?? this.#policy?.ttl;
|
|
104
60
|
if (window !== undefined)
|
|
105
|
-
this.#
|
|
106
|
-
|
|
107
|
-
|
|
61
|
+
this.#policy ??= newPolicy();
|
|
62
|
+
if (!this.#policy)
|
|
63
|
+
return super.set(key, value);
|
|
64
|
+
const before = super.size;
|
|
65
|
+
super.set(key, value);
|
|
66
|
+
this.#track(key, value, window, super.size !== before);
|
|
108
67
|
this.#enforceCap();
|
|
109
68
|
return this;
|
|
110
69
|
}
|
|
111
70
|
setWithoutTTL(key, value) {
|
|
112
|
-
if (this.#
|
|
113
|
-
this.#
|
|
114
|
-
if (this.#lru.size > 0)
|
|
115
|
-
this.#lru.delete(key);
|
|
71
|
+
if (this.#policy)
|
|
72
|
+
this.#forget(key);
|
|
116
73
|
super.set(key, value);
|
|
117
74
|
return this;
|
|
118
75
|
}
|
|
119
76
|
get(key) {
|
|
120
|
-
|
|
121
|
-
|
|
77
|
+
const policy = this.#policy;
|
|
78
|
+
const entry = policy?.entries.get(key);
|
|
79
|
+
if (entry === undefined) {
|
|
80
|
+
const value = mapGet.call(this, key);
|
|
81
|
+
if (value !== undefined || mapHas.call(this, key)) {
|
|
82
|
+
this.#hits++;
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
this.#misses++;
|
|
122
86
|
return;
|
|
123
87
|
}
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
88
|
+
const timed = entry.window !== 0;
|
|
89
|
+
const now = timed ? Date.now() : 0;
|
|
90
|
+
if (timed && entry.deadline <= now) {
|
|
91
|
+
this.#expire(entry);
|
|
92
|
+
this.#misses++;
|
|
127
93
|
return;
|
|
128
94
|
}
|
|
129
|
-
this.#
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return value;
|
|
95
|
+
this.#hits++;
|
|
96
|
+
if (timed && policy.slide)
|
|
97
|
+
entry.deadline = now + entry.window;
|
|
98
|
+
if (entry.inLru)
|
|
99
|
+
this.#promote(policy, entry);
|
|
100
|
+
return entry.value;
|
|
101
|
+
}
|
|
102
|
+
ensure(key, factory, ttl) {
|
|
103
|
+
const existing = this.get(key);
|
|
104
|
+
if (existing !== undefined || super.has(key))
|
|
105
|
+
return existing;
|
|
106
|
+
const created = factory(key, this);
|
|
107
|
+
this.set(key, created, ttl);
|
|
108
|
+
return created;
|
|
135
109
|
}
|
|
136
110
|
peek(key) {
|
|
137
111
|
if (!this.#expireIfDue(key) && super.has(key)) {
|
|
138
|
-
this.#
|
|
112
|
+
this.#hits++;
|
|
139
113
|
return super.get(key);
|
|
140
114
|
}
|
|
141
|
-
this.#
|
|
115
|
+
this.#misses++;
|
|
142
116
|
return;
|
|
143
117
|
}
|
|
144
118
|
get stats() {
|
|
145
|
-
return {
|
|
119
|
+
return {
|
|
120
|
+
hits: this.#hits,
|
|
121
|
+
misses: this.#misses,
|
|
122
|
+
expired: this.#policy?.expired ?? 0,
|
|
123
|
+
evicted: this.#policy?.evicted ?? 0
|
|
124
|
+
};
|
|
146
125
|
}
|
|
147
126
|
has(key) {
|
|
148
127
|
return !this.#expireIfDue(key) && super.has(key);
|
|
@@ -150,19 +129,23 @@ class Collection extends Map {
|
|
|
150
129
|
delete(key) {
|
|
151
130
|
if (this.#expireIfDue(key))
|
|
152
131
|
return false;
|
|
153
|
-
this.#
|
|
154
|
-
|
|
132
|
+
if (this.#policy)
|
|
133
|
+
this.#forget(key);
|
|
155
134
|
return super.delete(key);
|
|
156
135
|
}
|
|
157
136
|
clear() {
|
|
158
137
|
super.clear();
|
|
159
|
-
this.#
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
138
|
+
const policy = this.#policy;
|
|
139
|
+
if (!policy)
|
|
140
|
+
return;
|
|
141
|
+
policy.entries.clear();
|
|
142
|
+
policy.oldest = policy.newest = undefined;
|
|
143
|
+
policy.lruSize = 0;
|
|
144
|
+
policy.heap.length = 0;
|
|
145
|
+
if (policy.timer)
|
|
146
|
+
clearTimeout(policy.timer);
|
|
147
|
+
policy.timer = undefined;
|
|
148
|
+
policy.armedFor = Infinity;
|
|
166
149
|
}
|
|
167
150
|
get size() {
|
|
168
151
|
this.purge();
|
|
@@ -190,11 +173,11 @@ class Collection extends Map {
|
|
|
190
173
|
ttlRemaining(key) {
|
|
191
174
|
if (this.#expireIfDue(key))
|
|
192
175
|
return;
|
|
193
|
-
const
|
|
194
|
-
return
|
|
176
|
+
const entry = this.#policy?.entries.get(key);
|
|
177
|
+
return entry && entry.window !== 0 ? Math.max(0, entry.deadline - Date.now()) : undefined;
|
|
195
178
|
}
|
|
196
179
|
purge() {
|
|
197
|
-
if (this.#
|
|
180
|
+
if (!this.#policy || this.#policy.heap.length === 0)
|
|
198
181
|
return 0;
|
|
199
182
|
const now = Date.now();
|
|
200
183
|
let removed = 0;
|
|
@@ -205,133 +188,255 @@ class Collection extends Map {
|
|
|
205
188
|
this.#remove(due.key);
|
|
206
189
|
removed++;
|
|
207
190
|
}
|
|
208
|
-
this.#
|
|
191
|
+
this.#policy.expired += removed;
|
|
209
192
|
this.#rearm();
|
|
210
193
|
for (const [key, value] of dropped)
|
|
211
194
|
this.#notify(key, value, "expired");
|
|
212
195
|
return removed;
|
|
213
196
|
}
|
|
214
197
|
#expireIfDue(key) {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
198
|
+
const entry = this.#policy?.entries.get(key);
|
|
199
|
+
if (!entry || entry.window === 0 || entry.deadline > Date.now())
|
|
217
200
|
return false;
|
|
218
|
-
|
|
219
|
-
this.#remove(key);
|
|
220
|
-
this.#stats.expired++;
|
|
221
|
-
this.#notify(key, value, "expired");
|
|
201
|
+
this.#expire(entry);
|
|
222
202
|
return true;
|
|
223
203
|
}
|
|
204
|
+
#expire(entry) {
|
|
205
|
+
const value = super.get(entry.key);
|
|
206
|
+
this.#remove(entry.key);
|
|
207
|
+
this.#policy.expired++;
|
|
208
|
+
this.#notify(entry.key, value, "expired");
|
|
209
|
+
}
|
|
224
210
|
#remove(key) {
|
|
225
|
-
this.#
|
|
226
|
-
this.#lru.delete(key);
|
|
211
|
+
this.#forget(key);
|
|
227
212
|
super.delete(key);
|
|
228
213
|
}
|
|
214
|
+
#forget(key) {
|
|
215
|
+
const policy = this.#policy;
|
|
216
|
+
const entry = policy.entries.get(key);
|
|
217
|
+
if (!entry)
|
|
218
|
+
return;
|
|
219
|
+
if (entry.inLru)
|
|
220
|
+
this.#unlink(policy, entry);
|
|
221
|
+
policy.entries.delete(key);
|
|
222
|
+
}
|
|
223
|
+
#track(key, value, window, isNew) {
|
|
224
|
+
const policy = this.#policy;
|
|
225
|
+
const lru = policy.maxSize !== undefined;
|
|
226
|
+
let entry = isNew ? undefined : policy.entries.get(key);
|
|
227
|
+
if (entry)
|
|
228
|
+
entry.value = value;
|
|
229
|
+
if (window === undefined) {
|
|
230
|
+
if (entry && entry.window !== 0) {
|
|
231
|
+
if (lru)
|
|
232
|
+
entry = this.#replace(policy, entry, 0, 0);
|
|
233
|
+
else {
|
|
234
|
+
this.#forget(key);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!entry && lru) {
|
|
239
|
+
entry = this.#create(key, value, 0, 0);
|
|
240
|
+
policy.entries.set(key, entry);
|
|
241
|
+
}
|
|
242
|
+
if (entry)
|
|
243
|
+
this.#promote(policy, entry);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const deadline = Date.now() + window;
|
|
247
|
+
if (entry && entry.window !== 0) {
|
|
248
|
+
entry.deadline = deadline;
|
|
249
|
+
entry.window = window;
|
|
250
|
+
if (deadline < entry.filed)
|
|
251
|
+
entry = this.#replace(policy, entry, window, deadline);
|
|
252
|
+
else {
|
|
253
|
+
if (entry.inLru)
|
|
254
|
+
this.#promote(policy, entry);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
} else if (entry) {
|
|
258
|
+
entry.window = window;
|
|
259
|
+
entry.deadline = entry.filed = deadline;
|
|
260
|
+
} else {
|
|
261
|
+
entry = this.#create(key, value, window, deadline);
|
|
262
|
+
policy.entries.set(key, entry);
|
|
263
|
+
}
|
|
264
|
+
if (lru)
|
|
265
|
+
this.#promote(policy, entry);
|
|
266
|
+
this.#heapPush(entry);
|
|
267
|
+
if (policy.heap.length > 2 * policy.entries.size + 8)
|
|
268
|
+
this.#compact();
|
|
269
|
+
if (policy.timer === undefined || deadline < policy.armedFor)
|
|
270
|
+
this.#rearm();
|
|
271
|
+
}
|
|
272
|
+
#create(key, value, window, deadline) {
|
|
273
|
+
return {
|
|
274
|
+
key,
|
|
275
|
+
value,
|
|
276
|
+
older: undefined,
|
|
277
|
+
newer: undefined,
|
|
278
|
+
inLru: false,
|
|
279
|
+
window,
|
|
280
|
+
deadline,
|
|
281
|
+
filed: deadline
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
#replace(policy, old, window, deadline) {
|
|
285
|
+
const entry = {
|
|
286
|
+
...old,
|
|
287
|
+
window,
|
|
288
|
+
deadline,
|
|
289
|
+
filed: deadline
|
|
290
|
+
};
|
|
291
|
+
if (old.inLru) {
|
|
292
|
+
if (old.older)
|
|
293
|
+
old.older.newer = entry;
|
|
294
|
+
else
|
|
295
|
+
policy.oldest = entry;
|
|
296
|
+
if (old.newer)
|
|
297
|
+
old.newer.older = entry;
|
|
298
|
+
else
|
|
299
|
+
policy.newest = entry;
|
|
300
|
+
}
|
|
301
|
+
policy.entries.set(old.key, entry);
|
|
302
|
+
return entry;
|
|
303
|
+
}
|
|
304
|
+
#promote(policy, entry) {
|
|
305
|
+
if (entry === policy.newest)
|
|
306
|
+
return;
|
|
307
|
+
if (entry.inLru)
|
|
308
|
+
this.#unlink(policy, entry, true);
|
|
309
|
+
else {
|
|
310
|
+
entry.inLru = true;
|
|
311
|
+
policy.lruSize++;
|
|
312
|
+
}
|
|
313
|
+
entry.older = policy.newest;
|
|
314
|
+
entry.newer = undefined;
|
|
315
|
+
if (policy.newest)
|
|
316
|
+
policy.newest.newer = entry;
|
|
317
|
+
else
|
|
318
|
+
policy.oldest = entry;
|
|
319
|
+
policy.newest = entry;
|
|
320
|
+
}
|
|
321
|
+
#unlink(policy, entry, keepCount = false) {
|
|
322
|
+
if (entry.older)
|
|
323
|
+
entry.older.newer = entry.newer;
|
|
324
|
+
else
|
|
325
|
+
policy.oldest = entry.newer;
|
|
326
|
+
if (entry.newer)
|
|
327
|
+
entry.newer.older = entry.older;
|
|
328
|
+
else
|
|
329
|
+
policy.newest = entry.older;
|
|
330
|
+
entry.older = entry.newer = undefined;
|
|
331
|
+
if (!keepCount) {
|
|
332
|
+
entry.inLru = false;
|
|
333
|
+
policy.lruSize--;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
#derived() {
|
|
337
|
+
const Species = this.constructor[Symbol.species] ?? Collection;
|
|
338
|
+
return new Species;
|
|
339
|
+
}
|
|
229
340
|
#notify(key, value, reason) {
|
|
230
|
-
|
|
341
|
+
const onEvict = this.#policy?.onEvict;
|
|
342
|
+
if (!onEvict)
|
|
231
343
|
return;
|
|
232
344
|
try {
|
|
233
|
-
|
|
345
|
+
onEvict(key, value, reason);
|
|
234
346
|
} catch {}
|
|
235
347
|
}
|
|
236
348
|
#enforceCap() {
|
|
237
|
-
|
|
349
|
+
const policy = this.#policy;
|
|
350
|
+
const max = policy.maxSize;
|
|
351
|
+
if (max === undefined)
|
|
238
352
|
return;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.#
|
|
353
|
+
if (policy.lruSize > max && policy.heap.length > 0 && policy.heap[0].filed <= Date.now())
|
|
354
|
+
this.purge();
|
|
355
|
+
while (policy.lruSize > max) {
|
|
356
|
+
const oldest = policy.oldest;
|
|
357
|
+
const value = policy.onEvict ? super.get(oldest.key) : undefined;
|
|
358
|
+
this.#unlink(policy, oldest);
|
|
359
|
+
policy.entries.delete(oldest.key);
|
|
360
|
+
super.delete(oldest.key);
|
|
361
|
+
policy.evicted++;
|
|
362
|
+
this.#notify(oldest.key, value, "evicted");
|
|
245
363
|
}
|
|
246
364
|
}
|
|
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
365
|
#nextDeadline() {
|
|
366
|
+
const policy = this.#policy;
|
|
264
367
|
for (;; ) {
|
|
265
|
-
const top =
|
|
368
|
+
const top = policy.heap[0];
|
|
266
369
|
if (top === undefined)
|
|
267
370
|
return Infinity;
|
|
268
|
-
|
|
269
|
-
if (!expiry || expiry.filed !== top.deadline) {
|
|
371
|
+
if (policy.entries.get(top.key) !== top) {
|
|
270
372
|
this.#heapPop();
|
|
271
373
|
continue;
|
|
272
374
|
}
|
|
273
|
-
if (
|
|
274
|
-
return top.
|
|
375
|
+
if (top.deadline === top.filed)
|
|
376
|
+
return top.filed;
|
|
275
377
|
this.#heapPop();
|
|
276
|
-
|
|
277
|
-
this.#heapPush(
|
|
378
|
+
top.filed = top.deadline;
|
|
379
|
+
this.#heapPush(top);
|
|
278
380
|
}
|
|
279
381
|
}
|
|
280
382
|
#compact() {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
383
|
+
const policy = this.#policy;
|
|
384
|
+
const live = policy.heap.filter((entry) => policy.entries.get(entry.key) === entry);
|
|
385
|
+
policy.heap.length = 0;
|
|
386
|
+
for (const entry of live)
|
|
387
|
+
this.#heapPush(entry);
|
|
285
388
|
}
|
|
286
389
|
#rearm() {
|
|
390
|
+
const p = this.#policy;
|
|
287
391
|
const deadline = this.#nextDeadline();
|
|
288
|
-
if (
|
|
392
|
+
if (p.timer !== undefined && deadline >= p.armedFor)
|
|
289
393
|
return;
|
|
290
|
-
if (
|
|
291
|
-
clearTimeout(
|
|
292
|
-
|
|
293
|
-
|
|
394
|
+
if (p.timer)
|
|
395
|
+
clearTimeout(p.timer);
|
|
396
|
+
p.timer = undefined;
|
|
397
|
+
p.armedFor = deadline;
|
|
294
398
|
if (deadline === Infinity)
|
|
295
399
|
return;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
400
|
+
p.timer = setTimeout(() => {
|
|
401
|
+
p.timer = undefined;
|
|
402
|
+
p.armedFor = Infinity;
|
|
299
403
|
this.purge();
|
|
300
404
|
}, Math.max(0, deadline - Date.now()));
|
|
301
|
-
|
|
405
|
+
p.timer.unref?.();
|
|
302
406
|
}
|
|
303
|
-
#heapPush(
|
|
304
|
-
const heap = this.#heap;
|
|
305
|
-
heap.
|
|
306
|
-
|
|
407
|
+
#heapPush(entry) {
|
|
408
|
+
const heap = this.#policy.heap;
|
|
409
|
+
let i = heap.length;
|
|
410
|
+
heap.push(entry);
|
|
307
411
|
while (i > 0) {
|
|
308
412
|
const parent = i - 1 >> 1;
|
|
309
|
-
|
|
413
|
+
const above = heap[parent];
|
|
414
|
+
if (above.filed <= entry.filed)
|
|
310
415
|
break;
|
|
311
|
-
|
|
416
|
+
heap[i] = above;
|
|
312
417
|
i = parent;
|
|
313
418
|
}
|
|
419
|
+
heap[i] = entry;
|
|
314
420
|
}
|
|
315
421
|
#heapPop() {
|
|
316
|
-
const heap = this.#heap;
|
|
422
|
+
const heap = this.#policy.heap;
|
|
317
423
|
const top = heap[0];
|
|
318
424
|
const last = heap.pop();
|
|
319
425
|
if (top === undefined || heap.length === 0)
|
|
320
426
|
return top;
|
|
321
|
-
|
|
322
|
-
for (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
let smallest = i;
|
|
326
|
-
if (left < heap.length && heap[left].deadline < heap[smallest].deadline)
|
|
327
|
-
smallest = left;
|
|
328
|
-
if (right < heap.length && heap[right].deadline < heap[smallest].deadline)
|
|
329
|
-
smallest = right;
|
|
330
|
-
if (smallest === i)
|
|
427
|
+
let i = 0;
|
|
428
|
+
for (;; ) {
|
|
429
|
+
let child = 2 * i + 1;
|
|
430
|
+
if (child >= heap.length)
|
|
331
431
|
break;
|
|
332
|
-
|
|
333
|
-
|
|
432
|
+
if (child + 1 < heap.length && heap[child + 1].filed < heap[child].filed)
|
|
433
|
+
child++;
|
|
434
|
+
if (heap[child].filed >= last.filed)
|
|
435
|
+
break;
|
|
436
|
+
heap[i] = heap[child];
|
|
437
|
+
i = child;
|
|
334
438
|
}
|
|
439
|
+
heap[i] = last;
|
|
335
440
|
return top;
|
|
336
441
|
}
|
|
337
442
|
first() {
|
|
@@ -363,8 +468,26 @@ class Collection extends Map {
|
|
|
363
468
|
}
|
|
364
469
|
return;
|
|
365
470
|
}
|
|
471
|
+
findLast(predicate) {
|
|
472
|
+
const entries = [...this];
|
|
473
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
474
|
+
const [key, value] = entries[i];
|
|
475
|
+
if (predicate(value, key, this))
|
|
476
|
+
return value;
|
|
477
|
+
}
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
findLastKey(predicate) {
|
|
481
|
+
const entries = [...this];
|
|
482
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
483
|
+
const [key, value] = entries[i];
|
|
484
|
+
if (predicate(value, key, this))
|
|
485
|
+
return key;
|
|
486
|
+
}
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
366
489
|
filter(predicate) {
|
|
367
|
-
const result =
|
|
490
|
+
const result = this.#derived();
|
|
368
491
|
for (const [key, value] of this) {
|
|
369
492
|
if (predicate(value, key, this))
|
|
370
493
|
result.set(key, value);
|
|
@@ -408,7 +531,7 @@ class Collection extends Map {
|
|
|
408
531
|
return [...this.entries()];
|
|
409
532
|
}
|
|
410
533
|
clone() {
|
|
411
|
-
const copy =
|
|
534
|
+
const copy = this.#derived();
|
|
412
535
|
for (const [key, value] of this)
|
|
413
536
|
copy.set(key, value);
|
|
414
537
|
return copy;
|
|
@@ -463,7 +586,7 @@ class Collection extends Map {
|
|
|
463
586
|
return result;
|
|
464
587
|
}
|
|
465
588
|
intersection(other) {
|
|
466
|
-
const result =
|
|
589
|
+
const result = this.#derived();
|
|
467
590
|
for (const [key, value] of this) {
|
|
468
591
|
if (other.has(key))
|
|
469
592
|
result.set(key, value);
|
|
@@ -471,7 +594,7 @@ class Collection extends Map {
|
|
|
471
594
|
return result;
|
|
472
595
|
}
|
|
473
596
|
difference(other) {
|
|
474
|
-
const result =
|
|
597
|
+
const result = this.#derived();
|
|
475
598
|
for (const [key, value] of this) {
|
|
476
599
|
if (!other.has(key))
|
|
477
600
|
result.set(key, value);
|
|
@@ -479,8 +602,8 @@ class Collection extends Map {
|
|
|
479
602
|
return result;
|
|
480
603
|
}
|
|
481
604
|
partition(predicate) {
|
|
482
|
-
const pass =
|
|
483
|
-
const fail =
|
|
605
|
+
const pass = this.#derived();
|
|
606
|
+
const fail = this.#derived();
|
|
484
607
|
for (const [key, value] of this) {
|
|
485
608
|
if (predicate(value, key, this))
|
|
486
609
|
pass.set(key, value);
|
|
@@ -489,6 +612,81 @@ class Collection extends Map {
|
|
|
489
612
|
}
|
|
490
613
|
return [pass, fail];
|
|
491
614
|
}
|
|
615
|
+
symmetricDifference(other) {
|
|
616
|
+
const result = this.#derived();
|
|
617
|
+
for (const [key, value] of this)
|
|
618
|
+
if (!other.has(key))
|
|
619
|
+
result.set(key, value);
|
|
620
|
+
for (const [key, value] of other)
|
|
621
|
+
if (!this.has(key))
|
|
622
|
+
result.set(key, value);
|
|
623
|
+
return result;
|
|
624
|
+
}
|
|
625
|
+
concat(...collections) {
|
|
626
|
+
const result = this.clone();
|
|
627
|
+
for (const collection of collections)
|
|
628
|
+
for (const [key, value] of collection)
|
|
629
|
+
result.set(key, value);
|
|
630
|
+
return result;
|
|
631
|
+
}
|
|
632
|
+
merge(other, whenInSelf, whenInOther, whenInBoth) {
|
|
633
|
+
const result = this.#derived();
|
|
634
|
+
const decide = (key, kept) => {
|
|
635
|
+
if (kept.keep)
|
|
636
|
+
result.set(key, kept.value);
|
|
637
|
+
};
|
|
638
|
+
for (const [key, value] of this) {
|
|
639
|
+
decide(key, other.has(key) ? whenInBoth(value, peekOf(other, key), key) : whenInSelf(value, key));
|
|
640
|
+
}
|
|
641
|
+
for (const [key, value] of other)
|
|
642
|
+
if (!this.has(key))
|
|
643
|
+
decide(key, whenInOther(value, key));
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
equals(other) {
|
|
647
|
+
if (!other)
|
|
648
|
+
return false;
|
|
649
|
+
if (other === this)
|
|
650
|
+
return true;
|
|
651
|
+
if (this.size !== other.size)
|
|
652
|
+
return false;
|
|
653
|
+
for (const [key, value] of this) {
|
|
654
|
+
if (!other.has(key))
|
|
655
|
+
return false;
|
|
656
|
+
if (value !== peekOf(other, key))
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
mapValues(transform) {
|
|
662
|
+
const result = this.#derived();
|
|
663
|
+
for (const [key, value] of this)
|
|
664
|
+
result.set(key, transform(value, key, this));
|
|
665
|
+
return result;
|
|
666
|
+
}
|
|
667
|
+
toReversed() {
|
|
668
|
+
const result = this.#derived();
|
|
669
|
+
const entries = [...this];
|
|
670
|
+
for (let i = entries.length - 1;i >= 0; i--)
|
|
671
|
+
result.set(entries[i][0], entries[i][1]);
|
|
672
|
+
return result;
|
|
673
|
+
}
|
|
674
|
+
toSorted(comparator) {
|
|
675
|
+
return this.sorted(comparator);
|
|
676
|
+
}
|
|
677
|
+
static groupBy(items, keySelector) {
|
|
678
|
+
const groups = new Collection;
|
|
679
|
+
let index = 0;
|
|
680
|
+
for (const item of items)
|
|
681
|
+
groups.ensure(keySelector(item, index++), () => []).push(item);
|
|
682
|
+
return groups;
|
|
683
|
+
}
|
|
684
|
+
static combineEntries(entries, combine) {
|
|
685
|
+
const result = new Collection;
|
|
686
|
+
for (const [key, value] of entries)
|
|
687
|
+
result.set(key, result.has(key) ? combine(result.get(key), value, key) : value);
|
|
688
|
+
return result;
|
|
689
|
+
}
|
|
492
690
|
tap(fn) {
|
|
493
691
|
fn(this);
|
|
494
692
|
return this;
|
|
@@ -507,6 +705,13 @@ class Collection extends Map {
|
|
|
507
705
|
acc = fn(acc, value, key, this);
|
|
508
706
|
return acc;
|
|
509
707
|
}
|
|
708
|
+
reduceRight(fn, initialValue) {
|
|
709
|
+
const entries = [...this];
|
|
710
|
+
let acc = initialValue;
|
|
711
|
+
for (let i = entries.length - 1;i >= 0; i--)
|
|
712
|
+
acc = fn(acc, entries[i][1], entries[i][0], this);
|
|
713
|
+
return acc;
|
|
714
|
+
}
|
|
510
715
|
sorted(comparator) {
|
|
511
716
|
const decorated = [...this.entries()].map((entry, index) => ({
|
|
512
717
|
entry,
|
|
@@ -517,22 +722,34 @@ class Collection extends Map {
|
|
|
517
722
|
const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
|
|
518
723
|
return comparison !== 0 ? comparison : x.index - y.index;
|
|
519
724
|
});
|
|
520
|
-
const result =
|
|
725
|
+
const result = this.#derived();
|
|
521
726
|
for (const { entry } of decorated)
|
|
522
727
|
result.set(entry[0], entry[1]);
|
|
523
728
|
return result;
|
|
524
729
|
}
|
|
525
|
-
random() {
|
|
526
|
-
|
|
527
|
-
|
|
730
|
+
random(amount) {
|
|
731
|
+
if (amount !== undefined)
|
|
732
|
+
return sample([...this.values()], amount);
|
|
733
|
+
const size = this.size;
|
|
734
|
+
if (size === 0)
|
|
528
735
|
return;
|
|
529
|
-
|
|
736
|
+
let index = Math.floor(Math.random() * size);
|
|
737
|
+
for (const value of this.values())
|
|
738
|
+
if (index-- === 0)
|
|
739
|
+
return value;
|
|
740
|
+
return;
|
|
530
741
|
}
|
|
531
|
-
randomKey() {
|
|
532
|
-
|
|
533
|
-
|
|
742
|
+
randomKey(amount) {
|
|
743
|
+
if (amount !== undefined)
|
|
744
|
+
return sample([...this.keys()], amount);
|
|
745
|
+
const size = this.size;
|
|
746
|
+
if (size === 0)
|
|
534
747
|
return;
|
|
535
|
-
|
|
748
|
+
let index = Math.floor(Math.random() * size);
|
|
749
|
+
for (const key of this.keys())
|
|
750
|
+
if (index-- === 0)
|
|
751
|
+
return key;
|
|
752
|
+
return;
|
|
536
753
|
}
|
|
537
754
|
at(index) {
|
|
538
755
|
const arr = [...this.values()];
|
|
@@ -550,6 +767,11 @@ class Collection extends Map {
|
|
|
550
767
|
}
|
|
551
768
|
|
|
552
769
|
// packages/managers/src/base.ts
|
|
770
|
+
function splitReason(options) {
|
|
771
|
+
const { reason, ...payload } = options;
|
|
772
|
+
return [payload, reason];
|
|
773
|
+
}
|
|
774
|
+
|
|
553
775
|
class Manager {
|
|
554
776
|
cache = new Collection;
|
|
555
777
|
get(id) {
|
|
@@ -651,12 +873,15 @@ class ResourceManager extends Manager {
|
|
|
651
873
|
// packages/rest/package.json
|
|
652
874
|
var package_default = {
|
|
653
875
|
name: "@lunibee/rest",
|
|
654
|
-
version: "0.2.
|
|
876
|
+
version: "0.2.4",
|
|
655
877
|
type: "module",
|
|
656
878
|
module: "./src/index.ts",
|
|
657
879
|
types: "./src/index.ts",
|
|
658
880
|
exports: {
|
|
659
881
|
".": "./src/index.ts"
|
|
882
|
+
},
|
|
883
|
+
dependencies: {
|
|
884
|
+
"@lunibee/types": "workspace:*"
|
|
660
885
|
}
|
|
661
886
|
};
|
|
662
887
|
|
|
@@ -665,6 +890,9 @@ var Routes = {
|
|
|
665
890
|
user: () => "/users/@me",
|
|
666
891
|
userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
|
|
667
892
|
guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
|
|
893
|
+
currentUserGuild: (guildId) => `/users/@me/guilds/${snowflake(guildId, "Guild ID")}`,
|
|
894
|
+
sticker: (stickerId) => `/stickers/${snowflake(stickerId, "Sticker ID")}`,
|
|
895
|
+
messageReactionUser: (channelId, messageId, emoji, userId) => `${Routes.messageReactions(channelId, messageId, emoji)}/${snowflake(userId, "User ID")}`,
|
|
668
896
|
guildPreview: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/preview`,
|
|
669
897
|
guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
|
|
670
898
|
guildWebhooks: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/webhooks`,
|
|
@@ -682,6 +910,8 @@ var Routes = {
|
|
|
682
910
|
crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
|
|
683
911
|
messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
|
|
684
912
|
messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
|
|
913
|
+
channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
|
|
914
|
+
channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
|
|
685
915
|
channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
|
|
686
916
|
channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
|
|
687
917
|
messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
|
|
@@ -744,7 +974,7 @@ function snowflake(value, field) {
|
|
|
744
974
|
// packages/rest/src/index.ts
|
|
745
975
|
var LIBRARY_VERSION = package_default.version;
|
|
746
976
|
var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
|
|
747
|
-
var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${
|
|
977
|
+
var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${LIBRARY_VERSION})`;
|
|
748
978
|
var REQUEST_DATA_KEYS = new Set([
|
|
749
979
|
"body",
|
|
750
980
|
"files",
|
|
@@ -775,7 +1005,7 @@ function cdnURL(path, hash, options = {}) {
|
|
|
775
1005
|
const isAnimated = hash.startsWith("a_") && !options.forceStatic;
|
|
776
1006
|
const ext = options.extension ?? (isAnimated ? "gif" : "png");
|
|
777
1007
|
const size = options.size ? `?size=${options.size}` : "";
|
|
778
|
-
return `${CDN_BASE}${path}/${hash}.${ext}${size}`;
|
|
1008
|
+
return `${CDN_BASE}${path}/${encodeURIComponent(hash)}.${ext}${size}`;
|
|
779
1009
|
}
|
|
780
1010
|
|
|
781
1011
|
class User extends BaseStructure {
|
|
@@ -844,13 +1074,13 @@ class Channel extends BaseStructure {
|
|
|
844
1074
|
this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
|
|
845
1075
|
this.#context = context;
|
|
846
1076
|
}
|
|
847
|
-
|
|
1077
|
+
send(options) {
|
|
848
1078
|
if (!this.#context)
|
|
849
1079
|
throw new Error("This channel is not attached to a client.");
|
|
850
1080
|
return this.#context.sendMessage(this.id, options);
|
|
851
1081
|
}
|
|
852
|
-
|
|
853
|
-
return this.
|
|
1082
|
+
sendMessage(options) {
|
|
1083
|
+
return this.send(options);
|
|
854
1084
|
}
|
|
855
1085
|
edit(options) {
|
|
856
1086
|
if (!this.#context?.editChannel)
|
|
@@ -873,10 +1103,10 @@ class Channel extends BaseStructure {
|
|
|
873
1103
|
editParent(parentId) {
|
|
874
1104
|
return this.edit({ parent_id: parentId });
|
|
875
1105
|
}
|
|
876
|
-
delete() {
|
|
1106
|
+
delete(reason) {
|
|
877
1107
|
if (!this.#context?.deleteChannel)
|
|
878
1108
|
throw new Error("This channel is not attached to a client.");
|
|
879
|
-
return this.#context.deleteChannel(this.id);
|
|
1109
|
+
return this.#context.deleteChannel(this.id, reason);
|
|
880
1110
|
}
|
|
881
1111
|
update(options) {
|
|
882
1112
|
return this.edit(options);
|
|
@@ -923,6 +1153,15 @@ class Guild extends BaseStructure {
|
|
|
923
1153
|
mfaLevel;
|
|
924
1154
|
explicitContentFilter;
|
|
925
1155
|
defaultMessageNotifications;
|
|
1156
|
+
afkChannelId;
|
|
1157
|
+
afkTimeout;
|
|
1158
|
+
widgetEnabled;
|
|
1159
|
+
widgetChannelId;
|
|
1160
|
+
applicationId;
|
|
1161
|
+
publicUpdatesChannelId;
|
|
1162
|
+
safetyAlertsChannelId;
|
|
1163
|
+
maxPresences;
|
|
1164
|
+
maxVideoChannelUsers;
|
|
926
1165
|
constructor(data) {
|
|
927
1166
|
super(data.id);
|
|
928
1167
|
if (!data.name)
|
|
@@ -944,14 +1183,22 @@ class Guild extends BaseStructure {
|
|
|
944
1183
|
this.vanityUrlCode = data.vanity_url_code ?? null;
|
|
945
1184
|
this.nsfwLevel = data.nsfw_level ?? 0;
|
|
946
1185
|
this.discoverySplash = data.discovery_splash ?? null;
|
|
947
|
-
|
|
948
|
-
this.
|
|
949
|
-
this.
|
|
950
|
-
this.
|
|
951
|
-
this.
|
|
952
|
-
this.
|
|
953
|
-
this.
|
|
954
|
-
this.
|
|
1186
|
+
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
1187
|
+
this.systemChannelId = data.system_channel_id ?? null;
|
|
1188
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
1189
|
+
this.maxMembers = data.max_members ?? 0;
|
|
1190
|
+
this.mfaLevel = data.mfa_level ?? 0;
|
|
1191
|
+
this.explicitContentFilter = data.explicit_content_filter ?? 0;
|
|
1192
|
+
this.defaultMessageNotifications = data.default_message_notifications ?? 0;
|
|
1193
|
+
this.afkChannelId = data.afk_channel_id ?? null;
|
|
1194
|
+
this.afkTimeout = data.afk_timeout;
|
|
1195
|
+
this.widgetEnabled = data.widget_enabled ?? false;
|
|
1196
|
+
this.widgetChannelId = data.widget_channel_id ?? null;
|
|
1197
|
+
this.applicationId = data.application_id ?? null;
|
|
1198
|
+
this.publicUpdatesChannelId = data.public_updates_channel_id ?? null;
|
|
1199
|
+
this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
|
|
1200
|
+
this.maxPresences = data.max_presences ?? null;
|
|
1201
|
+
this.maxVideoChannelUsers = data.max_video_channel_users;
|
|
955
1202
|
}
|
|
956
1203
|
iconURL(options = {}) {
|
|
957
1204
|
if (!this.icon)
|
|
@@ -1114,60 +1361,7 @@ var Permissions = {
|
|
|
1114
1361
|
PinMessages: 1n << 51n,
|
|
1115
1362
|
BypassSlowmode: 1n << 52n
|
|
1116
1363
|
};
|
|
1117
|
-
var PermissionFlagsBits =
|
|
1118
|
-
CreateInstantInvite: 1n << 0n,
|
|
1119
|
-
KickMembers: 1n << 1n,
|
|
1120
|
-
BanMembers: 1n << 2n,
|
|
1121
|
-
Administrator: 1n << 3n,
|
|
1122
|
-
ManageChannels: 1n << 4n,
|
|
1123
|
-
ManageGuild: 1n << 5n,
|
|
1124
|
-
AddReactions: 1n << 6n,
|
|
1125
|
-
ViewAuditLog: 1n << 7n,
|
|
1126
|
-
PrioritySpeaker: 1n << 8n,
|
|
1127
|
-
Stream: 1n << 9n,
|
|
1128
|
-
ViewChannel: 1n << 10n,
|
|
1129
|
-
SendMessages: 1n << 11n,
|
|
1130
|
-
SendTTSMessages: 1n << 12n,
|
|
1131
|
-
ManageMessages: 1n << 13n,
|
|
1132
|
-
EmbedLinks: 1n << 14n,
|
|
1133
|
-
AttachFiles: 1n << 15n,
|
|
1134
|
-
ReadMessageHistory: 1n << 16n,
|
|
1135
|
-
MentionEveryone: 1n << 17n,
|
|
1136
|
-
UseExternalEmojis: 1n << 18n,
|
|
1137
|
-
ViewGuildInsights: 1n << 19n,
|
|
1138
|
-
Connect: 1n << 20n,
|
|
1139
|
-
Speak: 1n << 21n,
|
|
1140
|
-
MuteMembers: 1n << 22n,
|
|
1141
|
-
DeafenMembers: 1n << 23n,
|
|
1142
|
-
MoveMembers: 1n << 24n,
|
|
1143
|
-
UseVAD: 1n << 25n,
|
|
1144
|
-
ChangeNickname: 1n << 26n,
|
|
1145
|
-
ManageNicknames: 1n << 27n,
|
|
1146
|
-
ManageRoles: 1n << 28n,
|
|
1147
|
-
ManageWebhooks: 1n << 29n,
|
|
1148
|
-
ManageGuildExpressions: 1n << 30n,
|
|
1149
|
-
UseApplicationCommands: 1n << 31n,
|
|
1150
|
-
RequestToSpeak: 1n << 32n,
|
|
1151
|
-
ManageEvents: 1n << 33n,
|
|
1152
|
-
ManageThreads: 1n << 34n,
|
|
1153
|
-
CreatePublicThreads: 1n << 35n,
|
|
1154
|
-
CreatePrivateThreads: 1n << 36n,
|
|
1155
|
-
UseExternalStickers: 1n << 37n,
|
|
1156
|
-
SendMessagesInThreads: 1n << 38n,
|
|
1157
|
-
UseEmbeddedActivities: 1n << 39n,
|
|
1158
|
-
ModerateMembers: 1n << 40n,
|
|
1159
|
-
ViewCreatorMonetizationAnalytics: 1n << 41n,
|
|
1160
|
-
UseSoundboard: 1n << 42n,
|
|
1161
|
-
CreateGuildExpressions: 1n << 43n,
|
|
1162
|
-
CreateEvents: 1n << 44n,
|
|
1163
|
-
UseExternalSounds: 1n << 45n,
|
|
1164
|
-
SendVoiceMessages: 1n << 46n,
|
|
1165
|
-
SetVoiceChannelStatus: 1n << 48n,
|
|
1166
|
-
SendPolls: 1n << 49n,
|
|
1167
|
-
UseExternalApps: 1n << 50n,
|
|
1168
|
-
PinMessages: 1n << 51n,
|
|
1169
|
-
BypassSlowmode: 1n << 52n
|
|
1170
|
-
};
|
|
1364
|
+
var PermissionFlagsBits = Permissions;
|
|
1171
1365
|
|
|
1172
1366
|
class PermissionSet {
|
|
1173
1367
|
bitfield;
|
|
@@ -1568,10 +1762,10 @@ class GuildMember {
|
|
|
1568
1762
|
get permissions() {
|
|
1569
1763
|
if (this.#suppliedPermissions)
|
|
1570
1764
|
return this.#suppliedPermissions;
|
|
1571
|
-
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds) ?? 0n);
|
|
1765
|
+
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, undefined, this.timedOutUntil) ?? 0n);
|
|
1572
1766
|
}
|
|
1573
1767
|
permissionsIn(channelId) {
|
|
1574
|
-
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId);
|
|
1768
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId, this.timedOutUntil);
|
|
1575
1769
|
return computed ? new PermissionsBitField(computed) : null;
|
|
1576
1770
|
}
|
|
1577
1771
|
#action(name) {
|
|
@@ -1930,10 +2124,10 @@ class Message extends BaseStructure {
|
|
|
1930
2124
|
update(options) {
|
|
1931
2125
|
return this.edit(options);
|
|
1932
2126
|
}
|
|
1933
|
-
delete() {
|
|
2127
|
+
delete(reason) {
|
|
1934
2128
|
if (!this.#context)
|
|
1935
2129
|
throw new Error("This message is not attached to a client.");
|
|
1936
|
-
return this.#context.deleteMessage(this.channelId, this.id);
|
|
2130
|
+
return this.#context.deleteMessage(this.channelId, this.id, reason);
|
|
1937
2131
|
}
|
|
1938
2132
|
reply(options) {
|
|
1939
2133
|
if (!this.#context)
|
|
@@ -1980,15 +2174,15 @@ class Message extends BaseStructure {
|
|
|
1980
2174
|
throw new Error("This message is not attached to a client.");
|
|
1981
2175
|
return this.#context.removeAllReactions(this.channelId, this.id);
|
|
1982
2176
|
}
|
|
1983
|
-
pin() {
|
|
2177
|
+
pin(reason) {
|
|
1984
2178
|
if (!this.#context?.pinMessage)
|
|
1985
2179
|
throw new Error("This message is not attached to a client.");
|
|
1986
|
-
return this.#context.pinMessage(this.channelId, this.id);
|
|
2180
|
+
return this.#context.pinMessage(this.channelId, this.id, reason);
|
|
1987
2181
|
}
|
|
1988
|
-
unpin() {
|
|
2182
|
+
unpin(reason) {
|
|
1989
2183
|
if (!this.#context?.unpinMessage)
|
|
1990
2184
|
throw new Error("This message is not attached to a client.");
|
|
1991
|
-
return this.#context.unpinMessage(this.channelId, this.id);
|
|
2185
|
+
return this.#context.unpinMessage(this.channelId, this.id, reason);
|
|
1992
2186
|
}
|
|
1993
2187
|
get isEphemeral() {
|
|
1994
2188
|
return (this.flags & 64) !== 0;
|
|
@@ -2142,7 +2336,7 @@ class UserManager extends ResourceManager {
|
|
|
2142
2336
|
return this.upsert(new User(data));
|
|
2143
2337
|
}
|
|
2144
2338
|
async leaveGuild(guildId) {
|
|
2145
|
-
await this.#rest.delete(
|
|
2339
|
+
await this.#rest.delete(Routes.currentUserGuild(guildId));
|
|
2146
2340
|
}
|
|
2147
2341
|
async createDM(userId) {
|
|
2148
2342
|
return this.#rest.post("/users/@me/channels", {
|
|
@@ -2167,15 +2361,22 @@ class EmojiManager extends Manager {
|
|
|
2167
2361
|
return data.map((item) => this.upsert(item));
|
|
2168
2362
|
}
|
|
2169
2363
|
async create(options) {
|
|
2170
|
-
|
|
2364
|
+
const [payload, reason] = splitReason(options);
|
|
2365
|
+
return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), payload, { reason }));
|
|
2171
2366
|
}
|
|
2172
2367
|
async edit(emojiId, options) {
|
|
2173
|
-
|
|
2368
|
+
const [payload, reason] = splitReason(options);
|
|
2369
|
+
return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), payload, { reason }));
|
|
2174
2370
|
}
|
|
2175
|
-
async
|
|
2176
|
-
await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId)
|
|
2371
|
+
async remove(emojiId, reason) {
|
|
2372
|
+
await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId), {
|
|
2373
|
+
reason
|
|
2374
|
+
});
|
|
2177
2375
|
this.delete(emojiId);
|
|
2178
2376
|
}
|
|
2377
|
+
deleteEmoji(emojiId) {
|
|
2378
|
+
return this.remove(emojiId);
|
|
2379
|
+
}
|
|
2179
2380
|
upsert(data) {
|
|
2180
2381
|
const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
|
|
2181
2382
|
return this.#merge(key, new Emoji2(data));
|
|
@@ -2379,11 +2580,16 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2379
2580
|
await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
|
|
2380
2581
|
this.delete(userId);
|
|
2381
2582
|
}
|
|
2382
|
-
async unban(userId) {
|
|
2383
|
-
await this.#rest.delete(Routes.guildBan(this.guildId, userId)
|
|
2583
|
+
async unban(userId, reason) {
|
|
2584
|
+
await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
|
|
2585
|
+
reason
|
|
2586
|
+
});
|
|
2384
2587
|
}
|
|
2385
2588
|
async edit(userId, options, reason) {
|
|
2386
|
-
const
|
|
2589
|
+
const [payload, optionsReason] = splitReason(options);
|
|
2590
|
+
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), payload, {
|
|
2591
|
+
reason: optionsReason ?? reason
|
|
2592
|
+
});
|
|
2387
2593
|
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
2388
2594
|
this.set(member.user.id, member);
|
|
2389
2595
|
return member;
|
|
@@ -2419,28 +2625,43 @@ class RoleManager extends ResourceManager {
|
|
|
2419
2625
|
}
|
|
2420
2626
|
async create(options) {
|
|
2421
2627
|
const { reason, ...payload } = options;
|
|
2422
|
-
const data = await this.#rest.post(Routes.guildRoles(this.guildId), {
|
|
2423
|
-
|
|
2424
|
-
permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
|
|
2425
|
-
});
|
|
2426
|
-
const role = new Role(data);
|
|
2427
|
-
this.set(role.id, role);
|
|
2428
|
-
return role;
|
|
2628
|
+
const data = await this.#rest.post(Routes.guildRoles(this.guildId), rolePayload(payload), { reason });
|
|
2629
|
+
return this.#store(data);
|
|
2429
2630
|
}
|
|
2430
2631
|
async edit(roleId, options) {
|
|
2431
2632
|
const { reason, ...payload } = options;
|
|
2432
|
-
const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), {
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2633
|
+
const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), rolePayload(payload), { reason });
|
|
2634
|
+
return this.#store(data);
|
|
2635
|
+
}
|
|
2636
|
+
#store(data) {
|
|
2436
2637
|
const role = new Role(data);
|
|
2437
2638
|
this.set(role.id, role);
|
|
2438
2639
|
return role;
|
|
2439
2640
|
}
|
|
2440
|
-
async
|
|
2441
|
-
await this.#rest.delete(Routes.guildRole(this.guildId, roleId)
|
|
2641
|
+
async remove(roleId, reason) {
|
|
2642
|
+
await this.#rest.delete(Routes.guildRole(this.guildId, roleId), {
|
|
2643
|
+
reason
|
|
2644
|
+
});
|
|
2442
2645
|
this.delete(roleId);
|
|
2443
2646
|
}
|
|
2647
|
+
async setPositions(positions, reason) {
|
|
2648
|
+
const data = await this.#rest.patch(Routes.guildRoles(this.guildId), positions.map(({ id, position }) => ({ id, position })), { reason });
|
|
2649
|
+
return data.map((item) => {
|
|
2650
|
+
const role = new Role(item);
|
|
2651
|
+
this.set(role.id, role);
|
|
2652
|
+
return role;
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
deleteRole(roleId) {
|
|
2656
|
+
return this.remove(roleId);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
function rolePayload(options) {
|
|
2660
|
+
const { permissions, ...rest } = options;
|
|
2661
|
+
return {
|
|
2662
|
+
...rest,
|
|
2663
|
+
permissions: permissions !== undefined ? String(permissions) : undefined
|
|
2664
|
+
};
|
|
2444
2665
|
}
|
|
2445
2666
|
|
|
2446
2667
|
// packages/managers/src/guild-resources.ts
|
|
@@ -2512,13 +2733,15 @@ class GuildScheduledEventManager extends Manager {
|
|
|
2512
2733
|
return events.map((event) => this.#store(event));
|
|
2513
2734
|
}
|
|
2514
2735
|
async create(options, reason) {
|
|
2515
|
-
|
|
2736
|
+
const [payload, optionsReason] = splitReason(options);
|
|
2737
|
+
return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason ?? reason }));
|
|
2516
2738
|
}
|
|
2517
2739
|
async edit(eventId, options, reason) {
|
|
2518
|
-
|
|
2740
|
+
const [payload, optionsReason] = splitReason(options);
|
|
2741
|
+
return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason ?? reason }));
|
|
2519
2742
|
}
|
|
2520
|
-
async remove(eventId) {
|
|
2521
|
-
await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId));
|
|
2743
|
+
async remove(eventId, reason) {
|
|
2744
|
+
await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId), { reason });
|
|
2522
2745
|
this.delete(eventId);
|
|
2523
2746
|
}
|
|
2524
2747
|
async fetchSubscribers(eventId, options = {}) {
|
|
@@ -2549,13 +2772,13 @@ class StageInstanceManager extends Manager {
|
|
|
2549
2772
|
privacy_level: options.privacyLevel,
|
|
2550
2773
|
send_start_notification: options.sendStartNotification,
|
|
2551
2774
|
guild_scheduled_event_id: options.guildScheduledEventId
|
|
2552
|
-
}, { reason }));
|
|
2775
|
+
}, { reason: options.reason ?? reason }));
|
|
2553
2776
|
}
|
|
2554
2777
|
async fetch(channelId) {
|
|
2555
2778
|
return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
|
|
2556
2779
|
}
|
|
2557
2780
|
async edit(channelId, options, reason) {
|
|
2558
|
-
return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason }));
|
|
2781
|
+
return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason ?? reason }));
|
|
2559
2782
|
}
|
|
2560
2783
|
async remove(channelId, reason) {
|
|
2561
2784
|
await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
|
|
@@ -2592,7 +2815,7 @@ class PermissionOverwriteManager {
|
|
|
2592
2815
|
type: options.type,
|
|
2593
2816
|
allow: BigInt(options.allow ?? 0).toString(),
|
|
2594
2817
|
deny: BigInt(options.deny ?? 0).toString()
|
|
2595
|
-
}, { reason });
|
|
2818
|
+
}, { reason: options.reason ?? reason });
|
|
2596
2819
|
}
|
|
2597
2820
|
async remove(overwriteId, reason) {
|
|
2598
2821
|
await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
|
|
@@ -2710,12 +2933,16 @@ class GuildManager extends ResourceManager {
|
|
|
2710
2933
|
return this.upsert(new Guild(data));
|
|
2711
2934
|
}
|
|
2712
2935
|
async edit(id, options) {
|
|
2713
|
-
const
|
|
2936
|
+
const [payload, reason] = splitReason(options);
|
|
2937
|
+
const data = await this.#rest.patch(Routes.guild(id), payload, { reason });
|
|
2714
2938
|
return this.upsert(new Guild(data));
|
|
2715
2939
|
}
|
|
2716
|
-
async
|
|
2940
|
+
async remove(id) {
|
|
2717
2941
|
await this.#rest.delete(Routes.guild(id));
|
|
2718
2942
|
}
|
|
2943
|
+
deleteGuild(id) {
|
|
2944
|
+
return this.remove(id);
|
|
2945
|
+
}
|
|
2719
2946
|
async fetchPreview(id) {
|
|
2720
2947
|
return this.#rest.get(Routes.guildPreview(id));
|
|
2721
2948
|
}
|
|
@@ -2759,15 +2986,17 @@ class GuildManager extends ResourceManager {
|
|
|
2759
2986
|
return new AutoModerationRule(rule);
|
|
2760
2987
|
}
|
|
2761
2988
|
async createAutoModerationRule(guildId, options) {
|
|
2762
|
-
const
|
|
2989
|
+
const [payload, reason] = splitReason(options);
|
|
2990
|
+
const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), payload, { reason });
|
|
2763
2991
|
return new AutoModerationRule(rule);
|
|
2764
2992
|
}
|
|
2765
2993
|
async editAutoModerationRule(guildId, ruleId, options) {
|
|
2766
|
-
const
|
|
2994
|
+
const [payload, reason] = splitReason(options);
|
|
2995
|
+
const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), payload, { reason });
|
|
2767
2996
|
return new AutoModerationRule(rule);
|
|
2768
2997
|
}
|
|
2769
|
-
async deleteAutoModerationRule(guildId, ruleId) {
|
|
2770
|
-
await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId));
|
|
2998
|
+
async deleteAutoModerationRule(guildId, ruleId, reason) {
|
|
2999
|
+
await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { reason });
|
|
2771
3000
|
}
|
|
2772
3001
|
}
|
|
2773
3002
|
var AuditLogEvent = {
|
|
@@ -2883,16 +3112,16 @@ class ChannelManager extends Manager {
|
|
|
2883
3112
|
this.#context = {
|
|
2884
3113
|
sendMessage: (channelId, options) => this.send(channelId, options),
|
|
2885
3114
|
editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
|
|
2886
|
-
deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
|
|
3115
|
+
deleteMessage: (channelId, messageId, reason) => this.deleteMessage(channelId, messageId, reason),
|
|
2887
3116
|
crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
|
|
2888
3117
|
editChannel: (channelId, options) => this.edit(channelId, options),
|
|
2889
|
-
deleteChannel: (channelId) => this.
|
|
3118
|
+
deleteChannel: (channelId, reason) => this.remove(channelId, reason),
|
|
2890
3119
|
addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
|
|
2891
3120
|
removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
|
|
2892
3121
|
removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
|
|
2893
3122
|
removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
|
|
2894
|
-
pinMessage: (channelId, messageId) => this.pinMessage(channelId, messageId),
|
|
2895
|
-
unpinMessage: (channelId, messageId) => this.unpinMessage(channelId, messageId)
|
|
3123
|
+
pinMessage: (channelId, messageId, reason) => this.pinMessage(channelId, messageId, reason),
|
|
3124
|
+
unpinMessage: (channelId, messageId, reason) => this.unpinMessage(channelId, messageId, reason)
|
|
2896
3125
|
};
|
|
2897
3126
|
}
|
|
2898
3127
|
messages(channelId) {
|
|
@@ -2962,15 +3191,20 @@ class ChannelManager extends Manager {
|
|
|
2962
3191
|
return this.#messageManagers.get(channelId);
|
|
2963
3192
|
}
|
|
2964
3193
|
async create(guildId, options) {
|
|
2965
|
-
|
|
3194
|
+
const [payload, reason] = splitReason(options);
|
|
3195
|
+
return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), payload, { reason }));
|
|
2966
3196
|
}
|
|
2967
3197
|
async edit(channelId, options) {
|
|
2968
|
-
|
|
3198
|
+
const [payload, reason] = splitReason(options);
|
|
3199
|
+
return this.upsert(await this.#rest.patch(Routes.channel(channelId), payload, { reason }));
|
|
2969
3200
|
}
|
|
2970
|
-
async
|
|
2971
|
-
await this.#rest.delete(Routes.channel(channelId));
|
|
3201
|
+
async remove(channelId, reason) {
|
|
3202
|
+
await this.#rest.delete(Routes.channel(channelId), { reason });
|
|
2972
3203
|
this.delete(channelId);
|
|
2973
3204
|
}
|
|
3205
|
+
deleteChannel(channelId) {
|
|
3206
|
+
return this.remove(channelId);
|
|
3207
|
+
}
|
|
2974
3208
|
delete(channelId) {
|
|
2975
3209
|
this.#messageManagers.delete(channelId);
|
|
2976
3210
|
return super.delete(channelId);
|
|
@@ -3006,8 +3240,10 @@ class ChannelManager extends Manager {
|
|
|
3006
3240
|
async editMessage(channelId, messageId, options) {
|
|
3007
3241
|
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
|
|
3008
3242
|
}
|
|
3009
|
-
async deleteMessage(channelId, messageId) {
|
|
3010
|
-
await this.#rest.delete(Routes.message(channelId, messageId)
|
|
3243
|
+
async deleteMessage(channelId, messageId, reason) {
|
|
3244
|
+
await this.#rest.delete(Routes.message(channelId, messageId), {
|
|
3245
|
+
reason
|
|
3246
|
+
});
|
|
3011
3247
|
this.messages(channelId).delete(messageId);
|
|
3012
3248
|
}
|
|
3013
3249
|
deleteCachedMessage(channelId, messageId) {
|
|
@@ -3016,19 +3252,17 @@ class ChannelManager extends Manager {
|
|
|
3016
3252
|
async crosspostMessage(channelId, messageId) {
|
|
3017
3253
|
return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
|
|
3018
3254
|
}
|
|
3019
|
-
async bulkDeleteMessages(channelId, messageIds) {
|
|
3255
|
+
async bulkDeleteMessages(channelId, messageIds, reason) {
|
|
3020
3256
|
const ids = [...new Set(messageIds)];
|
|
3021
3257
|
if (ids.length < 1 || ids.length > 100)
|
|
3022
3258
|
throw new RangeError("bulkDelete requires between 1 and 100 message IDs.");
|
|
3023
3259
|
if (ids.length === 1)
|
|
3024
|
-
return this.deleteMessage(channelId, ids[0]);
|
|
3260
|
+
return this.deleteMessage(channelId, ids[0], reason);
|
|
3025
3261
|
const cutoff = Date.now() - BULK_DELETE_MAX_AGE_MS;
|
|
3026
3262
|
const tooOld = ids.filter((id) => snowflakeTime(id) < cutoff);
|
|
3027
3263
|
if (tooOld.length)
|
|
3028
3264
|
throw new RangeError(`bulkDelete cannot delete messages older than 14 days: ${tooOld.join(", ")}`);
|
|
3029
|
-
await this.#rest.post(Routes.channelBulkDelete(channelId), {
|
|
3030
|
-
messages: ids
|
|
3031
|
-
});
|
|
3265
|
+
await this.#rest.post(Routes.channelBulkDelete(channelId), { messages: ids }, { reason });
|
|
3032
3266
|
for (const id of ids)
|
|
3033
3267
|
this.messages(channelId).delete(id);
|
|
3034
3268
|
}
|
|
@@ -3065,20 +3299,26 @@ class ChannelManager extends Manager {
|
|
|
3065
3299
|
await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/@me`);
|
|
3066
3300
|
}
|
|
3067
3301
|
async removeReaction(channelId, messageId, emoji, userId) {
|
|
3068
|
-
await this.#rest.delete(
|
|
3302
|
+
await this.#rest.delete(Routes.messageReactionUser(channelId, messageId, emoji, userId));
|
|
3069
3303
|
}
|
|
3070
3304
|
async removeAllReactions(channelId, messageId) {
|
|
3071
3305
|
await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
|
|
3072
3306
|
}
|
|
3073
3307
|
async fetchPinnedMessages(channelId) {
|
|
3074
|
-
const data = await this.#rest.get(Routes.
|
|
3075
|
-
return data.map((item) => this.messages(channelId).upsert(item));
|
|
3308
|
+
const data = await this.#rest.get(Routes.channelMessagesPins(channelId));
|
|
3309
|
+
return data.items.map((item) => this.messages(channelId).upsert(item.message));
|
|
3076
3310
|
}
|
|
3077
|
-
async pinMessage(channelId, messageId) {
|
|
3078
|
-
await this.#rest.put(Routes.
|
|
3311
|
+
async pinMessage(channelId, messageId, reason) {
|
|
3312
|
+
await this.#rest.put(Routes.channelMessagesPin(channelId, messageId), undefined, { reason });
|
|
3079
3313
|
}
|
|
3080
|
-
async unpinMessage(channelId, messageId) {
|
|
3081
|
-
await this.#rest.delete(Routes.
|
|
3314
|
+
async unpinMessage(channelId, messageId, reason) {
|
|
3315
|
+
await this.#rest.delete(Routes.channelMessagesPin(channelId, messageId), { reason });
|
|
3316
|
+
}
|
|
3317
|
+
async createWebhook(channelId, options) {
|
|
3318
|
+
const [payload, reason] = splitReason(options);
|
|
3319
|
+
return this.#rest.post(Routes.channelWebhooks(channelId), payload, {
|
|
3320
|
+
reason
|
|
3321
|
+
});
|
|
3082
3322
|
}
|
|
3083
3323
|
createThreadFromMessage(channelId, messageId, options) {
|
|
3084
3324
|
return this.threads(channelId).createFromMessage(messageId, options);
|
|
@@ -3096,7 +3336,7 @@ class ChannelManager extends Manager {
|
|
|
3096
3336
|
hasMore: messages.length === limit
|
|
3097
3337
|
};
|
|
3098
3338
|
}
|
|
3099
|
-
|
|
3339
|
+
bulkDelete(channelId, messageIds) {
|
|
3100
3340
|
return this.bulkDeleteMessages(channelId, messageIds);
|
|
3101
3341
|
}
|
|
3102
3342
|
clear() {
|
|
@@ -3131,4 +3371,4 @@ export {
|
|
|
3131
3371
|
toRequest
|
|
3132
3372
|
};
|
|
3133
3373
|
|
|
3134
|
-
//# debugId=
|
|
3374
|
+
//# debugId=B358201AAE38843564756E2164756E21
|