lunibee 0.3.1 → 0.3.3
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/dist/builders/attachment.d.ts +1 -0
- package/dist/builders/clone.d.ts +10 -0
- package/dist/builders/commands.d.ts +1 -1
- package/dist/builders/components.d.ts +24 -5
- package/dist/builders/index.js +64 -17
- package/dist/builders/index.js.map +10 -9
- package/dist/collection/index.d.ts +1 -0
- package/dist/collection/index.js +297 -19
- package/dist/collection/index.js.map +5 -4
- package/dist/collection/redis.d.ts +98 -0
- package/dist/core/collector.d.ts +8 -0
- package/dist/core/events.d.ts +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +6242 -4733
- package/dist/core/index.js.map +47 -40
- package/dist/core/permissions.d.ts +3 -402
- package/dist/core/redis-cache.d.ts +85 -0
- package/dist/formatters/index.d.ts +5 -1
- package/dist/formatters/index.js +7 -3
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js +11 -2
- package/dist/handlers/index.js.map +3 -3
- package/dist/index.js +8688 -6136
- package/dist/index.js.map +67 -59
- package/dist/managers/application.d.ts +10 -6
- package/dist/managers/base.d.ts +11 -1
- package/dist/managers/guild.d.ts +3 -1
- package/dist/managers/index.d.ts +6 -1
- package/dist/managers/index.js +383 -109
- package/dist/managers/index.js.map +20 -23
- package/dist/managers/member.d.ts +3 -1
- package/dist/managers/message.d.ts +13 -4
- package/dist/managers/thread.d.ts +3 -3
- package/dist/rest/decoder.d.ts +2 -0
- package/dist/rest/errors.d.ts +5 -2
- package/dist/rest/headers.d.ts +31 -0
- package/dist/rest/identity.d.ts +31 -0
- package/dist/rest/index.d.ts +97 -6
- package/dist/rest/index.js +1355 -220
- package/dist/rest/index.js.map +16 -13
- package/dist/rest/limiter.d.ts +75 -10
- package/dist/rest/redis.d.ts +103 -22
- package/dist/rest/scheduler.d.ts +13 -0
- package/dist/rest/store.d.ts +135 -12
- package/dist/rest/telemetry.d.ts +151 -0
- package/dist/rest/webhook.d.ts +18 -6
- package/dist/sharding/bus.d.ts +4 -2
- package/dist/sharding/cluster.d.ts +29 -1
- package/dist/sharding/health.d.ts +1 -1
- package/dist/sharding/host.d.ts +13 -2
- package/dist/sharding/identify.d.ts +2 -0
- package/dist/sharding/index.d.ts +8 -0
- package/dist/sharding/index.js +579 -65
- package/dist/sharding/index.js.map +17 -15
- package/dist/sharding/leader.d.ts +34 -0
- package/dist/sharding/remote.d.ts +36 -2
- package/dist/sharding/supervisor.d.ts +1 -1
- package/dist/sharding/thread.d.ts +30 -0
- package/dist/sharding/transport.d.ts +6 -5
- package/dist/sharding/worker.d.ts +11 -1
- package/dist/structures/base.d.ts +16 -5
- package/dist/structures/index.d.ts +1 -1
- package/dist/structures/index.js +57 -91
- package/dist/structures/index.js.map +10 -18
- package/dist/structures/options.d.ts +3 -2
- package/dist/structures/permissions.d.ts +409 -0
- package/dist/structures/resources.d.ts +4 -1
- package/dist/types/gateway.d.ts +4 -0
- package/dist/types/index.d.ts +14 -4
- package/dist/types/index.js.map +3 -3
- package/dist/utils/args.d.ts +3 -1
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.js +17 -10
- package/dist/utils/index.js.map +4 -4
- package/dist/voice/index.d.ts +7 -1
- package/dist/voice/index.js +33 -10
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/index.d.ts +2 -0
- package/dist/ws/index.js +32 -4
- package/dist/ws/index.js.map +5 -5
- package/package.json +21 -17
package/dist/managers/index.js
CHANGED
|
@@ -1,4 +1,102 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// packages/collection/src/redis.ts
|
|
3
|
+
var PRELUDE = `
|
|
4
|
+
local exp, lru, clock, ep = KEYS[1], KEYS[2], KEYS[3], ARGV[1]
|
|
5
|
+
local t = redis.call('TIME')
|
|
6
|
+
local now = tonumber(t[1]) * 1000 + math.floor(tonumber(t[2]) / 1000)
|
|
7
|
+
local out = {}
|
|
8
|
+
local function drop(m, reason)
|
|
9
|
+
local v = redis.call('GET', ep .. m)
|
|
10
|
+
redis.call('DEL', ep .. m)
|
|
11
|
+
redis.call('ZREM', exp, m)
|
|
12
|
+
redis.call('ZREM', lru, m)
|
|
13
|
+
if reason then
|
|
14
|
+
table.insert(out, m)
|
|
15
|
+
table.insert(out, v or false)
|
|
16
|
+
table.insert(out, reason)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
local gone = redis.call('ZRANGEBYSCORE', exp, '-inf', now, 'LIMIT', 0, 1000)
|
|
20
|
+
for _, m in ipairs(gone) do drop(m, 'expired') end
|
|
21
|
+
local function touch(m) redis.call('ZADD', lru, redis.call('INCR', clock), m) end
|
|
22
|
+
`;
|
|
23
|
+
var SET_SCRIPT = `${PRELUDE}
|
|
24
|
+
local m, payload, ttl, max, mode = ARGV[2], ARGV[3], tonumber(ARGV[4]), tonumber(ARGV[5]), ARGV[6]
|
|
25
|
+
if mode == 'nx' then
|
|
26
|
+
local cur = redis.call('GET', ep .. m)
|
|
27
|
+
if cur then
|
|
28
|
+
touch(m)
|
|
29
|
+
table.insert(out, 1, cur)
|
|
30
|
+
return out
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
local env = ttl .. ':' .. payload
|
|
34
|
+
if ttl > 0 then
|
|
35
|
+
-- The key outlives its logical expiry by a grace second, so the prune
|
|
36
|
+
-- that reports the expiry can still hand the value to onEvict.
|
|
37
|
+
redis.call('SET', ep .. m, env, 'PX', ttl + 1000)
|
|
38
|
+
redis.call('ZADD', exp, now + ttl, m)
|
|
39
|
+
else
|
|
40
|
+
redis.call('SET', ep .. m, env)
|
|
41
|
+
redis.call('ZREM', exp, m)
|
|
42
|
+
end
|
|
43
|
+
touch(m)
|
|
44
|
+
if max > 0 then
|
|
45
|
+
local n = redis.call('ZCARD', lru)
|
|
46
|
+
while n > max do
|
|
47
|
+
local popped = redis.call('ZPOPMIN', lru)
|
|
48
|
+
local victim = popped[1]
|
|
49
|
+
if victim == nil then break end
|
|
50
|
+
if victim ~= m then drop(victim, 'evicted') end
|
|
51
|
+
n = n - 1
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
table.insert(out, 1, false)
|
|
55
|
+
return out
|
|
56
|
+
`;
|
|
57
|
+
var GET_SCRIPT = `${PRELUDE}
|
|
58
|
+
local m, slide, mark = ARGV[2], ARGV[3], ARGV[4]
|
|
59
|
+
local env = redis.call('GET', ep .. m)
|
|
60
|
+
if not env then
|
|
61
|
+
redis.call('ZREM', exp, m)
|
|
62
|
+
redis.call('ZREM', lru, m)
|
|
63
|
+
table.insert(out, 1, false)
|
|
64
|
+
return out
|
|
65
|
+
end
|
|
66
|
+
if mark == '1' then touch(m) end
|
|
67
|
+
if slide == '1' then
|
|
68
|
+
local ttl = tonumber(string.match(env, '^(%d+):'))
|
|
69
|
+
if ttl and ttl > 0 then
|
|
70
|
+
redis.call('PEXPIRE', ep .. m, ttl + 1000)
|
|
71
|
+
redis.call('ZADD', exp, now + ttl, m)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
table.insert(out, 1, env)
|
|
75
|
+
return out
|
|
76
|
+
`;
|
|
77
|
+
var DELETE_SCRIPT = `${PRELUDE}
|
|
78
|
+
local m = ARGV[2]
|
|
79
|
+
local existed = redis.call('EXISTS', ep .. m)
|
|
80
|
+
drop(m, nil)
|
|
81
|
+
table.insert(out, 1, existed)
|
|
82
|
+
return out
|
|
83
|
+
`;
|
|
84
|
+
var LIST_SCRIPT = `${PRELUDE}
|
|
85
|
+
local what = ARGV[2]
|
|
86
|
+
if what == 'clear' then
|
|
87
|
+
local n = 0
|
|
88
|
+
repeat
|
|
89
|
+
local batch = redis.call('ZRANGE', lru, 0, 999)
|
|
90
|
+
for _, m in ipairs(batch) do drop(m, nil) end
|
|
91
|
+
n = n + #batch
|
|
92
|
+
until #batch == 0
|
|
93
|
+
redis.call('DEL', exp, lru, clock)
|
|
94
|
+
return {n}
|
|
95
|
+
end
|
|
96
|
+
local result = what == 'size' and redis.call('ZCARD', lru) or redis.call('ZRANGE', lru, 0, -1)
|
|
97
|
+
return {result, unpack(out)}
|
|
98
|
+
`;
|
|
99
|
+
|
|
2
100
|
// packages/collection/src/index.ts
|
|
3
101
|
function newPolicy(options = {}) {
|
|
4
102
|
return {
|
|
@@ -56,21 +154,35 @@ class Collection extends Map {
|
|
|
56
154
|
this.set(key, value);
|
|
57
155
|
}
|
|
58
156
|
set(key, value, ttl) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
assertTTL(ttl);
|
|
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()));
|
|
66
|
-
if (window !== undefined)
|
|
67
|
-
this.#policy ??= newPolicy();
|
|
68
|
-
if (!this.#policy)
|
|
157
|
+
let policy = this.#policy;
|
|
158
|
+
if (ttl === undefined && policy === undefined)
|
|
69
159
|
return super.set(key, value);
|
|
70
|
-
|
|
160
|
+
if (ttl !== undefined)
|
|
161
|
+
assertTTL(ttl);
|
|
162
|
+
let window = ttl ?? policy?.ttl;
|
|
163
|
+
if (window !== undefined && policy !== undefined && policy.jitter > 0)
|
|
164
|
+
window = Math.max(1, window * (1 - policy.jitter * Math.random()));
|
|
165
|
+
if (policy === undefined) {
|
|
166
|
+
if (window === undefined)
|
|
167
|
+
return super.set(key, value);
|
|
168
|
+
policy = this.#policy = newPolicy();
|
|
169
|
+
}
|
|
170
|
+
const entry = policy.entries.get(key);
|
|
71
171
|
super.set(key, value);
|
|
72
|
-
|
|
73
|
-
|
|
172
|
+
if (entry !== undefined && window !== undefined && entry.window !== 0) {
|
|
173
|
+
const deadline = Date.now() + window;
|
|
174
|
+
if (deadline >= entry.filed) {
|
|
175
|
+
entry.value = value;
|
|
176
|
+
entry.deadline = deadline;
|
|
177
|
+
entry.window = window;
|
|
178
|
+
if (entry.inLru)
|
|
179
|
+
this.#promote(policy, entry);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.#track(key, value, window, entry);
|
|
184
|
+
if (policy.maxSize !== undefined && policy.lruSize > policy.maxSize)
|
|
185
|
+
this.#enforceCap();
|
|
74
186
|
return this;
|
|
75
187
|
}
|
|
76
188
|
setWithoutTTL(key, value) {
|
|
@@ -226,10 +338,10 @@ class Collection extends Map {
|
|
|
226
338
|
this.#unlink(policy, entry);
|
|
227
339
|
policy.entries.delete(key);
|
|
228
340
|
}
|
|
229
|
-
#track(key, value, window,
|
|
341
|
+
#track(key, value, window, existing) {
|
|
230
342
|
const policy = this.#policy;
|
|
231
343
|
const lru = policy.maxSize !== undefined;
|
|
232
|
-
let entry =
|
|
344
|
+
let entry = existing;
|
|
233
345
|
if (entry)
|
|
234
346
|
entry.value = value;
|
|
235
347
|
if (window === undefined) {
|
|
@@ -361,11 +473,20 @@ class Collection extends Map {
|
|
|
361
473
|
while (policy.lruSize > max) {
|
|
362
474
|
const oldest = policy.oldest;
|
|
363
475
|
const value = policy.onEvict ? super.get(oldest.key) : undefined;
|
|
364
|
-
|
|
476
|
+
const next = oldest.newer;
|
|
477
|
+
policy.oldest = next;
|
|
478
|
+
if (next)
|
|
479
|
+
next.older = undefined;
|
|
480
|
+
else
|
|
481
|
+
policy.newest = undefined;
|
|
482
|
+
oldest.newer = undefined;
|
|
483
|
+
oldest.inLru = false;
|
|
484
|
+
policy.lruSize--;
|
|
365
485
|
policy.entries.delete(oldest.key);
|
|
366
486
|
super.delete(oldest.key);
|
|
367
487
|
policy.evicted++;
|
|
368
|
-
|
|
488
|
+
if (policy.onEvict)
|
|
489
|
+
this.#notify(oldest.key, value, "evicted");
|
|
369
490
|
}
|
|
370
491
|
}
|
|
371
492
|
#nextDeadline() {
|
|
@@ -780,13 +901,25 @@ class Collection extends Map {
|
|
|
780
901
|
}
|
|
781
902
|
|
|
782
903
|
// packages/managers/src/base.ts
|
|
904
|
+
function assignFields(into, from) {
|
|
905
|
+
const target = into;
|
|
906
|
+
const source = from;
|
|
907
|
+
for (const key of Object.keys(source))
|
|
908
|
+
target[key] = source[key];
|
|
909
|
+
return into;
|
|
910
|
+
}
|
|
783
911
|
function splitReason(options) {
|
|
784
912
|
const { reason, ...payload } = options;
|
|
785
913
|
return [payload, reason];
|
|
786
914
|
}
|
|
787
915
|
|
|
788
916
|
class Manager {
|
|
789
|
-
cache
|
|
917
|
+
cache;
|
|
918
|
+
#bounded;
|
|
919
|
+
constructor(maxSize) {
|
|
920
|
+
this.#bounded = maxSize !== undefined;
|
|
921
|
+
this.cache = new Collection(null, { maxSize });
|
|
922
|
+
}
|
|
790
923
|
get(id) {
|
|
791
924
|
return this.cache.get(id);
|
|
792
925
|
}
|
|
@@ -822,7 +955,10 @@ class Manager {
|
|
|
822
955
|
}
|
|
823
956
|
set(id, value) {
|
|
824
957
|
this.#markDirty(id);
|
|
825
|
-
this
|
|
958
|
+
if (this.#bounded)
|
|
959
|
+
this.cache.set(id, value);
|
|
960
|
+
else
|
|
961
|
+
this.cache.setWithoutTTL(id, value);
|
|
826
962
|
return this;
|
|
827
963
|
}
|
|
828
964
|
delete(id) {
|
|
@@ -852,8 +988,8 @@ class Manager {
|
|
|
852
988
|
class ResourceManager extends Manager {
|
|
853
989
|
#fetcher;
|
|
854
990
|
#key;
|
|
855
|
-
constructor(fetcher, key) {
|
|
856
|
-
super();
|
|
991
|
+
constructor(fetcher, key, maxSize) {
|
|
992
|
+
super(maxSize);
|
|
857
993
|
if (typeof fetcher !== "function" || typeof key !== "function")
|
|
858
994
|
throw new TypeError("ResourceManager requires fetcher and key functions.");
|
|
859
995
|
this.#fetcher = fetcher;
|
|
@@ -863,7 +999,7 @@ class ResourceManager extends Manager {
|
|
|
863
999
|
return this.get(id) ?? this.fetch(id);
|
|
864
1000
|
}
|
|
865
1001
|
fetch(id) {
|
|
866
|
-
return this.fetchOnce(id, () => this.#fetcher(id));
|
|
1002
|
+
return this.fetchOnce(id, () => this.#fetcher(id), (value) => this.upsert(value));
|
|
867
1003
|
}
|
|
868
1004
|
async fetchMany(ids) {
|
|
869
1005
|
return Promise.all([...ids].map((id) => this.resolve(id)));
|
|
@@ -872,7 +1008,7 @@ class ResourceManager extends Manager {
|
|
|
872
1008
|
const key = this.#key(resource);
|
|
873
1009
|
const existing = this.get(key);
|
|
874
1010
|
if (existing !== undefined && existing !== resource && typeof existing === "object" && existing !== null) {
|
|
875
|
-
|
|
1011
|
+
assignFields(existing, resource);
|
|
876
1012
|
this.set(key, existing);
|
|
877
1013
|
return existing;
|
|
878
1014
|
}
|
|
@@ -886,7 +1022,7 @@ class ResourceManager extends Manager {
|
|
|
886
1022
|
// packages/rest/package.json
|
|
887
1023
|
var package_default = {
|
|
888
1024
|
name: "@lunibee/rest",
|
|
889
|
-
version: "0.3.
|
|
1025
|
+
version: "0.3.3",
|
|
890
1026
|
type: "module",
|
|
891
1027
|
module: "./src/index.ts",
|
|
892
1028
|
types: "./src/index.ts",
|
|
@@ -996,6 +1132,139 @@ function snowflake(value, field) {
|
|
|
996
1132
|
throw new TypeError(`${field} must be a valid Discord snowflake.`);
|
|
997
1133
|
return value;
|
|
998
1134
|
}
|
|
1135
|
+
// packages/rest/src/redis.ts
|
|
1136
|
+
var LUA_PRELUDE = `
|
|
1137
|
+
local function now_ms()
|
|
1138
|
+
local t = redis.call('TIME')
|
|
1139
|
+
return tonumber(t[1]) * 1000 + math.floor(tonumber(t[2]) / 1000)
|
|
1140
|
+
end
|
|
1141
|
+
local function load(key)
|
|
1142
|
+
local raw = redis.call('GET', key)
|
|
1143
|
+
if not raw then return nil end
|
|
1144
|
+
local ok, s = pcall(cjson.decode, raw)
|
|
1145
|
+
if ok and type(s) == 'table' and type(s.resetAt) == 'number'
|
|
1146
|
+
and type(s.remaining) == 'number' then return s end
|
|
1147
|
+
return nil
|
|
1148
|
+
end
|
|
1149
|
+
local function save(key, s, now, linger)
|
|
1150
|
+
local ttl = math.max(1, math.ceil(s.resetAt - now)) + linger
|
|
1151
|
+
redis.call('SET', key, cjson.encode(s), 'PX', ttl)
|
|
1152
|
+
end
|
|
1153
|
+
`;
|
|
1154
|
+
var RESERVE_SCRIPT = `${LUA_PRELUDE}
|
|
1155
|
+
local now = now_ms()
|
|
1156
|
+
local glimit, gwindow = tonumber(ARGV[4]) or 0, tonumber(ARGV[5]) or 1000
|
|
1157
|
+
if #KEYS > 1 then
|
|
1158
|
+
local g = tonumber(redis.call('GET', KEYS[2]) or '0') or 0
|
|
1159
|
+
if g > now then return {0, math.ceil(g - now), 'global'} end
|
|
1160
|
+
end
|
|
1161
|
+
if #KEYS < 3 then glimit = 0 end
|
|
1162
|
+
-- A sliding log of send times: at most glimit in any gwindow span.
|
|
1163
|
+
if glimit > 0 then
|
|
1164
|
+
redis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now - gwindow)
|
|
1165
|
+
if redis.call('ZCARD', KEYS[3]) >= glimit then
|
|
1166
|
+
local oldest = redis.call('ZRANGE', KEYS[3], 0, 0, 'WITHSCORES')
|
|
1167
|
+
return {0, math.max(1, tonumber(oldest[2]) + gwindow - now + 1), 'global'}
|
|
1168
|
+
end
|
|
1169
|
+
end
|
|
1170
|
+
local function count()
|
|
1171
|
+
if glimit > 0 then
|
|
1172
|
+
local seq = redis.call('ZCARD', KEYS[3])
|
|
1173
|
+
redis.call('ZADD', KEYS[3], now, now .. ':' .. seq)
|
|
1174
|
+
redis.call('PEXPIRE', KEYS[3], gwindow + 1000)
|
|
1175
|
+
end
|
|
1176
|
+
end
|
|
1177
|
+
local probe, poll, linger = tonumber(ARGV[1]), tonumber(ARGV[2]), tonumber(ARGV[3])
|
|
1178
|
+
local s = load(KEYS[1])
|
|
1179
|
+
if s and s.resetAt > now then
|
|
1180
|
+
if s.remaining > 0 then
|
|
1181
|
+
s.remaining = s.remaining - 1
|
|
1182
|
+
save(KEYS[1], s, now, linger)
|
|
1183
|
+
count()
|
|
1184
|
+
return {1, s.resetAt, 1}
|
|
1185
|
+
end
|
|
1186
|
+
local wait = s.resetAt - now
|
|
1187
|
+
if s.provisional then wait = math.min(wait, poll) end
|
|
1188
|
+
local reason = 'bucket'
|
|
1189
|
+
if s.probe then reason = 'probe' end
|
|
1190
|
+
return {0, math.ceil(wait), reason}
|
|
1191
|
+
end
|
|
1192
|
+
local resetAt = now + probe
|
|
1193
|
+
if s and type(s.limit) == 'number' and s.limit > 0 then
|
|
1194
|
+
save(KEYS[1], {remaining = s.limit - 1, resetAt = resetAt, limit = s.limit, provisional = true}, now, linger)
|
|
1195
|
+
count()
|
|
1196
|
+
return {1, resetAt, 1}
|
|
1197
|
+
end
|
|
1198
|
+
save(KEYS[1], {remaining = 0, resetAt = resetAt, provisional = true, probe = true}, now, 0)
|
|
1199
|
+
count()
|
|
1200
|
+
return {1, resetAt, 0}
|
|
1201
|
+
`;
|
|
1202
|
+
var RECONCILE_SCRIPT = `${LUA_PRELUDE}
|
|
1203
|
+
local now = now_ms()
|
|
1204
|
+
local rem, after, limit = tonumber(ARGV[1]), tonumber(ARGV[2]), tonumber(ARGV[3])
|
|
1205
|
+
local win, retry, linger = tonumber(ARGV[4]), tonumber(ARGV[5]), tonumber(ARGV[6])
|
|
1206
|
+
local tol = 50
|
|
1207
|
+
local incoming = nil
|
|
1208
|
+
if after then incoming = math.ceil(now + after) end
|
|
1209
|
+
local s = load(KEYS[1])
|
|
1210
|
+
local n
|
|
1211
|
+
if s and s.resetAt > now and not s.probe then
|
|
1212
|
+
n = s
|
|
1213
|
+
local stale = win and n.window and win < n.window - tol
|
|
1214
|
+
if not stale then
|
|
1215
|
+
if rem then n.remaining = math.min(n.remaining, rem) end
|
|
1216
|
+
if incoming then
|
|
1217
|
+
local newer = win and n.window and win > n.window + tol
|
|
1218
|
+
if n.provisional or newer then n.resetAt = incoming
|
|
1219
|
+
else n.resetAt = math.max(n.resetAt, incoming) end
|
|
1220
|
+
n.provisional = nil
|
|
1221
|
+
end
|
|
1222
|
+
if win then n.window = math.max(n.window or 0, win) end
|
|
1223
|
+
end
|
|
1224
|
+
else
|
|
1225
|
+
if not rem and not retry then
|
|
1226
|
+
if s and s.probe then redis.call('DEL', KEYS[1]) end
|
|
1227
|
+
return 0
|
|
1228
|
+
end
|
|
1229
|
+
n = {remaining = rem or 0, resetAt = incoming or now}
|
|
1230
|
+
if s and type(s.limit) == 'number' then n.limit = s.limit end
|
|
1231
|
+
if win then n.window = win end
|
|
1232
|
+
end
|
|
1233
|
+
if limit and limit > 0 then n.limit = limit end
|
|
1234
|
+
if retry then
|
|
1235
|
+
n.remaining = 0
|
|
1236
|
+
n.resetAt = math.max(n.resetAt, math.ceil(now + retry))
|
|
1237
|
+
n.provisional = nil
|
|
1238
|
+
end
|
|
1239
|
+
save(KEYS[1], n, now, linger)
|
|
1240
|
+
return 1
|
|
1241
|
+
`;
|
|
1242
|
+
var EXTEND_GLOBAL_SCRIPT = `${LUA_PRELUDE}
|
|
1243
|
+
local now = now_ms()
|
|
1244
|
+
local target = math.ceil(now + tonumber(ARGV[1]))
|
|
1245
|
+
local cur = tonumber(redis.call('GET', KEYS[1]) or '0') or 0
|
|
1246
|
+
if target > cur then
|
|
1247
|
+
redis.call('SET', KEYS[1], tostring(target), 'PX', math.max(1, target - now))
|
|
1248
|
+
return target - now
|
|
1249
|
+
end
|
|
1250
|
+
return math.max(0, cur - now)
|
|
1251
|
+
`;
|
|
1252
|
+
var RELEASE_SCRIPT = `${LUA_PRELUDE}
|
|
1253
|
+
local s = load(KEYS[1])
|
|
1254
|
+
if not s or s.resetAt ~= tonumber(ARGV[1]) then return 0 end
|
|
1255
|
+
if s.probe then
|
|
1256
|
+
redis.call('DEL', KEYS[1])
|
|
1257
|
+
return 1
|
|
1258
|
+
end
|
|
1259
|
+
if ARGV[2] == '1' then
|
|
1260
|
+
local cap = s.remaining + 1
|
|
1261
|
+
if type(s.limit) == 'number' then cap = math.min(cap, s.limit) end
|
|
1262
|
+
s.remaining = cap
|
|
1263
|
+
redis.call('SET', KEYS[1], cjson.encode(s), 'KEEPTTL')
|
|
1264
|
+
return 1
|
|
1265
|
+
end
|
|
1266
|
+
return 0
|
|
1267
|
+
`;
|
|
999
1268
|
|
|
1000
1269
|
// packages/rest/src/index.ts
|
|
1001
1270
|
var LIBRARY_VERSION = package_default.version;
|
|
@@ -1008,7 +1277,8 @@ var REQUEST_DATA_KEYS = new Set([
|
|
|
1008
1277
|
"headers",
|
|
1009
1278
|
"reason",
|
|
1010
1279
|
"auth",
|
|
1011
|
-
"signal"
|
|
1280
|
+
"signal",
|
|
1281
|
+
"maxQueueWait"
|
|
1012
1282
|
]);
|
|
1013
1283
|
|
|
1014
1284
|
// packages/types/src/channel-kind.ts
|
|
@@ -1157,8 +1427,9 @@ class Channel extends BaseStructure {
|
|
|
1157
1427
|
rateLimitPerUser;
|
|
1158
1428
|
position;
|
|
1159
1429
|
permissionOverwrites;
|
|
1430
|
+
partial;
|
|
1160
1431
|
#context;
|
|
1161
|
-
constructor(data, context) {
|
|
1432
|
+
constructor(data, context, options) {
|
|
1162
1433
|
super(data.id);
|
|
1163
1434
|
if (!Number.isInteger(data.type) || data.type < 0)
|
|
1164
1435
|
throw new RangeError("A Discord channel requires a valid channel type.");
|
|
@@ -1171,6 +1442,7 @@ class Channel extends BaseStructure {
|
|
|
1171
1442
|
this.rateLimitPerUser = data.rate_limit_per_user;
|
|
1172
1443
|
this.position = data.position;
|
|
1173
1444
|
this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
|
|
1445
|
+
this.partial = options?.partial ?? false;
|
|
1174
1446
|
this.#context = context;
|
|
1175
1447
|
}
|
|
1176
1448
|
send(options) {
|
|
@@ -1361,7 +1633,7 @@ class Guild extends BaseStructure {
|
|
|
1361
1633
|
}
|
|
1362
1634
|
}
|
|
1363
1635
|
|
|
1364
|
-
// packages/
|
|
1636
|
+
// packages/structures/src/permissions.ts
|
|
1365
1637
|
var Permission = {
|
|
1366
1638
|
createInstantInvite: 1n << 0n,
|
|
1367
1639
|
kickMembers: 1n << 1n,
|
|
@@ -1643,6 +1915,15 @@ class PermissionSet {
|
|
|
1643
1915
|
get useExternalApps() {
|
|
1644
1916
|
return (this.bitfield & Permission.useExternalApps) === Permission.useExternalApps;
|
|
1645
1917
|
}
|
|
1918
|
+
get setVoiceChannelStatus() {
|
|
1919
|
+
return (this.bitfield & Permission.setVoiceChannelStatus) === Permission.setVoiceChannelStatus;
|
|
1920
|
+
}
|
|
1921
|
+
get pinMessages() {
|
|
1922
|
+
return (this.bitfield & Permission.pinMessages) === Permission.pinMessages;
|
|
1923
|
+
}
|
|
1924
|
+
get bypassSlowmode() {
|
|
1925
|
+
return (this.bitfield & Permission.bypassSlowmode) === Permission.bypassSlowmode;
|
|
1926
|
+
}
|
|
1646
1927
|
has(...permissions) {
|
|
1647
1928
|
if (permissions.length === 1) {
|
|
1648
1929
|
const p = permissions[0];
|
|
@@ -1745,60 +2026,7 @@ class PermissionsBitField extends PermissionSet {
|
|
|
1745
2026
|
}
|
|
1746
2027
|
}
|
|
1747
2028
|
var ALL_PERMISSIONS = Object.values(Permission).reduce((bits, bit) => bits | bit, 0n);
|
|
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
|
-
]);
|
|
1771
|
-
// packages/ws/src/close-codes.ts
|
|
1772
|
-
var GatewayCloseCodes = {
|
|
1773
|
-
UnknownError: 4000,
|
|
1774
|
-
UnknownOpcode: 4001,
|
|
1775
|
-
DecodeError: 4002,
|
|
1776
|
-
NotAuthenticated: 4003,
|
|
1777
|
-
AuthenticationFailed: 4004,
|
|
1778
|
-
AlreadyAuthenticated: 4005,
|
|
1779
|
-
InvalidSeq: 4007,
|
|
1780
|
-
RateLimited: 4008,
|
|
1781
|
-
SessionTimedOut: 4009,
|
|
1782
|
-
InvalidShard: 4010,
|
|
1783
|
-
ShardingRequired: 4011,
|
|
1784
|
-
InvalidAPIVersion: 4012,
|
|
1785
|
-
InvalidIntents: 4013,
|
|
1786
|
-
DisallowedIntents: 4014
|
|
1787
|
-
};
|
|
1788
2029
|
|
|
1789
|
-
// packages/ws/src/reconnect.ts
|
|
1790
|
-
var FATAL_CLOSE_CODES = [
|
|
1791
|
-
GatewayCloseCodes.AuthenticationFailed,
|
|
1792
|
-
GatewayCloseCodes.InvalidShard,
|
|
1793
|
-
GatewayCloseCodes.ShardingRequired,
|
|
1794
|
-
GatewayCloseCodes.InvalidAPIVersion,
|
|
1795
|
-
GatewayCloseCodes.InvalidIntents,
|
|
1796
|
-
GatewayCloseCodes.DisallowedIntents
|
|
1797
|
-
];
|
|
1798
|
-
var IDENTIFY_CLOSE_CODES = [
|
|
1799
|
-
GatewayCloseCodes.InvalidSeq,
|
|
1800
|
-
GatewayCloseCodes.SessionTimedOut
|
|
1801
|
-
];
|
|
1802
2030
|
// packages/structures/src/resources.ts
|
|
1803
2031
|
function toDateOrNull(value) {
|
|
1804
2032
|
if (!value)
|
|
@@ -1954,7 +2182,7 @@ class TextChannel extends Channel {
|
|
|
1954
2182
|
return `<#${this.id}>`;
|
|
1955
2183
|
}
|
|
1956
2184
|
}
|
|
1957
|
-
class
|
|
2185
|
+
class Emoji extends BaseStructure {
|
|
1958
2186
|
name;
|
|
1959
2187
|
roleIds;
|
|
1960
2188
|
user;
|
|
@@ -2302,7 +2530,7 @@ class Message extends BaseStructure {
|
|
|
2302
2530
|
user: data.member.user ?? data.author,
|
|
2303
2531
|
guild_id: data.guild_id
|
|
2304
2532
|
}, context) : null;
|
|
2305
|
-
this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
|
|
2533
|
+
this.channel = context?.cachedChannel?.(data.channel_id) ?? new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context, { partial: true });
|
|
2306
2534
|
}
|
|
2307
2535
|
get embedsSuppressed() {
|
|
2308
2536
|
return (this.flags & 4) !== 0;
|
|
@@ -2430,18 +2658,41 @@ class Message extends BaseStructure {
|
|
|
2430
2658
|
|
|
2431
2659
|
// packages/managers/src/message.ts
|
|
2432
2660
|
function toAttachments(files) {
|
|
2433
|
-
return files.map((file) => ({
|
|
2661
|
+
return files.map((file) => ("toBuffer" in file) ? { name: file.name, data: file.toBuffer() } : {
|
|
2434
2662
|
name: file.name,
|
|
2435
2663
|
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
2436
2664
|
contentType: file.contentType
|
|
2437
|
-
})
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
function assertAllowedMentions(mentions) {
|
|
2668
|
+
const parse = mentions.parse ?? [];
|
|
2669
|
+
for (const kind of parse)
|
|
2670
|
+
if (!["roles", "users", "everyone"].includes(kind))
|
|
2671
|
+
throw new TypeError(`allowed_mentions.parse has unknown value "${String(kind)}".`);
|
|
2672
|
+
for (const [kind, list] of [
|
|
2673
|
+
["users", mentions.users],
|
|
2674
|
+
["roles", mentions.roles]
|
|
2675
|
+
]) {
|
|
2676
|
+
if (list === undefined)
|
|
2677
|
+
continue;
|
|
2678
|
+
if (!Array.isArray(list) || list.some((id) => typeof id !== "string"))
|
|
2679
|
+
throw new TypeError(`allowed_mentions.${kind} must be an array of ID strings.`);
|
|
2680
|
+
if (list.length > 100)
|
|
2681
|
+
throw new RangeError(`allowed_mentions.${kind} holds at most 100 IDs.`);
|
|
2682
|
+
if (list.length > 0 && parse.includes(kind))
|
|
2683
|
+
throw new TypeError(`allowed_mentions cannot list ${kind} by ID and also parse "${kind}".`);
|
|
2684
|
+
}
|
|
2438
2685
|
}
|
|
2439
2686
|
function toRequest(options, allowedMentions) {
|
|
2440
2687
|
const { files, ...body } = options;
|
|
2441
2688
|
if (allowedMentions !== undefined && body.allowed_mentions === undefined)
|
|
2442
2689
|
body.allowed_mentions = allowedMentions;
|
|
2690
|
+
if (body.allowed_mentions)
|
|
2691
|
+
assertAllowedMentions(body.allowed_mentions);
|
|
2443
2692
|
if (!files?.length)
|
|
2444
2693
|
return body;
|
|
2694
|
+
if (body.attachments === undefined && files.some((f) => f.description))
|
|
2695
|
+
body.attachments = files.map((file, id) => file.description ? { id, description: file.description } : { id });
|
|
2445
2696
|
return {
|
|
2446
2697
|
body,
|
|
2447
2698
|
files: toAttachments(files)
|
|
@@ -2486,7 +2737,7 @@ class MessageManager {
|
|
|
2486
2737
|
const existing = this.cache.peek(data.id);
|
|
2487
2738
|
const message = new Message(data, this.#context);
|
|
2488
2739
|
if (existing) {
|
|
2489
|
-
|
|
2740
|
+
assignFields(existing, message);
|
|
2490
2741
|
return existing;
|
|
2491
2742
|
}
|
|
2492
2743
|
if (this.#caching)
|
|
@@ -2503,12 +2754,14 @@ class ThreadManager {
|
|
|
2503
2754
|
#rest;
|
|
2504
2755
|
#context;
|
|
2505
2756
|
#channelId;
|
|
2506
|
-
|
|
2757
|
+
#allowedMentions;
|
|
2758
|
+
constructor(rest, context, channelId, allowedMentions) {
|
|
2507
2759
|
if (!channelId)
|
|
2508
2760
|
throw new TypeError("Channel ID is required.");
|
|
2509
2761
|
this.#rest = rest;
|
|
2510
2762
|
this.#context = context;
|
|
2511
2763
|
this.#channelId = channelId;
|
|
2764
|
+
this.#allowedMentions = allowedMentions;
|
|
2512
2765
|
}
|
|
2513
2766
|
async createFromMessage(messageId, options) {
|
|
2514
2767
|
const data = await this.#rest.post(Routes.messageThread(this.#channelId, messageId), {
|
|
@@ -2530,14 +2783,17 @@ class ThreadManager {
|
|
|
2530
2783
|
}
|
|
2531
2784
|
async createForumPost(options) {
|
|
2532
2785
|
const { message, appliedTags, reason, ...thread } = options;
|
|
2533
|
-
const
|
|
2786
|
+
const request = toRequest(message, this.#allowedMentions);
|
|
2787
|
+
const withFiles = "body" in request && "files" in request;
|
|
2788
|
+
const content = withFiles ? request.body : request;
|
|
2789
|
+
const files = withFiles ? request.files : undefined;
|
|
2534
2790
|
const data = await this.#rest.post(Routes.channelThreads(this.#channelId), {
|
|
2535
2791
|
name: thread.name,
|
|
2536
2792
|
auto_archive_duration: thread.autoArchiveDuration,
|
|
2537
2793
|
rate_limit_per_user: thread.rateLimitPerUser,
|
|
2538
2794
|
applied_tags: appliedTags,
|
|
2539
2795
|
message: content
|
|
2540
|
-
}, { files
|
|
2796
|
+
}, { files, reason });
|
|
2541
2797
|
return createChannel(data, this.#context);
|
|
2542
2798
|
}
|
|
2543
2799
|
async fetchArchived(scope, options = {}) {
|
|
@@ -2631,7 +2887,7 @@ class EmojiManager extends Manager {
|
|
|
2631
2887
|
this.#guildId = guildId;
|
|
2632
2888
|
}
|
|
2633
2889
|
fetch(emojiId) {
|
|
2634
|
-
return this.fetchOnce(emojiId, async () => new
|
|
2890
|
+
return this.fetchOnce(emojiId, async () => new Emoji(await this.#rest.get(Routes.guildEmoji(this.#guildId, emojiId))), (emoji) => this.#merge(emojiId, emoji));
|
|
2635
2891
|
}
|
|
2636
2892
|
async fetchAll() {
|
|
2637
2893
|
const data = await this.#rest.get(Routes.guildEmoji(this.#guildId));
|
|
@@ -2653,12 +2909,12 @@ class EmojiManager extends Manager {
|
|
|
2653
2909
|
}
|
|
2654
2910
|
upsert(data) {
|
|
2655
2911
|
const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
|
|
2656
|
-
return this.#merge(key, new
|
|
2912
|
+
return this.#merge(key, new Emoji(data));
|
|
2657
2913
|
}
|
|
2658
2914
|
#merge(key, emoji) {
|
|
2659
2915
|
const existing = this.get(key);
|
|
2660
2916
|
if (existing) {
|
|
2661
|
-
|
|
2917
|
+
assignFields(existing, emoji);
|
|
2662
2918
|
return existing;
|
|
2663
2919
|
}
|
|
2664
2920
|
this.set(key, emoji);
|
|
@@ -2871,8 +3127,8 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2871
3127
|
guildId;
|
|
2872
3128
|
constructor(guildId, rest, context = () => {
|
|
2873
3129
|
return;
|
|
2874
|
-
}) {
|
|
2875
|
-
super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id);
|
|
3130
|
+
}, maxSize) {
|
|
3131
|
+
super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id, maxSize);
|
|
2876
3132
|
this.guildId = guildId;
|
|
2877
3133
|
this.#rest = rest;
|
|
2878
3134
|
this.#context = context;
|
|
@@ -3202,9 +3458,11 @@ class GuildManager extends ResourceManager {
|
|
|
3202
3458
|
map.set(guildId, manager = create());
|
|
3203
3459
|
return manager;
|
|
3204
3460
|
}
|
|
3205
|
-
|
|
3461
|
+
#maxMembers;
|
|
3462
|
+
constructor(rest, options = {}) {
|
|
3206
3463
|
super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
|
|
3207
3464
|
this.#rest = rest;
|
|
3465
|
+
this.#maxMembers = options.maxMembers;
|
|
3208
3466
|
}
|
|
3209
3467
|
bans(guildId) {
|
|
3210
3468
|
let manager = this.#bans.get(guildId);
|
|
@@ -3221,7 +3479,7 @@ class GuildManager extends ResourceManager {
|
|
|
3221
3479
|
members(guildId) {
|
|
3222
3480
|
let manager = this.#members.get(guildId);
|
|
3223
3481
|
if (!manager)
|
|
3224
|
-
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context));
|
|
3482
|
+
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context, this.#maxMembers));
|
|
3225
3483
|
return manager;
|
|
3226
3484
|
}
|
|
3227
3485
|
roles(guildId) {
|
|
@@ -3265,9 +3523,13 @@ class GuildManager extends ResourceManager {
|
|
|
3265
3523
|
const existing = this.get(guild.id);
|
|
3266
3524
|
if (!existing)
|
|
3267
3525
|
return this.upsert(guild);
|
|
3268
|
-
|
|
3526
|
+
const from = guild;
|
|
3527
|
+
const into = existing;
|
|
3528
|
+
for (const key of Object.keys(from)) {
|
|
3529
|
+
const value = from[key];
|
|
3269
3530
|
if (value !== undefined)
|
|
3270
|
-
|
|
3531
|
+
into[key] = value;
|
|
3532
|
+
}
|
|
3271
3533
|
return existing;
|
|
3272
3534
|
}
|
|
3273
3535
|
delete(id) {
|
|
@@ -3435,6 +3697,10 @@ var AuditLogEvent = {
|
|
|
3435
3697
|
AutoModerationBlockMessage: 143
|
|
3436
3698
|
};
|
|
3437
3699
|
// packages/managers/src/application.ts
|
|
3700
|
+
function commandPayload(command) {
|
|
3701
|
+
return "toJSON" in command && typeof command.toJSON === "function" ? command.toJSON() : command;
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3438
3704
|
class ApplicationCommandManager {
|
|
3439
3705
|
#rest;
|
|
3440
3706
|
#applicationId;
|
|
@@ -3446,13 +3712,13 @@ class ApplicationCommandManager {
|
|
|
3446
3712
|
return this.#rest.get(Routes.applicationCommands(this.#applicationId));
|
|
3447
3713
|
}
|
|
3448
3714
|
create(data) {
|
|
3449
|
-
return this.#rest.post(Routes.applicationCommands(this.#applicationId), data);
|
|
3715
|
+
return this.#rest.post(Routes.applicationCommands(this.#applicationId), commandPayload(data));
|
|
3450
3716
|
}
|
|
3451
3717
|
set(commands) {
|
|
3452
|
-
return this.#rest.put(Routes.applicationCommands(this.#applicationId), commands);
|
|
3718
|
+
return this.#rest.put(Routes.applicationCommands(this.#applicationId), commands.map(commandPayload));
|
|
3453
3719
|
}
|
|
3454
3720
|
edit(commandId, data) {
|
|
3455
|
-
return this.#rest.patch(Routes.applicationCommand(this.#applicationId, commandId), data);
|
|
3721
|
+
return this.#rest.patch(Routes.applicationCommand(this.#applicationId, commandId), commandPayload(data));
|
|
3456
3722
|
}
|
|
3457
3723
|
async delete(commandId) {
|
|
3458
3724
|
await this.#rest.delete(Routes.applicationCommand(this.#applicationId, commandId));
|
|
@@ -3461,13 +3727,13 @@ class ApplicationCommandManager {
|
|
|
3461
3727
|
return this.#rest.get(Routes.guildApplicationCommands(this.#applicationId, guildId));
|
|
3462
3728
|
}
|
|
3463
3729
|
createGuild(guildId, data) {
|
|
3464
|
-
return this.#rest.post(Routes.guildApplicationCommands(this.#applicationId, guildId), data);
|
|
3730
|
+
return this.#rest.post(Routes.guildApplicationCommands(this.#applicationId, guildId), commandPayload(data));
|
|
3465
3731
|
}
|
|
3466
3732
|
setGuild(guildId, commands) {
|
|
3467
|
-
return this.#rest.put(Routes.guildApplicationCommands(this.#applicationId, guildId), commands);
|
|
3733
|
+
return this.#rest.put(Routes.guildApplicationCommands(this.#applicationId, guildId), commands.map(commandPayload));
|
|
3468
3734
|
}
|
|
3469
3735
|
editGuild(guildId, commandId, data) {
|
|
3470
|
-
return this.#rest.patch(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId), data);
|
|
3736
|
+
return this.#rest.patch(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId), commandPayload(data));
|
|
3471
3737
|
}
|
|
3472
3738
|
async deleteGuild(guildId, commandId) {
|
|
3473
3739
|
await this.#rest.delete(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId));
|
|
@@ -3515,10 +3781,13 @@ class ChannelManager extends Manager {
|
|
|
3515
3781
|
return manager;
|
|
3516
3782
|
}
|
|
3517
3783
|
permissionOverwrites(channelId) {
|
|
3518
|
-
return new PermissionOverwriteManager(this.#rest, channelId, () =>
|
|
3784
|
+
return new PermissionOverwriteManager(this.#rest, channelId, () => {
|
|
3785
|
+
const channel = this.get(channelId);
|
|
3786
|
+
return channel && !channel.partial ? channel.permissionOverwrites : undefined;
|
|
3787
|
+
});
|
|
3519
3788
|
}
|
|
3520
3789
|
threads(channelId) {
|
|
3521
|
-
return new ThreadManager(this.#rest, this.#context, channelId);
|
|
3790
|
+
return new ThreadManager(this.#rest, this.#context, channelId, this.#allowedMentions);
|
|
3522
3791
|
}
|
|
3523
3792
|
fetch(channelId) {
|
|
3524
3793
|
return this.fetchOnce(channelId, async () => createChannel(await this.#rest.get(Routes.channel(channelId)), this.#context), (channel) => this.#merge(channel));
|
|
@@ -3532,7 +3801,7 @@ class ChannelManager extends Manager {
|
|
|
3532
3801
|
#merge(channel) {
|
|
3533
3802
|
const existing = this.get(channel.id);
|
|
3534
3803
|
if (existing && existing.type === channel.type) {
|
|
3535
|
-
|
|
3804
|
+
assignFields(existing, channel);
|
|
3536
3805
|
return existing;
|
|
3537
3806
|
}
|
|
3538
3807
|
this.set(channel.id, channel);
|
|
@@ -3542,9 +3811,14 @@ class ChannelManager extends Manager {
|
|
|
3542
3811
|
return this.set(channel.id, channel);
|
|
3543
3812
|
}
|
|
3544
3813
|
deleteGuildChannels(guildId) {
|
|
3814
|
+
const ids = [];
|
|
3815
|
+
this.cache.forEach((channel, id) => {
|
|
3816
|
+
if (channel.guildId === guildId)
|
|
3817
|
+
ids.push(id);
|
|
3818
|
+
});
|
|
3545
3819
|
let removed = 0;
|
|
3546
|
-
for (const
|
|
3547
|
-
if (
|
|
3820
|
+
for (const id of ids)
|
|
3821
|
+
if (this.delete(id))
|
|
3548
3822
|
removed++;
|
|
3549
3823
|
return removed;
|
|
3550
3824
|
}
|
|
@@ -3785,4 +4059,4 @@ export {
|
|
|
3785
4059
|
toRequest
|
|
3786
4060
|
};
|
|
3787
4061
|
|
|
3788
|
-
//# debugId=
|
|
4062
|
+
//# debugId=2CD7EF31353EB8CE64756E2164756E21
|