@discordeno/utils 19.0.0-next.c32e90e → 19.0.0-next.c460c88
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 +1 -1
- package/dist/bucket.d.ts +36 -48
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +72 -72
- package/dist/bucket.js.map +1 -1
- package/dist/builders/embeds.d.ts +146 -0
- package/dist/builders/embeds.d.ts.map +1 -0
- package/dist/builders/embeds.js +295 -0
- package/dist/builders/embeds.js.map +1 -0
- package/dist/builders.d.ts +4 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +5 -0
- package/dist/builders.js.map +1 -0
- package/dist/casing.d.ts.map +1 -1
- package/dist/casing.js +2 -2
- package/dist/casing.js.map +1 -1
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +1 -5
- package/dist/colors.js.map +1 -1
- package/dist/images.js +2 -2
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +8 -8
- package/dist/logger.js.map +1 -1
- package/dist/oauth2.d.ts +58 -0
- package/dist/oauth2.d.ts.map +1 -0
- package/dist/oauth2.js +16 -0
- package/dist/oauth2.js.map +1 -0
- package/dist/token.d.ts +1 -1
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +8 -3
- package/dist/token.js.map +1 -1
- package/dist/typeguards.d.ts +2 -1
- package/dist/typeguards.d.ts.map +1 -1
- package/dist/typeguards.js +3 -0
- package/dist/typeguards.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/package.json +13 -12
- package/dist/files.d.ts +0 -4
- package/dist/files.d.ts.map +0 -1
- package/dist/files.js +0 -41
- package/dist/files.js.map +0 -1
package/README.md
CHANGED
|
@@ -149,6 +149,6 @@ and unofficial templates:
|
|
|
149
149
|
|
|
150
150
|
## Links
|
|
151
151
|
|
|
152
|
-
- [Website](https://discordeno.
|
|
152
|
+
- [Website](https://discordeno.js.org/)
|
|
153
153
|
- [Documentation](https://doc.deno.land/https/deno.land/x/discordeno/mod.ts)
|
|
154
154
|
- [Discord](https://discord.com/invite/5vBgXk3UcZ)
|
package/dist/bucket.d.ts
CHANGED
|
@@ -1,55 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Useful for rate limiting purposes.
|
|
4
|
-
* This uses `performance.now()` instead of `Date.now()` for higher accuracy.
|
|
5
|
-
*
|
|
6
|
-
* NOTE: This bucket is lazy, means it only updates when a related method is called.
|
|
7
|
-
*/
|
|
8
|
-
export interface LeakyBucket {
|
|
9
|
-
/** How many tokens this bucket can hold. */
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class LeakyBucket implements LeakyBucketOptions {
|
|
10
3
|
max: number;
|
|
11
|
-
/** Amount of tokens gained per interval.
|
|
12
|
-
* If bigger than `max` it will be pressed to `max`.
|
|
13
|
-
*/
|
|
14
|
-
refillAmount: number;
|
|
15
|
-
/** Interval at which the bucket gains tokens. */
|
|
16
4
|
refillInterval: number;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
refillAmount: number;
|
|
6
|
+
/** The amount of requests that have been used up already. */
|
|
7
|
+
used: number;
|
|
8
|
+
/** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */
|
|
9
|
+
queue: Array<(value: void | PromiseLike<void>) => void>;
|
|
10
|
+
/** Whether or not the queue is already processing. */
|
|
11
|
+
processing: boolean;
|
|
12
|
+
/** The timeout id for the timer to reduce the used amount by the refill amount. */
|
|
13
|
+
timeoutId?: NodeJS.Timeout;
|
|
14
|
+
/** The timestamp in milliseconds when the next refill is scheduled. */
|
|
15
|
+
refillsAt?: number;
|
|
16
|
+
constructor(options?: LeakyBucketOptions);
|
|
17
|
+
/** The amount of requests that still remain. */
|
|
18
|
+
get remaining(): number;
|
|
19
|
+
/** Refills the bucket as needed. */
|
|
20
|
+
refillBucket(): void;
|
|
21
|
+
/** Begin processing the queue. */
|
|
22
|
+
processQueue(): Promise<void>;
|
|
23
|
+
/** Pauses the execution until the request is available to be made. */
|
|
24
|
+
acquire(highPriority?: boolean): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface LeakyBucketOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Max requests allowed at once.
|
|
29
|
+
* @default 1
|
|
32
30
|
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
31
|
+
max?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Interval in milliseconds between refills.
|
|
34
|
+
* @default 5000
|
|
36
35
|
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
36
|
+
refillInterval?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Amount of requests to refill at each interval.
|
|
39
|
+
* @default 1
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
refillAmount?: number;
|
|
42
42
|
}
|
|
43
|
-
export declare function createLeakyBucket({ max, refillInterval, refillAmount, tokens, waiting, ...rest }: Omit<PickPartial<LeakyBucket, 'max' | 'refillInterval' | 'refillAmount'>, 'tokens'> & {
|
|
44
|
-
/** Current tokens in the bucket.
|
|
45
|
-
* @default max
|
|
46
|
-
*/
|
|
47
|
-
tokens?: number;
|
|
48
|
-
}): LeakyBucket;
|
|
49
|
-
/** Update the tokens of that bucket.
|
|
50
|
-
* @returns {number} The amount of current available tokens.
|
|
51
|
-
*/
|
|
52
|
-
export declare function updateTokens(bucket: LeakyBucket): number;
|
|
53
|
-
export declare function nextRefill(bucket: LeakyBucket): number;
|
|
54
|
-
export declare function acquire(bucket: LeakyBucket, amount: number, highPriority?: boolean): Promise<void>;
|
|
55
43
|
//# sourceMappingURL=bucket.d.ts.map
|
package/dist/bucket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bucket.d.ts","sourceRoot":"","sources":["../src/bucket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bucket.d.ts","sourceRoot":"","sources":["../src/bucket.ts"],"names":[],"mappings":";AAGA,qBAAa,WAAY,YAAW,kBAAkB;IACpD,GAAG,EAAE,MAAM,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IAEpB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAI;IAChB,4FAA4F;IAC5F,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAK;IAC5D,sDAAsD;IACtD,UAAU,EAAE,OAAO,CAAQ;IAC3B,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;IAC1B,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAA;gBAEN,OAAO,CAAC,EAAE,kBAAkB;IAMxC,gDAAgD;IAChD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,oCAAoC;IACpC,YAAY,IAAI,IAAI;IAkBpB,kCAAkC;IAC5B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAmDnC,sEAAsE;IAChE,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAWrD;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
package/dist/bucket.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
+
import logger from './logger.js';
|
|
1
2
|
import { delay } from './utils.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
3
|
+
export class LeakyBucket {
|
|
4
|
+
constructor(options){
|
|
5
|
+
/** The amount of requests that have been used up already. */ this.used = 0;
|
|
6
|
+
/** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */ this.queue = [];
|
|
7
|
+
/** Whether or not the queue is already processing. */ this.processing = false;
|
|
8
|
+
this.max = options?.max ?? 1;
|
|
9
|
+
this.refillAmount = options?.refillAmount ? options.refillAmount > this.max ? this.max : options.refillAmount : 1;
|
|
10
|
+
this.refillInterval = options?.refillInterval ?? 5000;
|
|
11
|
+
}
|
|
12
|
+
/** The amount of requests that still remain. */ get remaining() {
|
|
13
|
+
return this.max < this.used ? 0 : this.max - this.used;
|
|
14
|
+
}
|
|
15
|
+
/** Refills the bucket as needed. */ refillBucket() {
|
|
16
|
+
logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`);
|
|
17
|
+
// Lower the used amount by the refill amount
|
|
18
|
+
this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
|
|
19
|
+
// Reset the refillsAt timestamp since it just got refilled
|
|
20
|
+
this.refillsAt = undefined;
|
|
21
|
+
// Reset the timeoutId
|
|
22
|
+
clearTimeout(this.timeoutId);
|
|
23
|
+
this.timeoutId = undefined;
|
|
24
|
+
if (this.used > 0) {
|
|
25
|
+
this.timeoutId = setTimeout(()=>{
|
|
26
|
+
this.refillBucket();
|
|
27
|
+
}, this.refillInterval);
|
|
28
|
+
this.refillsAt = Date.now() + this.refillInterval;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Begin processing the queue. */ async processQueue() {
|
|
32
|
+
logger.debug('[LeakyBucket] Processing queue');
|
|
33
|
+
// There is already a queue that is processing
|
|
34
|
+
if (this.processing) return logger.debug('[LeakyBucket] Queue is already processing.');
|
|
35
|
+
this.processing = true;
|
|
36
|
+
// Begin going through the queue.
|
|
37
|
+
while(this.queue.length){
|
|
38
|
+
if (this.remaining) {
|
|
39
|
+
logger.debug(`[LeakyBucket] Processing queue. Remaining: ${this.remaining} Length: ${this.queue.length}`);
|
|
40
|
+
// Resolves the promise allowing the paused execution of this request to resolve and continue.
|
|
41
|
+
this.queue.shift()?.();
|
|
42
|
+
// A request can be made
|
|
43
|
+
this.used++;
|
|
44
|
+
// Create a new timeout for this request if none exists.
|
|
45
|
+
if (!this.timeoutId) {
|
|
46
|
+
logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`);
|
|
47
|
+
this.timeoutId = setTimeout(()=>{
|
|
48
|
+
this.refillBucket();
|
|
49
|
+
}, this.refillInterval);
|
|
50
|
+
// Set the time for when this refill will occur.
|
|
51
|
+
this.refillsAt = Date.now() + this.refillInterval;
|
|
52
|
+
}
|
|
53
|
+
} else if (this.refillsAt) {
|
|
54
|
+
const now = Date.now();
|
|
55
|
+
// If there is time left until next refill, just delay execution.
|
|
56
|
+
if (this.refillsAt > now) {
|
|
57
|
+
logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for ${this.refillsAt - now}ms`);
|
|
58
|
+
await delay(this.refillsAt - now);
|
|
59
|
+
logger.debug(`[LeakyBucket] Resuming execution`);
|
|
60
|
+
} else {
|
|
61
|
+
logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for 1000ms`);
|
|
62
|
+
await delay(1000);
|
|
63
|
+
}
|
|
48
64
|
}
|
|
49
|
-
});
|
|
50
|
-
// Somehow another acquire has started,
|
|
51
|
-
// so need to wait again.
|
|
52
|
-
if (!bucket.allowAcquire) {
|
|
53
|
-
return await acquire(bucket, amount);
|
|
54
65
|
}
|
|
66
|
+
// Loop has ended mark false so it can restart later when needed
|
|
67
|
+
this.processing = false;
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const refillsNeeded = Math.ceil(tokensNeeded / bucket.refillAmount);
|
|
65
|
-
const waitTime = bucket.refillInterval * refillsNeeded;
|
|
66
|
-
await delay(waitTime);
|
|
67
|
-
// Update the tokens again to ensure nothing has been missed.
|
|
68
|
-
updateTokens(bucket);
|
|
69
|
+
/** Pauses the execution until the request is available to be made. */ async acquire(highPriority) {
|
|
70
|
+
return await new Promise((resolve)=>{
|
|
71
|
+
// High priority requests get added to the start of the queue
|
|
72
|
+
if (highPriority) this.queue.unshift(resolve);
|
|
73
|
+
else this.queue.push(resolve);
|
|
74
|
+
// Each request should trigger the queue to be processed.
|
|
75
|
+
void this.processQueue();
|
|
76
|
+
});
|
|
69
77
|
}
|
|
70
|
-
// In order to not subtract too much from the tokens,
|
|
71
|
-
// calculate what is actually needed to subtract.
|
|
72
|
-
const toSubtract = (amount % bucket.refillAmount) ?? amount;
|
|
73
|
-
bucket.tokensState -= toSubtract;
|
|
74
|
-
// Allow the next acquire to happen.
|
|
75
|
-
bucket.allowAcquire = true;
|
|
76
|
-
// If there is an acquire waiting, let it continue.
|
|
77
|
-
bucket.waiting.shift()?.();
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
//# sourceMappingURL=bucket.js.map
|
package/dist/bucket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bucket.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/bucket.ts"],"sourcesContent":["import logger from './logger.js'\nimport { delay } from './utils.js'\n\nexport class LeakyBucket implements LeakyBucketOptions {\n max: number\n refillInterval: number\n refillAmount: number\n\n /** The amount of requests that have been used up already. */\n used: number = 0\n /** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */\n queue: Array<(value: void | PromiseLike<void>) => void> = []\n /** Whether or not the queue is already processing. */\n processing: boolean = false\n /** The timeout id for the timer to reduce the used amount by the refill amount. */\n timeoutId?: NodeJS.Timeout\n /** The timestamp in milliseconds when the next refill is scheduled. */\n refillsAt?: number\n\n constructor(options?: LeakyBucketOptions) {\n this.max = options?.max ?? 1\n this.refillAmount = options?.refillAmount ? (options.refillAmount > this.max ? this.max : options.refillAmount) : 1\n this.refillInterval = options?.refillInterval ?? 5000\n }\n\n /** The amount of requests that still remain. */\n get remaining(): number {\n return this.max < this.used ? 0 : this.max - this.used\n }\n\n /** Refills the bucket as needed. */\n refillBucket(): void {\n logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`)\n // Lower the used amount by the refill amount\n this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount\n // Reset the refillsAt timestamp since it just got refilled\n this.refillsAt = undefined\n // Reset the timeoutId\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n\n if (this.used > 0) {\n this.timeoutId = setTimeout(() => {\n this.refillBucket()\n }, this.refillInterval)\n this.refillsAt = Date.now() + this.refillInterval\n }\n }\n\n /** Begin processing the queue. */\n async processQueue(): Promise<void> {\n logger.debug('[LeakyBucket] Processing queue')\n\n // There is already a queue that is processing\n if (this.processing) return logger.debug('[LeakyBucket] Queue is already processing.')\n\n this.processing = true\n\n // Begin going through the queue.\n while (this.queue.length) {\n if (this.remaining) {\n logger.debug(`[LeakyBucket] Processing queue. Remaining: ${this.remaining} Length: ${this.queue.length}`)\n // Resolves the promise allowing the paused execution of this request to resolve and continue.\n this.queue.shift()?.()\n // A request can be made\n this.used++\n\n // Create a new timeout for this request if none exists.\n if (!this.timeoutId) {\n logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`)\n\n this.timeoutId = setTimeout(() => {\n this.refillBucket()\n }, this.refillInterval)\n // Set the time for when this refill will occur.\n this.refillsAt = Date.now() + this.refillInterval\n }\n }\n\n // Check if a refill is scheduled, since we have used up all available requests\n else if (this.refillsAt) {\n const now = Date.now()\n // If there is time left until next refill, just delay execution.\n if (this.refillsAt > now) {\n logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for ${this.refillsAt - now}ms`)\n await delay(this.refillsAt - now)\n logger.debug(`[LeakyBucket] Resuming execution`)\n }\n\n // If the refillsAt has passed but the timeout didn't yet execute delay the execution\n else {\n logger.debug(`[LeakyBucket] Delaying execution of leaky bucket requests for 1000ms`)\n await delay(1000)\n }\n }\n }\n\n // Loop has ended mark false so it can restart later when needed\n this.processing = false\n }\n\n /** Pauses the execution until the request is available to be made. */\n async acquire(highPriority?: boolean): Promise<void> {\n return await new Promise((resolve) => {\n // High priority requests get added to the start of the queue\n if (highPriority) this.queue.unshift(resolve)\n // All other requests get pushed to the end.\n else this.queue.push(resolve)\n\n // Each request should trigger the queue to be processed.\n void this.processQueue()\n })\n }\n}\n\nexport interface LeakyBucketOptions {\n /**\n * Max requests allowed at once.\n * @default 1\n */\n max?: number\n /**\n * Interval in milliseconds between refills.\n * @default 5000\n */\n refillInterval?: number\n /**\n * Amount of requests to refill at each interval.\n * @default 1\n */\n refillAmount?: number\n}\n"],"names":["logger","delay","LeakyBucket","constructor","options","used","queue","processing","max","refillAmount","refillInterval","remaining","refillBucket","debug","refillsAt","undefined","clearTimeout","timeoutId","setTimeout","Date","now","processQueue","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EA,gEAAgE;QAChE,IAAI,CAACM,UAAU,GAAG,KAAK;IACzB;IAEA,oEAAoE,GACpE,MAAMiB,QAAQC,YAAsB,EAAiB;QACnD,OAAO,MAAM,IAAIC,QAAQ,CAACC,UAAY;YACpC,6DAA6D;YAC7D,IAAIF,cAAc,IAAI,CAACnB,KAAK,CAACsB,OAAO,CAACD;iBAEhC,IAAI,CAACrB,KAAK,CAACuB,IAAI,CAACF;YAErB,yDAAyD;YACzD,KAAK,IAAI,CAACN,YAAY;QACxB;IACF;AACF,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { DiscordEmbed, DiscordEmbedAuthor, DiscordEmbedField, DiscordEmbedFooter, DiscordEmbedImage, DiscordEmbedThumbnail, DiscordEmbedVideo } from '@discordeno/types';
|
|
2
|
+
/**
|
|
3
|
+
* A builder to help create Discord embeds.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class EmbedsBuilder
|
|
7
|
+
* @typedef {EmbedsBuilder}
|
|
8
|
+
* @extends {Array<DiscordEmbed>}
|
|
9
|
+
* @example
|
|
10
|
+
* const embeds = new EmbedBuilder()
|
|
11
|
+
* .setTitle('My Embed')
|
|
12
|
+
* .setDescription('This is my new embed')
|
|
13
|
+
* .newEmbed()
|
|
14
|
+
* .setTitle('My Second Embed')
|
|
15
|
+
*/
|
|
16
|
+
export declare class EmbedsBuilder extends Array<DiscordEmbed> {
|
|
17
|
+
#private;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a new field to the embed fields array.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} name - Field name
|
|
22
|
+
* @param {string} value - Field value
|
|
23
|
+
* @param {?boolean} [inline=false] - Field should be inline or not.
|
|
24
|
+
* @returns {EmbedsBuilder}
|
|
25
|
+
*/
|
|
26
|
+
addField(name: string, value: string, inline?: boolean): EmbedsBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a blank embed.
|
|
29
|
+
*
|
|
30
|
+
* @returns {EmbedsBuilder}
|
|
31
|
+
*/
|
|
32
|
+
newEmbed(): EmbedsBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Set the current embed author.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} name - Name of the author
|
|
37
|
+
* @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options
|
|
38
|
+
* @returns {EmbedsBuilder}
|
|
39
|
+
*/
|
|
40
|
+
setAuthor(name: string, options?: Omit<DiscordEmbedAuthor, 'name'>): EmbedsBuilder;
|
|
41
|
+
/**
|
|
42
|
+
* Set the color on the side of the current embed.
|
|
43
|
+
*
|
|
44
|
+
* @param {(number | string)} color - The color, in base16 or hex color code
|
|
45
|
+
* @returns {EmbedsBuilder}
|
|
46
|
+
*/
|
|
47
|
+
setColor(color: number | string): EmbedsBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Set the current embed to a different index.
|
|
50
|
+
*
|
|
51
|
+
* WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.
|
|
52
|
+
*
|
|
53
|
+
* @param {?number} [index] - The index of the embed in the EmbedsBuilder array
|
|
54
|
+
* @returns {EmbedsBuilder}
|
|
55
|
+
*/
|
|
56
|
+
setCurrentEmbed(index?: number): EmbedsBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Set the description of the current embed.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} description - Description
|
|
61
|
+
* @returns {EmbedsBuilder}
|
|
62
|
+
*/
|
|
63
|
+
setDescription(description: string): EmbedsBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* Overwrite all fields on the current embed.
|
|
66
|
+
*
|
|
67
|
+
* @param {DiscordEmbedField[]} fields
|
|
68
|
+
* @returns {EmbedsBuilder}
|
|
69
|
+
*/
|
|
70
|
+
setFields(fields: DiscordEmbedField[]): EmbedsBuilder;
|
|
71
|
+
/**
|
|
72
|
+
* Set the footer in the current embed.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} text - The text to display in the footer
|
|
75
|
+
* @param {?Omit<DiscordEmbedFooter, 'text'>} [options]
|
|
76
|
+
* @returns {EmbedsBuilder}
|
|
77
|
+
*/
|
|
78
|
+
setFooter(text: string, options?: Omit<DiscordEmbedFooter, 'text'>): EmbedsBuilder;
|
|
79
|
+
/**
|
|
80
|
+
* Set the image in the current embed.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} url - URL of the image
|
|
83
|
+
* @param {?Omit<DiscordEmbedImage, 'url'>} [options]
|
|
84
|
+
* @returns {EmbedsBuilder}
|
|
85
|
+
*/
|
|
86
|
+
setImage(url: string, options?: Omit<DiscordEmbedImage, 'url'>): EmbedsBuilder;
|
|
87
|
+
/**
|
|
88
|
+
* Set the provider of the current embed.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} name
|
|
91
|
+
* @param {?string} [url]
|
|
92
|
+
* @returns {EmbedsBuilder}
|
|
93
|
+
*/
|
|
94
|
+
setProvider(name: string, url?: string): EmbedsBuilder;
|
|
95
|
+
/**
|
|
96
|
+
* Set the color of the current embed to a random value.
|
|
97
|
+
*
|
|
98
|
+
* @returns {EmbedsBuilder}
|
|
99
|
+
*/
|
|
100
|
+
setRandomColor(): EmbedsBuilder;
|
|
101
|
+
/**
|
|
102
|
+
* Set the title of the current embed.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} title
|
|
105
|
+
* @param {?string} [url]
|
|
106
|
+
* @returns {EmbedsBuilder}
|
|
107
|
+
*/
|
|
108
|
+
setTitle(title: string, url?: string): EmbedsBuilder;
|
|
109
|
+
/**
|
|
110
|
+
* Set the timestamp of the current embed.
|
|
111
|
+
*
|
|
112
|
+
* @param {?(string | number | Date)} [timestamp]
|
|
113
|
+
* @returns {EmbedsBuilder}
|
|
114
|
+
*/
|
|
115
|
+
setTimestamp(timestamp?: string | number | Date): EmbedsBuilder;
|
|
116
|
+
/**
|
|
117
|
+
* Set the thumbnail of the current embed.
|
|
118
|
+
*
|
|
119
|
+
* @param {string} url - URL of the image
|
|
120
|
+
* @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]
|
|
121
|
+
* @returns {EmbedsBuilder}
|
|
122
|
+
*/
|
|
123
|
+
setThumbnail(url: string, options?: Omit<DiscordEmbedThumbnail, 'url'>): EmbedsBuilder;
|
|
124
|
+
/**
|
|
125
|
+
* Set the URL of the current embed title.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} url
|
|
128
|
+
* @returns {EmbedsBuilder}
|
|
129
|
+
*/
|
|
130
|
+
setUrl(url: string): EmbedsBuilder;
|
|
131
|
+
/**
|
|
132
|
+
* Set the video of the current embed.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} url
|
|
135
|
+
* @param {?Omit<DiscordEmbedVideo, 'url'>} [options]
|
|
136
|
+
* @returns {EmbedsBuilder}
|
|
137
|
+
*/
|
|
138
|
+
setVideo(url: string, options?: Omit<DiscordEmbedVideo, 'url'>): EmbedsBuilder;
|
|
139
|
+
/**
|
|
140
|
+
* Validate all embeds available against current known Discord limits to help prevent bad requests.
|
|
141
|
+
*
|
|
142
|
+
* @returns {EmbedsBuilder}
|
|
143
|
+
*/
|
|
144
|
+
validate(): EmbedsBuilder;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=embeds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeds.d.ts","sourceRoot":"","sources":["../../src/builders/embeds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAc,SAAQ,KAAK,CAAC,YAAY,CAAC;;IAGpD;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa;IActE;;;;OAIG;IACH,QAAQ,IAAI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