lunibee 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -24
- package/dist/builders/commands.d.ts +37 -0
- package/dist/builders/components.d.ts +127 -12
- package/dist/builders/embed.d.ts +3 -1
- package/dist/builders/index.d.ts +2 -2
- package/dist/builders/index.js +319 -16
- package/dist/builders/index.js.map +8 -7
- package/dist/collection/index.d.ts +36 -0
- package/dist/collection/index.js +110 -6
- package/dist/collection/index.js.map +4 -4
- package/dist/core/events.d.ts +69 -3
- package/dist/core/index.d.ts +158 -90
- package/dist/core/index.js +1543 -1169
- package/dist/core/index.js.map +24 -23
- package/dist/core/permissions.d.ts +112 -53
- package/dist/formatters/index.d.ts +43 -3
- package/dist/formatters/index.js +64 -1
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js.map +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3882 -1588
- package/dist/index.js.map +43 -35
- package/dist/managers/emoji.d.ts +38 -0
- package/dist/managers/guild.d.ts +141 -0
- package/dist/managers/index.d.ts +86 -75
- package/dist/managers/index.js +1084 -67
- package/dist/managers/index.js.map +21 -16
- package/dist/managers/message.d.ts +7 -12
- package/dist/managers/user.d.ts +20 -0
- package/dist/rest/index.d.ts +173 -1
- package/dist/rest/index.js +343 -47
- package/dist/rest/index.js.map +8 -6
- package/dist/rest/redis.d.ts +37 -0
- package/dist/rest/routes.d.ts +26 -1
- package/dist/rest/store.d.ts +38 -0
- package/dist/rest/webhook.d.ts +2 -2
- package/dist/sharding/cluster.d.ts +61 -0
- package/dist/sharding/index.d.ts +8 -0
- package/dist/sharding/index.js +289 -18
- package/dist/sharding/index.js.map +8 -7
- package/dist/structures/audit-log.d.ts +26 -0
- package/dist/structures/base.d.ts +131 -48
- package/dist/structures/embed.d.ts +65 -0
- package/dist/structures/index.d.ts +74 -26
- package/dist/structures/index.js +1528 -59
- package/dist/structures/index.js.map +14 -8
- package/dist/structures/interactions.d.ts +72 -17
- package/dist/structures/resources.d.ts +199 -7
- package/dist/types/index.d.ts +605 -84
- package/dist/types/index.js +71 -1
- package/dist/types/index.js.map +3 -3
- package/dist/utils/index.js.map +2 -2
- package/dist/voice/index.d.ts +88 -0
- package/dist/voice/index.js +204 -5
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/index.d.ts +40 -1
- package/dist/ws/index.js +105 -18
- package/dist/ws/index.js.map +4 -4
- package/package.json +16 -16
- package/dist/structures/permissions.d.ts +0 -73
package/dist/collection/index.js
CHANGED
|
@@ -31,19 +31,32 @@ class Cache {
|
|
|
31
31
|
this.#entries.delete(key);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
+
this.#entries.delete(key);
|
|
35
|
+
this.#entries.set(key, entry);
|
|
34
36
|
return entry.value;
|
|
35
37
|
}
|
|
36
38
|
has(key) {
|
|
37
|
-
|
|
39
|
+
const entry = this.#entries.get(key);
|
|
40
|
+
if (!entry)
|
|
41
|
+
return false;
|
|
42
|
+
if (entry.expiresAt > 0 && entry.expiresAt <= Date.now()) {
|
|
43
|
+
this.#entries.delete(key);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
38
47
|
}
|
|
39
48
|
set(key, value) {
|
|
40
49
|
const expiresAt = this.#ttl > 0 ? Date.now() + this.#ttl : 0;
|
|
41
50
|
this.#entries.delete(key);
|
|
42
51
|
this.#entries.set(key, { value, expiresAt });
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
if (this.#maxSize !== Infinity) {
|
|
53
|
+
while (this.#entries.size > this.#maxSize) {
|
|
54
|
+
const oldest = this.#entries.firstKey();
|
|
55
|
+
if (oldest !== undefined)
|
|
56
|
+
this.#entries.delete(oldest);
|
|
57
|
+
else
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
47
60
|
}
|
|
48
61
|
return this;
|
|
49
62
|
}
|
|
@@ -205,10 +218,101 @@ class Collection extends Map {
|
|
|
205
218
|
entry = [item[0], item[1]];
|
|
206
219
|
return entry;
|
|
207
220
|
}
|
|
221
|
+
union(other) {
|
|
222
|
+
const result = this.clone();
|
|
223
|
+
for (const [key, value] of other)
|
|
224
|
+
result.set(key, value);
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
intersection(other) {
|
|
228
|
+
const result = new Collection;
|
|
229
|
+
for (const [key, value] of this) {
|
|
230
|
+
if (other.has(key))
|
|
231
|
+
result.set(key, value);
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
difference(other) {
|
|
236
|
+
const result = new Collection;
|
|
237
|
+
for (const [key, value] of this) {
|
|
238
|
+
if (!other.has(key))
|
|
239
|
+
result.set(key, value);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
partition(predicate) {
|
|
244
|
+
const pass = new Collection;
|
|
245
|
+
const fail = new Collection;
|
|
246
|
+
for (const [key, value] of this) {
|
|
247
|
+
if (predicate(value, key, this))
|
|
248
|
+
pass.set(key, value);
|
|
249
|
+
else
|
|
250
|
+
fail.set(key, value);
|
|
251
|
+
}
|
|
252
|
+
return [pass, fail];
|
|
253
|
+
}
|
|
254
|
+
tap(fn) {
|
|
255
|
+
fn(this);
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
flatMap(transform) {
|
|
259
|
+
const result = [];
|
|
260
|
+
for (const [key, value] of this) {
|
|
261
|
+
for (const item of transform(value, key, this))
|
|
262
|
+
result.push(item);
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
reduce(fn, initialValue) {
|
|
267
|
+
let acc = initialValue;
|
|
268
|
+
for (const [key, value] of this)
|
|
269
|
+
acc = fn(acc, value, key, this);
|
|
270
|
+
return acc;
|
|
271
|
+
}
|
|
272
|
+
sorted(comparator) {
|
|
273
|
+
const decorated = [...this.entries()].map((entry, index) => ({
|
|
274
|
+
entry,
|
|
275
|
+
index
|
|
276
|
+
}));
|
|
277
|
+
if (comparator)
|
|
278
|
+
decorated.sort((x, y) => {
|
|
279
|
+
const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
|
|
280
|
+
return comparison !== 0 ? comparison : x.index - y.index;
|
|
281
|
+
});
|
|
282
|
+
const result = new Collection;
|
|
283
|
+
for (const { entry } of decorated)
|
|
284
|
+
result.set(entry[0], entry[1]);
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
random() {
|
|
288
|
+
const arr = [...this.values()];
|
|
289
|
+
if (!arr.length)
|
|
290
|
+
return;
|
|
291
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
292
|
+
}
|
|
293
|
+
randomKey() {
|
|
294
|
+
const arr = [...this.keys()];
|
|
295
|
+
if (!arr.length)
|
|
296
|
+
return;
|
|
297
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
298
|
+
}
|
|
299
|
+
at(index) {
|
|
300
|
+
const arr = [...this.values()];
|
|
301
|
+
const i = index < 0 ? arr.length + index : index;
|
|
302
|
+
return arr[i];
|
|
303
|
+
}
|
|
304
|
+
keyAt(index) {
|
|
305
|
+
const arr = [...this.keys()];
|
|
306
|
+
const i = index < 0 ? arr.length + index : index;
|
|
307
|
+
return arr[i];
|
|
308
|
+
}
|
|
309
|
+
toJSON() {
|
|
310
|
+
return [...this.entries()];
|
|
311
|
+
}
|
|
208
312
|
}
|
|
209
313
|
export {
|
|
210
314
|
Cache,
|
|
211
315
|
Collection
|
|
212
316
|
};
|
|
213
317
|
|
|
214
|
-
//# debugId=
|
|
318
|
+
//# debugId=F7AF9637261DF97664756E2164756E21
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/collection/src/cache.ts", "../../packages/collection/src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { Collection } from \"./index.js\";\r\n\r\n/** Cache policy for bounded resource storage. */\r\nexport interface CacheOptions {\r\n
|
|
6
|
-
"/** A lightweight keyed collection for Lunibee resource and application state. */\r\nexport class Collection<K, V> extends Map<K, V> {\r\n /** Returns the first stored value. */\r\n public first(): V | undefined {\r\n for (const value of this.values()) return value;\r\n return undefined;\r\n }\r\n /** Returns the first stored key. */\r\n public firstKey(): K | undefined {\r\n for (const key of this.keys()) return key;\r\n return undefined;\r\n }\r\n /** Returns the last stored value. */\r\n public last(): V | undefined {\r\n let value: V | undefined;\r\n for (const item of this.values()) value = item;\r\n return value;\r\n }\r\n /** Returns the last stored key. */\r\n public lastKey(): K | undefined {\r\n let key: K | undefined;\r\n for (const item of this.keys()) key = item;\r\n return key;\r\n }\r\n /** Finds the first value matching a predicate. */\r\n public find(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): V | undefined {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return value;\r\n }\r\n return undefined;\r\n }\r\n /** Returns all values matching a predicate. */\r\n public filter(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): Collection<K, V> {\r\n const result = new Collection<K, V>();\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) result.set(key, value);\r\n }\r\n return result;\r\n }\r\n /** Transforms every stored value into an array. */\r\n public map<T>(transform: (value: V, key: K, collection: this) => T): T[] {\r\n const result: T[] = [];\r\n for (const [key, value] of this) {\r\n result.push(transform(value, key, this));\r\n }\r\n return result;\r\n }\r\n /** Returns whether at least one stored value satisfies a predicate. */\r\n public some(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return true;\r\n }\r\n return false;\r\n }\r\n /** Returns whether every stored value satisfies a predicate. */\r\n public every(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n for (const [key, value] of this) {\r\n if (!predicate(value, key, this)) return false;\r\n }\r\n return true;\r\n }\r\n /** Runs a callback for each stored value. */\r\n public each(callback: (value: V, key: K, collection: this) => unknown): this {\r\n for (const [key, value] of this) {\r\n callback(value, key, this);\r\n }\r\n return this;\r\n }\r\n /** Returns an array containing all stored values. */\r\n public array(): V[] {\r\n return [...this.values()];\r\n }\r\n /** Returns an array containing all stored keys. */\r\n public keyArray(): K[] {\r\n return [...this.keys()];\r\n }\r\n /** Returns a plain array of entries. */\r\n public entriesArray(): [K, V][] {\r\n return [...this.entries()];\r\n }\r\n /** Returns a new collection with the same entries. */\r\n public clone(): Collection<K, V> {\r\n const copy = new Collection<K, V>();\r\n for (const [key, value] of this) copy.set(key, value);\r\n return copy;\r\n }\r\n /** Returns whether all supplied keys are present. */\r\n public hasAll(...keys: K[]): boolean {\r\n for (let i = 0; i < keys.length; i++) {\r\n if (!this.has(keys[i]!)) return false;\r\n }\r\n return true;\r\n }\r\n /** Returns whether at least one supplied key is present. */\r\n public hasAny(...keys: K[]): boolean {\r\n for (let i = 0; i < keys.length; i++) {\r\n if (this.has(keys[i]!)) return true;\r\n }\r\n return false;\r\n }\r\n /** Returns the first key whose value matches a predicate. */\r\n public findKey(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): K | undefined {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return key;\r\n }\r\n return undefined;\r\n }\r\n /** Returns whether a predicate matches at least one entry. */\r\n public someEntry(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n return this.some(predicate);\r\n }\r\n /** Removes every entry matching a predicate and returns the number removed. */\r\n public sweep(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): number {\r\n let removed = 0;\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this) && this.delete(key)) removed++;\r\n }\r\n return removed;\r\n }\r\n /** Returns the collection's first matching entry as a tuple. */\r\n public firstEntry(): [K, V] | undefined {\r\n for (const [key, value] of this) return [key, value];\r\n return undefined;\r\n }\r\n /** Returns the collection's last matching entry as a tuple. */\r\n public lastEntry(): [K, V] | undefined {\r\n let entry: [K, V] | undefined;\r\n for (const item of this) entry = [item[0], item[1]];\r\n return entry;\r\n }\r\n}\r\n\r\nexport { Cache } from \"./cache.js\";\r\nexport type { CacheOptions } from \"./cache.js\";\r\n"
|
|
5
|
+
"import { Collection } from \"./index.js\";\r\n\r\n/** Cache policy for bounded resource storage. */\r\nexport interface CacheOptions {\r\n /** Maximum number of entries retained. */\r\n maxSize?: number;\r\n /** Time-to-live in milliseconds. Omit to disable expiration. */\r\n ttl?: number;\r\n /** Sweep interval in milliseconds. */\r\n sweepInterval?: number;\r\n}\r\n\r\ntype Entry<V> = { value: V; expiresAt: number };\r\n\r\n/** Bounded cache with TTL expiration and explicit invalidation support. */\r\nexport class Cache<K, V> {\r\n readonly #entries = new Collection<K, Entry<V>>();\r\n readonly #maxSize: number;\r\n readonly #ttl: number;\r\n #timer?: ReturnType<typeof setInterval>;\r\n\r\n /** Creates a cache using the supplied retention policy. */\r\n public constructor(options: CacheOptions = {}) {\r\n this.#maxSize = options.maxSize ?? Infinity;\r\n this.#ttl = options.ttl ?? 0;\r\n if (\r\n (!Number.isInteger(this.#maxSize) && this.#maxSize !== Infinity) ||\r\n this.#maxSize < 1\r\n )\r\n throw new RangeError(\"Cache maxSize must be a positive integer.\");\r\n if (!Number.isFinite(this.#ttl) || this.#ttl < 0)\r\n throw new RangeError(\r\n \"Cache ttl must be a non-negative finite number.\",\r\n );\r\n if (this.#ttl > 0) {\r\n const interval =\r\n options.sweepInterval ?? Math.min(this.#ttl, 60_000);\r\n if (!Number.isFinite(interval) || interval < 1)\r\n throw new RangeError(\"Cache sweepInterval must be positive.\");\r\n this.#timer = setInterval(() => this.sweep(), interval);\r\n }\r\n }\r\n\r\n /** Number of currently live entries. */\r\n public get size(): number {\r\n this.#sweepExpired();\r\n return this.#entries.size;\r\n }\r\n /** Reads a live entry. */\r\n public get(key: K): V | undefined {\r\n const entry = this.#entries.get(key);\r\n if (!entry) return undefined;\r\n if (entry.expiresAt > 0 && entry.expiresAt <= Date.now()) {\r\n this.#entries.delete(key);\r\n return undefined;\r\n }\r\n // LRU Promotion: move to end of insertion order\r\n this.#entries.delete(key);\r\n this.#entries.set(key, entry);\r\n return entry.value;\r\n }\r\n /** Returns whether a live entry exists. */\r\n public has(key: K): boolean {\r\n const entry = this.#entries.get(key);\r\n if (!entry) return false;\r\n if (entry.expiresAt > 0 && entry.expiresAt <= Date.now()) {\r\n this.#entries.delete(key);\r\n return false;\r\n }\r\n return true;\r\n }\r\n /** Stores an entry and evicts the oldest entries when the bound is exceeded. */\r\n public set(key: K, value: V): this {\r\n const expiresAt = this.#ttl > 0 ? Date.now() + this.#ttl : 0;\r\n this.#entries.delete(key);\r\n this.#entries.set(key, { value, expiresAt });\r\n // Skip eviction entirely for unbounded caches (maxSize === Infinity).\r\n if (this.#maxSize !== Infinity) {\r\n while (this.#entries.size > this.#maxSize) {\r\n const oldest = this.#entries.firstKey();\r\n if (oldest !== undefined) this.#entries.delete(oldest);\r\n else break;\r\n }\r\n }\r\n return this;\r\n }\r\n /** Invalidates one key. */\r\n public delete(key: K): boolean {\r\n return this.#entries.delete(key);\r\n }\r\n /** Invalidates every cached resource. */\r\n public clear(): void {\r\n this.#entries.clear();\r\n }\r\n /** Invalidates every entry matching a predicate. */\r\n public invalidate(predicate: (value: V, key: K) => boolean): number {\r\n return this.#entries.sweep((entry, key) => predicate(entry.value, key));\r\n }\r\n /** Removes expired entries and returns the number removed. */\r\n public sweep(): number {\r\n return this.#entries.sweep((entry) => this.#expired(entry));\r\n }\r\n /** Stops the background sweeper and releases its timer. */\r\n public dispose(): void {\r\n if (this.#timer) clearInterval(this.#timer);\r\n this.#timer = undefined;\r\n }\r\n /** Returns live cached values. */\r\n public values(): V[] {\r\n this.#sweepExpired();\r\n return this.#entries.map((entry) => entry.value);\r\n }\r\n /** Returns live cached entries. */\r\n public entries(): [K, V][] {\r\n this.#sweepExpired();\r\n return this.#entries.map((entry, key) => [key, entry.value]);\r\n }\r\n #expired(entry: Entry<V>): boolean {\r\n return entry.expiresAt > 0 && entry.expiresAt <= Date.now();\r\n }\r\n #sweepExpired(): void {\r\n if (this.#ttl > 0) this.sweep();\r\n }\r\n}\r\n",
|
|
6
|
+
"/** A lightweight keyed collection for Lunibee resource and application state. */\r\nexport class Collection<K, V> extends Map<K, V> {\r\n /** Returns the first stored value. */\r\n public first(): V | undefined {\r\n for (const value of this.values()) return value;\r\n return undefined;\r\n }\r\n /** Returns the first stored key. */\r\n public firstKey(): K | undefined {\r\n for (const key of this.keys()) return key;\r\n return undefined;\r\n }\r\n /** Returns the last stored value. */\r\n public last(): V | undefined {\r\n let value: V | undefined;\r\n for (const item of this.values()) value = item;\r\n return value;\r\n }\r\n /** Returns the last stored key. */\r\n public lastKey(): K | undefined {\r\n let key: K | undefined;\r\n for (const item of this.keys()) key = item;\r\n return key;\r\n }\r\n /** Finds the first value matching a predicate. */\r\n public find(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): V | undefined {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return value;\r\n }\r\n return undefined;\r\n }\r\n /** Returns all values matching a predicate. */\r\n public filter(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): Collection<K, V> {\r\n const result = new Collection<K, V>();\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) result.set(key, value);\r\n }\r\n return result;\r\n }\r\n /** Transforms every stored value into an array. */\r\n public map<T>(transform: (value: V, key: K, collection: this) => T): T[] {\r\n const result: T[] = [];\r\n for (const [key, value] of this) {\r\n result.push(transform(value, key, this));\r\n }\r\n return result;\r\n }\r\n /** Returns whether at least one stored value satisfies a predicate. */\r\n public some(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return true;\r\n }\r\n return false;\r\n }\r\n /** Returns whether every stored value satisfies a predicate. */\r\n public every(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n for (const [key, value] of this) {\r\n if (!predicate(value, key, this)) return false;\r\n }\r\n return true;\r\n }\r\n /** Runs a callback for each stored value. */\r\n public each(\r\n callback: (value: V, key: K, collection: this) => unknown,\r\n ): this {\r\n for (const [key, value] of this) {\r\n callback(value, key, this);\r\n }\r\n return this;\r\n }\r\n /** Returns an array containing all stored values. */\r\n public array(): V[] {\r\n return [...this.values()];\r\n }\r\n /** Returns an array containing all stored keys. */\r\n public keyArray(): K[] {\r\n return [...this.keys()];\r\n }\r\n /** Returns a plain array of entries. */\r\n public entriesArray(): [K, V][] {\r\n return [...this.entries()];\r\n }\r\n /** Returns a new collection with the same entries. */\r\n public clone(): Collection<K, V> {\r\n const copy = new Collection<K, V>();\r\n for (const [key, value] of this) copy.set(key, value);\r\n return copy;\r\n }\r\n /** Returns whether all supplied keys are present. */\r\n public hasAll(...keys: K[]): boolean {\r\n for (let i = 0; i < keys.length; i++) {\r\n if (!this.has(keys[i]!)) return false;\r\n }\r\n return true;\r\n }\r\n /** Returns whether at least one supplied key is present. */\r\n public hasAny(...keys: K[]): boolean {\r\n for (let i = 0; i < keys.length; i++) {\r\n if (this.has(keys[i]!)) return true;\r\n }\r\n return false;\r\n }\r\n /** Returns the first key whose value matches a predicate. */\r\n public findKey(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): K | undefined {\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) return key;\r\n }\r\n return undefined;\r\n }\r\n /** Returns whether a predicate matches at least one entry. */\r\n public someEntry(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): boolean {\r\n return this.some(predicate);\r\n }\r\n /** Removes every entry matching a predicate and returns the number removed. */\r\n public sweep(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): number {\r\n let removed = 0;\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this) && this.delete(key)) removed++;\r\n }\r\n return removed;\r\n }\r\n /** Returns the collection's first matching entry as a tuple. */\r\n public firstEntry(): [K, V] | undefined {\r\n for (const [key, value] of this) return [key, value];\r\n return undefined;\r\n }\r\n /** Returns the collection's last matching entry as a tuple. */\r\n public lastEntry(): [K, V] | undefined {\r\n let entry: [K, V] | undefined;\r\n for (const item of this) entry = [item[0], item[1]];\r\n return entry;\r\n }\r\n /** Returns a new Collection containing elements from both collections. */\r\n public union(other: Collection<K, V>): Collection<K, V> {\r\n const result = this.clone();\r\n for (const [key, value] of other) result.set(key, value);\r\n return result;\r\n }\r\n /** Returns a new Collection containing only elements present in both collections. */\r\n public intersection(other: Collection<K, V>): Collection<K, V> {\r\n const result = new Collection<K, V>();\r\n for (const [key, value] of this) {\r\n if (other.has(key)) result.set(key, value);\r\n }\r\n return result;\r\n }\r\n /** Returns a new Collection containing elements present in this collection but not the other. */\r\n public difference(other: Collection<K, V>): Collection<K, V> {\r\n const result = new Collection<K, V>();\r\n for (const [key, value] of this) {\r\n if (!other.has(key)) result.set(key, value);\r\n }\r\n return result;\r\n }\r\n /** Splits the collection into two collections based on a predicate.\r\n * @returns `[passing, failing]` — entries satisfying the predicate, then those that don't.\r\n */\r\n public partition(\r\n predicate: (value: V, key: K, collection: this) => boolean,\r\n ): [Collection<K, V>, Collection<K, V>] {\r\n const pass = new Collection<K, V>();\r\n const fail = new Collection<K, V>();\r\n for (const [key, value] of this) {\r\n if (predicate(value, key, this)) pass.set(key, value);\r\n else fail.set(key, value);\r\n }\r\n return [pass, fail];\r\n }\r\n /** Calls `fn` with this collection and returns the collection unchanged.\r\n * Useful for inserting debug side-effects in a chain without breaking the flow.\r\n */\r\n public tap(fn: (collection: this) => unknown): this {\r\n fn(this);\r\n return this;\r\n }\r\n /** Maps every entry to an array of items and flattens the results. */\r\n public flatMap<T>(\r\n transform: (value: V, key: K, collection: this) => T[],\r\n ): T[] {\r\n const result: T[] = [];\r\n for (const [key, value] of this) {\r\n for (const item of transform(value, key, this)) result.push(item);\r\n }\r\n return result;\r\n }\r\n /** Reduces the collection to a single value. */\r\n public reduce<T>(\r\n fn: (accumulator: T, value: V, key: K, collection: this) => T,\r\n initialValue: T,\r\n ): T {\r\n let acc = initialValue;\r\n for (const [key, value] of this) acc = fn(acc, value, key, this);\r\n return acc;\r\n }\r\n /** Returns a new Collection with entries sorted by comparator (non-mutating).\r\n * Defaults to insertion order if no comparator is provided.\r\n */\r\n public sorted(\r\n comparator?: (a: V, b: V, aKey: K, bKey: K) => number,\r\n ): Collection<K, V> {\r\n // Decorate with the original insertion index and use it as a tiebreaker so\r\n // equal elements keep their insertion order (a stable sort independent of\r\n // the engine's Array.prototype.sort stability guarantees).\r\n const decorated = [...this.entries()].map((entry, index) => ({\r\n entry,\r\n index,\r\n }));\r\n if (comparator)\r\n decorated.sort((x, y) => {\r\n const comparison = comparator(\r\n x.entry[1],\r\n y.entry[1],\r\n x.entry[0],\r\n y.entry[0],\r\n );\r\n return comparison !== 0 ? comparison : x.index - y.index;\r\n });\r\n const result = new Collection<K, V>();\r\n for (const { entry } of decorated) result.set(entry[0], entry[1]);\r\n return result;\r\n }\r\n /** Returns a random value from the collection, or `undefined` if empty.\r\n * Uses `Math.random()` (fast, non-cryptographic) — do not use for security-sensitive\r\n * selection such as tokens or secrets. */\r\n public random(): V | undefined {\r\n const arr = [...this.values()];\r\n if (!arr.length) return undefined;\r\n return arr[Math.floor(Math.random() * arr.length)];\r\n }\r\n /** Returns a random key from the collection, or `undefined` if empty.\r\n * Uses `Math.random()` (fast, non-cryptographic) — do not use for security-sensitive\r\n * selection such as tokens or secrets. */\r\n public randomKey(): K | undefined {\r\n const arr = [...this.keys()];\r\n if (!arr.length) return undefined;\r\n return arr[Math.floor(Math.random() * arr.length)];\r\n }\r\n /** Returns the value at a given insertion-order index (supports negative indices). */\r\n public at(index: number): V | undefined {\r\n const arr = [...this.values()];\r\n const i = index < 0 ? arr.length + index : index;\r\n return arr[i];\r\n }\r\n /** Returns the key at a given insertion-order index (supports negative indices). */\r\n public keyAt(index: number): K | undefined {\r\n const arr = [...this.keys()];\r\n const i = index < 0 ? arr.length + index : index;\r\n return arr[i];\r\n }\r\n /** Serializes the collection to a plain `[key, value]` array. */\r\n public toJSON(): [K, V][] {\r\n return [...this.entries()];\r\n }\r\n}\r\n\r\nexport { Cache } from \"./cache.js\";\r\nexport type { CacheOptions } from \"./cache.js\";\r\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;AAeO,MAAM,MAAY;AAAA,
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";;AAeO,MAAM,MAAY;AAAA,EACZ,WAAW,IAAI;AAAA,EACf;AAAA,EACA;AAAA,EACT;AAAA,EAGO,WAAW,CAAC,UAAwB,CAAC,GAAG;AAAA,IAC3C,KAAK,WAAW,QAAQ,WAAW;AAAA,IACnC,KAAK,OAAO,QAAQ,OAAO;AAAA,IAC3B,IACK,CAAC,OAAO,UAAU,KAAK,QAAQ,KAAK,KAAK,aAAa,YACvD,KAAK,WAAW;AAAA,MAEhB,MAAM,IAAI,WAAW,2CAA2C;AAAA,IACpE,IAAI,CAAC,OAAO,SAAS,KAAK,IAAI,KAAK,KAAK,OAAO;AAAA,MAC3C,MAAM,IAAI,WACN,iDACJ;AAAA,IACJ,IAAI,KAAK,OAAO,GAAG;AAAA,MACf,MAAM,WACF,QAAQ,iBAAiB,KAAK,IAAI,KAAK,MAAM,KAAM;AAAA,MACvD,IAAI,CAAC,OAAO,SAAS,QAAQ,KAAK,WAAW;AAAA,QACzC,MAAM,IAAI,WAAW,uCAAuC;AAAA,MAChE,KAAK,SAAS,YAAY,MAAM,KAAK,MAAM,GAAG,QAAQ;AAAA,IAC1D;AAAA;AAAA,MAIO,IAAI,GAAW;AAAA,IACtB,KAAK,cAAc;AAAA,IACnB,OAAO,KAAK,SAAS;AAAA;AAAA,EAGlB,GAAG,CAAC,KAAuB;AAAA,IAC9B,MAAM,QAAQ,KAAK,SAAS,IAAI,GAAG;AAAA,IACnC,IAAI,CAAC;AAAA,MAAO;AAAA,IACZ,IAAI,MAAM,YAAY,KAAK,MAAM,aAAa,KAAK,IAAI,GAAG;AAAA,MACtD,KAAK,SAAS,OAAO,GAAG;AAAA,M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AAQ,CAAC;AAAA;AAEjC;",
|
|
9
|
+
"debugId": "F7AF9637261DF97664756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/core/events.d.ts
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
|
-
import type { ClientEvents } from "./index.js";
|
|
2
1
|
/** Names of events emitted by a Lunibee client. */
|
|
3
|
-
export
|
|
2
|
+
export declare enum ClientEvent {
|
|
3
|
+
Ready = "ready",
|
|
4
|
+
Resumed = "resumed",
|
|
5
|
+
InvalidSession = "invalidSession",
|
|
6
|
+
Raw = "raw",
|
|
7
|
+
Error = "error",
|
|
8
|
+
Open = "open",
|
|
9
|
+
Close = "close",
|
|
10
|
+
MessageCreate = "messageCreate",
|
|
11
|
+
MessageUpdate = "messageUpdate",
|
|
12
|
+
MessageDelete = "messageDelete",
|
|
13
|
+
MessageDeleteBulk = "messageDeleteBulk",
|
|
14
|
+
MessageReactionAdd = "messageReactionAdd",
|
|
15
|
+
MessageReactionRemove = "messageReactionRemove",
|
|
16
|
+
MessageReactionRemoveAll = "messageReactionRemoveAll",
|
|
17
|
+
MessageReactionRemoveEmoji = "messageReactionRemoveEmoji",
|
|
18
|
+
MessagePollVoteAdd = "messagePollVoteAdd",
|
|
19
|
+
MessagePollVoteRemove = "messagePollVoteRemove",
|
|
20
|
+
GuildCreate = "guildCreate",
|
|
21
|
+
GuildUpdate = "guildUpdate",
|
|
22
|
+
GuildDelete = "guildDelete",
|
|
23
|
+
GuildAvailable = "guildAvailable",
|
|
24
|
+
GuildUnavailable = "guildUnavailable",
|
|
25
|
+
GuildMemberAdd = "guildMemberAdd",
|
|
26
|
+
GuildMemberUpdate = "guildMemberUpdate",
|
|
27
|
+
GuildMemberRemove = "guildMemberRemove",
|
|
28
|
+
GuildMembersChunk = "guildMembersChunk",
|
|
29
|
+
GuildBanAdd = "guildBanAdd",
|
|
30
|
+
GuildBanRemove = "guildBanRemove",
|
|
31
|
+
GuildRoleCreate = "guildRoleCreate",
|
|
32
|
+
GuildRoleUpdate = "guildRoleUpdate",
|
|
33
|
+
GuildRoleDelete = "guildRoleDelete",
|
|
34
|
+
GuildEmojisUpdate = "guildEmojisUpdate",
|
|
35
|
+
GuildStickersUpdate = "guildStickersUpdate",
|
|
36
|
+
GuildIntegrationsUpdate = "guildIntegrationsUpdate",
|
|
37
|
+
GuildScheduledEventCreate = "guildScheduledEventCreate",
|
|
38
|
+
GuildScheduledEventUpdate = "guildScheduledEventUpdate",
|
|
39
|
+
GuildScheduledEventDelete = "guildScheduledEventDelete",
|
|
40
|
+
GuildScheduledEventUserAdd = "guildScheduledEventUserAdd",
|
|
41
|
+
GuildScheduledEventUserRemove = "guildScheduledEventUserRemove",
|
|
42
|
+
AutoModerationRuleCreate = "autoModerationRuleCreate",
|
|
43
|
+
AutoModerationRuleUpdate = "autoModerationRuleUpdate",
|
|
44
|
+
AutoModerationRuleDelete = "autoModerationRuleDelete",
|
|
45
|
+
AutoModerationActionExecution = "autoModerationActionExecution",
|
|
46
|
+
ChannelCreate = "channelCreate",
|
|
47
|
+
ChannelUpdate = "channelUpdate",
|
|
48
|
+
ChannelDelete = "channelDelete",
|
|
49
|
+
ChannelPinsUpdate = "channelPinsUpdate",
|
|
50
|
+
ThreadCreate = "threadCreate",
|
|
51
|
+
ThreadUpdate = "threadUpdate",
|
|
52
|
+
ThreadDelete = "threadDelete",
|
|
53
|
+
ThreadListSync = "threadListSync",
|
|
54
|
+
ThreadMembersUpdate = "threadMembersUpdate",
|
|
55
|
+
ThreadMemberUpdate = "threadMemberUpdate",
|
|
56
|
+
StageInstanceCreate = "stageInstanceCreate",
|
|
57
|
+
StageInstanceUpdate = "stageInstanceUpdate",
|
|
58
|
+
StageInstanceDelete = "stageInstanceDelete",
|
|
59
|
+
InviteCreate = "inviteCreate",
|
|
60
|
+
InviteDelete = "inviteDelete",
|
|
61
|
+
WebhooksUpdate = "webhooksUpdate",
|
|
62
|
+
VoiceStateUpdate = "voiceStateUpdate",
|
|
63
|
+
VoiceServerUpdate = "voiceServerUpdate",
|
|
64
|
+
PresenceUpdate = "presenceUpdate",
|
|
65
|
+
TypingStart = "typingStart",
|
|
66
|
+
InteractionCreate = "interactionCreate"
|
|
67
|
+
}
|
|
68
|
+
/** Names of events emitted by a Lunibee client. */
|
|
69
|
+
export type ClientEventName = keyof import("./index.js").ClientEvents;
|
|
4
70
|
/** Listener signature for a Lunibee client event. */
|
|
5
|
-
export type ClientListener<K extends
|
|
71
|
+
export type ClientListener<K extends ClientEventName> = (...args: import("./index.js").ClientEvents[K]) => unknown;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,58 +1,12 @@
|
|
|
1
1
|
export { Permission, Permissions, PermissionFlagsBits, PermissionSet, PermissionsBitField, PermissionOverwriteType, type PermissionName, } from "./permissions.js";
|
|
2
|
+
export { ClientEvent, type ClientEventName, type ClientListener, } from "./events.js";
|
|
3
|
+
export { Collector, type CollectorOptions } from "./collector.js";
|
|
4
|
+
export { GatewayIntentBits, IntentBits, Intents, resolveGatewayIntents, type GatewayIntentResolvable, } from "@lunibee/types";
|
|
2
5
|
import { ApplicationCommandManager, ChannelManager, GuildManager, UserManager } from "@lunibee/managers";
|
|
3
6
|
import { REST } from "@lunibee/rest";
|
|
4
7
|
import { Channel, Message, Interaction, type InteractionClient } from "@lunibee/structures";
|
|
5
8
|
import { Gateway } from "@lunibee/ws";
|
|
6
|
-
import type { APIChannel, APIGuild, APIGuildMember, APIGuildRoleEvent, APIGuildRoleDeleteEvent, APIGuildBanEvent, APIGuildEmojisUpdateEvent, APIMessageDeleteBulkEvent, APIMessageDeleteEvent, APIMessageReactionEvent, APIThreadEvent, ClientOptions, ClientUser } from "@lunibee/types";
|
|
7
|
-
/** Events emitted by the Lunibee client. */
|
|
8
|
-
export interface ClientEvents {
|
|
9
|
-
/** Client is ready. */ ready: [ClientUser];
|
|
10
|
-
/** Raw gateway dispatch envelope. */ raw: [{
|
|
11
|
-
event: string;
|
|
12
|
-
data: unknown;
|
|
13
|
-
}];
|
|
14
|
-
/** Normalized client error. */ error: [Error];
|
|
15
|
-
/** Gateway opened. */ open: [];
|
|
16
|
-
/** Gateway closed. */ close: [{
|
|
17
|
-
code: number;
|
|
18
|
-
action: string;
|
|
19
|
-
}];
|
|
20
|
-
/** Message created. */ messageCreate: [Message];
|
|
21
|
-
/** Message updated. */ messageUpdate: [Message];
|
|
22
|
-
/** Message deleted. */ messageDelete: [APIMessageDeleteEvent];
|
|
23
|
-
/** Messages deleted in bulk. */ messageDeleteBulk: [
|
|
24
|
-
APIMessageDeleteBulkEvent
|
|
25
|
-
];
|
|
26
|
-
/** Guild became available. */ guildCreate: [APIGuild];
|
|
27
|
-
/** Guild updated. */ guildUpdate: [APIGuild];
|
|
28
|
-
/** Guild became unavailable or was removed. */ guildDelete: [
|
|
29
|
-
{
|
|
30
|
-
id: string;
|
|
31
|
-
unavailable?: boolean;
|
|
32
|
-
}
|
|
33
|
-
];
|
|
34
|
-
/** Channel created. */ channelCreate: [Channel];
|
|
35
|
-
/** Channel updated. */ channelUpdate: [Channel];
|
|
36
|
-
/** Channel deleted. */ channelDelete: [APIChannel];
|
|
37
|
-
/** Thread created. */ threadCreate: [Channel];
|
|
38
|
-
/** Thread updated. */ threadUpdate: [Channel];
|
|
39
|
-
/** Thread deleted. */ threadDelete: [APIThreadEvent];
|
|
40
|
-
/** Guild member added. */ guildMemberAdd: [APIGuildMember];
|
|
41
|
-
/** Guild member updated. */ guildMemberUpdate: [APIGuildMember];
|
|
42
|
-
/** Guild member removed. */ guildMemberRemove: [APIGuildMember];
|
|
43
|
-
/** Reaction added. */ messageReactionAdd: [APIMessageReactionEvent];
|
|
44
|
-
/** Reaction removed. */ messageReactionRemove: [APIMessageReactionEvent];
|
|
45
|
-
/** All reactions removed. */ messageReactionRemoveAll: [
|
|
46
|
-
APIMessageDeleteEvent
|
|
47
|
-
];
|
|
48
|
-
/** Interaction created. */ interactionCreate: [Interaction];
|
|
49
|
-
/** Guild role created. */ guildRoleCreate: [APIGuildRoleEvent];
|
|
50
|
-
/** Guild role updated. */ guildRoleUpdate: [APIGuildRoleEvent];
|
|
51
|
-
/** Guild role deleted. */ guildRoleDelete: [APIGuildRoleDeleteEvent];
|
|
52
|
-
/** Guild ban added. */ guildBanAdd: [APIGuildBanEvent];
|
|
53
|
-
/** Guild ban removed. */ guildBanRemove: [APIGuildBanEvent];
|
|
54
|
-
/** Guild emojis updated. */ guildEmojisUpdate: [APIGuildEmojisUpdateEvent];
|
|
55
|
-
}
|
|
9
|
+
import type { APIChannel, APIGuild, APIGuildMember, APIGuildRoleEvent, APIGuildRoleDeleteEvent, APIGuildBanEvent, APIGuildEmojisUpdateEvent, APIGuildStickersUpdateEvent, APIMessageDeleteBulkEvent, APIMessageDeleteEvent, APIMessageReactionEvent, APIMessageReactionRemoveEmojiEvent, APIThreadEvent, APIThreadListSync, APIThreadMembersUpdate, APIVoiceState, APIVoiceServerUpdate, APIPresenceUpdate, APITypingStart, APIInviteCreate, APIInviteDelete, APIWebhooksUpdate, APIAutoModerationRule, APIAutoModerationActionExecution, APIGuildScheduledEvent, APIGuildScheduledEventUserEvent, APIStageInstance, APIChannelPinsUpdate, APIGuildMembersChunk, APIMessagePollVoteEvent, APIThreadMember, ClientOptions, ClientUser } from "@lunibee/types";
|
|
56
10
|
/** Lifecycle state of a client. */
|
|
57
11
|
export type ClientState = "idle" | "connecting" | "ready" | "destroyed";
|
|
58
12
|
type Listener<T extends unknown[]> = (...args: T) => unknown;
|
|
@@ -61,51 +15,165 @@ declare class EventEmitter<Events extends {
|
|
|
61
15
|
[K in keyof Events]: unknown[];
|
|
62
16
|
}> {
|
|
63
17
|
#private;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
|
|
18
|
+
on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this;
|
|
19
|
+
once<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this;
|
|
20
|
+
off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this;
|
|
21
|
+
/** Alias of {@link off}, provided for Node.js/Discord.js familiarity. */
|
|
22
|
+
removeListener<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this;
|
|
23
|
+
removeAllListeners<K extends keyof Events>(event?: K): this;
|
|
24
|
+
protected emit<K extends keyof Events>(event: K, ...args: Events[K]): boolean;
|
|
69
25
|
}
|
|
70
26
|
/** Main Lunibee Discord client. */
|
|
71
27
|
export declare class Client extends EventEmitter<ClientEvents> implements InteractionClient {
|
|
72
28
|
#private;
|
|
73
29
|
readonly options: ClientOptions;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
30
|
+
readonly rest: REST;
|
|
31
|
+
readonly users: UserManager;
|
|
32
|
+
readonly guilds: GuildManager;
|
|
33
|
+
readonly channels: ChannelManager;
|
|
34
|
+
readonly application: {
|
|
35
|
+
commands: ApplicationCommandManager;
|
|
80
36
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/**
|
|
37
|
+
get ws(): Gateway;
|
|
38
|
+
get gateway(): Gateway;
|
|
39
|
+
user?: ClientUser;
|
|
40
|
+
readyAt?: Date;
|
|
41
|
+
state: ClientState;
|
|
42
|
+
/**
|
|
43
|
+
* The bot token this client is authenticated with, or `null` once the
|
|
44
|
+
* client has been destroyed. Mirrors `Client#token` in Discord.js.
|
|
45
|
+
*/
|
|
46
|
+
get token(): string | null;
|
|
87
47
|
get uptime(): number | null;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
48
|
+
get ping(): number;
|
|
49
|
+
/** Whether the client is ready and connected. */
|
|
50
|
+
isReady(): boolean;
|
|
51
|
+
/** Sets the bot's presence / status. @param data Presence payload. @returns Whether the payload was sent. */
|
|
52
|
+
setPresence(data: import("@lunibee/types").GatewayPresence): boolean;
|
|
53
|
+
/** Sends a voice state update. @param data Voice state payload. @returns Whether it was sent. */
|
|
54
|
+
setVoiceState(data: Record<string, unknown>): boolean;
|
|
55
|
+
/** Requests guild members. @param data Guild member request payload. @returns Whether it was sent. */
|
|
56
|
+
requestGuildMembers(data: Record<string, unknown>): boolean;
|
|
57
|
+
constructor(options: ClientOptions);
|
|
58
|
+
/**
|
|
59
|
+
* Convenience method to connect the bot to Discord.
|
|
60
|
+
* Optionally overrides the configured token.
|
|
61
|
+
* @param token Optional token override.
|
|
62
|
+
* @returns The token used to log in.
|
|
63
|
+
* @throws {TypeError} If the resulting token is empty.
|
|
64
|
+
*/
|
|
65
|
+
login(token?: string): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Destroys the client, permanently closing the Gateway connection.
|
|
68
|
+
*/
|
|
69
|
+
destroy(): void;
|
|
70
|
+
postInteractionResponse(id: string, token: string, response: import("@lunibee/structures").InteractionResponse): Promise<unknown>;
|
|
71
|
+
editInteractionReply(token: string, data: Record<string, unknown>): Promise<unknown>;
|
|
72
|
+
deleteInteractionReply(token: string): Promise<void>;
|
|
73
|
+
followUpInteraction(token: string, data: Record<string, unknown>): Promise<unknown>;
|
|
74
|
+
/** Fetches a webhook from Discord. */
|
|
75
|
+
fetchWebhook(id: string, token?: string): Promise<Record<string, unknown>>;
|
|
76
|
+
/** Fetches a guild preview from Discord. */
|
|
77
|
+
fetchGuildPreview(guildId: string): Promise<Record<string, unknown>>;
|
|
78
|
+
/** Fetches the voice regions from Discord. */
|
|
79
|
+
fetchVoiceRegions(): Promise<Record<string, unknown>[]>;
|
|
80
|
+
/** Fetches an invite from Discord. */
|
|
81
|
+
fetchInvite(code: string, options?: {
|
|
82
|
+
withCounts?: boolean;
|
|
83
|
+
withExpiration?: boolean;
|
|
84
|
+
guildScheduledEventId?: string;
|
|
85
|
+
}): Promise<Record<string, unknown>>;
|
|
86
|
+
/** Fetches a sticker from Discord. */
|
|
87
|
+
fetchSticker(id: string): Promise<Record<string, unknown>>;
|
|
88
|
+
/** Fetches premium sticker packs from Discord. */
|
|
89
|
+
fetchPremiumStickerPacks(): Promise<Record<string, unknown>>;
|
|
90
|
+
/** Fetches a guild template from Discord. */
|
|
91
|
+
fetchGuildTemplate(code: string): Promise<Record<string, unknown>>;
|
|
92
|
+
/** Generates an invite link for this client. */
|
|
93
|
+
generateInvite(options?: {
|
|
94
|
+
scopes?: string[];
|
|
95
|
+
permissions?: string | bigint;
|
|
96
|
+
}): string;
|
|
101
97
|
}
|
|
102
|
-
export
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
export type ClientEvents = {
|
|
99
|
+
ready: [user: ClientUser];
|
|
100
|
+
resumed: [];
|
|
101
|
+
invalidSession: [isRecoverable: boolean];
|
|
102
|
+
raw: [data: {
|
|
103
|
+
event: string;
|
|
104
|
+
data: unknown;
|
|
105
|
+
}];
|
|
106
|
+
error: [error: Error];
|
|
107
|
+
open: [];
|
|
108
|
+
close: [data: {
|
|
109
|
+
code: number;
|
|
110
|
+
action: string;
|
|
111
|
+
}];
|
|
112
|
+
messageCreate: [message: Message];
|
|
113
|
+
messageUpdate: [message: Message];
|
|
114
|
+
messageDelete: [data: APIMessageDeleteEvent];
|
|
115
|
+
messageDeleteBulk: [data: APIMessageDeleteBulkEvent];
|
|
116
|
+
messageReactionAdd: [data: APIMessageReactionEvent];
|
|
117
|
+
messageReactionRemove: [data: APIMessageReactionEvent];
|
|
118
|
+
messageReactionRemoveAll: [data: APIMessageDeleteEvent];
|
|
119
|
+
messageReactionRemoveEmoji: [data: APIMessageReactionRemoveEmojiEvent];
|
|
120
|
+
messagePollVoteAdd: [data: APIMessagePollVoteEvent];
|
|
121
|
+
messagePollVoteRemove: [data: APIMessagePollVoteEvent];
|
|
122
|
+
guildCreate: [data: APIGuild];
|
|
123
|
+
guildUpdate: [data: APIGuild];
|
|
124
|
+
guildDelete: [data: {
|
|
125
|
+
id: string;
|
|
126
|
+
unavailable?: boolean;
|
|
127
|
+
}];
|
|
128
|
+
guildAvailable: [data: APIGuild & {
|
|
129
|
+
unavailable?: boolean;
|
|
130
|
+
}];
|
|
131
|
+
guildUnavailable: [data: {
|
|
132
|
+
id: string;
|
|
133
|
+
unavailable?: boolean;
|
|
134
|
+
}];
|
|
135
|
+
guildMemberAdd: [member: APIGuildMember];
|
|
136
|
+
guildMemberUpdate: [member: APIGuildMember];
|
|
137
|
+
guildMemberRemove: [member: APIGuildMember];
|
|
138
|
+
guildMembersChunk: [data: APIGuildMembersChunk];
|
|
139
|
+
guildBanAdd: [data: APIGuildBanEvent];
|
|
140
|
+
guildBanRemove: [data: APIGuildBanEvent];
|
|
141
|
+
guildRoleCreate: [data: APIGuildRoleEvent];
|
|
142
|
+
guildRoleUpdate: [data: APIGuildRoleEvent];
|
|
143
|
+
guildRoleDelete: [data: APIGuildRoleDeleteEvent];
|
|
144
|
+
guildEmojisUpdate: [data: APIGuildEmojisUpdateEvent];
|
|
145
|
+
guildStickersUpdate: [data: APIGuildStickersUpdateEvent];
|
|
146
|
+
guildIntegrationsUpdate: [data: {
|
|
147
|
+
guild_id: string;
|
|
148
|
+
}];
|
|
149
|
+
guildScheduledEventCreate: [data: APIGuildScheduledEvent];
|
|
150
|
+
guildScheduledEventUpdate: [data: APIGuildScheduledEvent];
|
|
151
|
+
guildScheduledEventDelete: [data: APIGuildScheduledEvent];
|
|
152
|
+
guildScheduledEventUserAdd: [data: APIGuildScheduledEventUserEvent];
|
|
153
|
+
guildScheduledEventUserRemove: [data: APIGuildScheduledEventUserEvent];
|
|
154
|
+
autoModerationRuleCreate: [data: APIAutoModerationRule];
|
|
155
|
+
autoModerationRuleUpdate: [data: APIAutoModerationRule];
|
|
156
|
+
autoModerationRuleDelete: [data: APIAutoModerationRule];
|
|
157
|
+
autoModerationActionExecution: [data: APIAutoModerationActionExecution];
|
|
158
|
+
channelCreate: [channel: Channel];
|
|
159
|
+
channelUpdate: [channel: Channel];
|
|
160
|
+
channelDelete: [data: APIChannel];
|
|
161
|
+
channelPinsUpdate: [data: APIChannelPinsUpdate];
|
|
162
|
+
threadCreate: [channel: Channel];
|
|
163
|
+
threadUpdate: [channel: Channel];
|
|
164
|
+
threadDelete: [data: APIThreadEvent];
|
|
165
|
+
threadListSync: [data: APIThreadListSync];
|
|
166
|
+
threadMembersUpdate: [data: APIThreadMembersUpdate];
|
|
167
|
+
threadMemberUpdate: [data: APIThreadMember];
|
|
168
|
+
stageInstanceCreate: [data: APIStageInstance];
|
|
169
|
+
stageInstanceUpdate: [data: APIStageInstance];
|
|
170
|
+
stageInstanceDelete: [data: APIStageInstance];
|
|
171
|
+
inviteCreate: [data: APIInviteCreate];
|
|
172
|
+
inviteDelete: [data: APIInviteDelete];
|
|
173
|
+
webhooksUpdate: [data: APIWebhooksUpdate];
|
|
174
|
+
voiceStateUpdate: [data: APIVoiceState];
|
|
175
|
+
voiceServerUpdate: [data: APIVoiceServerUpdate];
|
|
176
|
+
presenceUpdate: [data: APIPresenceUpdate];
|
|
177
|
+
typingStart: [data: APITypingStart];
|
|
178
|
+
interactionCreate: [interaction: Interaction];
|
|
179
|
+
};
|