@discordeno/utils 19.0.0-next.f249e58 → 19.0.0-next.f34c0c3
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/bucket.d.ts.map +1 -1
- package/dist/bucket.js +3 -1
- package/dist/bucket.js.map +1 -1
- package/dist/images.js +1 -1
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.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/urlToBase64.d.ts.map +1 -1
- package/dist/urlToBase64.js +0 -1
- package/dist/urlToBase64.js.map +1 -1
- package/package.json +2 -3
package/dist/bucket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,oFAAoF;IACpF,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;
|
|
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,oFAAoF;IACpF,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;IA0CnC,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
|
@@ -18,8 +18,10 @@ export class LeakyBucket {
|
|
|
18
18
|
this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
|
|
19
19
|
// Reset the refillsAt timestamp since it just got refilled
|
|
20
20
|
this.refillsAt = undefined;
|
|
21
|
+
// Reset the timeoutId
|
|
22
|
+
clearTimeout(this.timeoutId);
|
|
23
|
+
this.timeoutId = undefined;
|
|
21
24
|
if (this.used > 0) {
|
|
22
|
-
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
23
25
|
this.timeoutId = setTimeout(()=>{
|
|
24
26
|
this.refillBucket();
|
|
25
27
|
}, this.refillInterval);
|
package/dist/bucket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\n
|
|
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('[Gateway] Processing queue')\n // There is already a queue that is processing\n if (this.processing) return logger.debug('[Gateway] Queue is already processing.')\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 }\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 processesd.\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","length","shift","acquire","highPriority","Promise","resolve","unshift","push"],"mappings":"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"}
|
package/dist/images.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* @param options - The parameters for the building of the URL.
|
|
20
20
|
* @returns The link to the resource.
|
|
21
21
|
*/ export function avatarUrl(userId, discriminator, options) {
|
|
22
|
-
return options?.avatar ? formatImageUrl(`https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`, options?.size ?? 128, options?.format) : `https://cdn.discordapp.com/embed/avatars/${Number(discriminator) % 5}.png`;
|
|
22
|
+
return options?.avatar ? formatImageUrl(`https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`, options?.size ?? 128, options?.format) : `https://cdn.discordapp.com/embed/avatars/${discriminator === '0' ? (BigInt(userId) >> BigInt(22)) % BigInt(6) : Number(discriminator) % 5}.png`;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Builds a URL to the guild banner stored in the Discord CDN.
|
package/dist/images.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/images.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { BigString, GetGuildWidgetImageQuery, ImageFormat, ImageSize } from '@discordeno/types'\nimport { iconBigintToHash } from './hash.js'\n\n/** Help format an image url. */\nexport function formatImageUrl(url: string, size: ImageSize = 128, format?: ImageFormat): string {\n return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`\n}\n\n/**\n * Get the url for an emoji.\n *\n * @param emojiId The id of the emoji\n * @param animated Whether or not the emoji is animated\n * @returns string\n */\nexport function emojiUrl(emojiId: BigString, animated = false): string {\n return `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'png'}`\n}\n\n/**\n * Builds a URL to a user's avatar stored in the Discord CDN.\n *\n * @param userId - The ID of the user to get the avatar of.\n * @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function avatarUrl(\n userId: BigString,\n discriminator: string,\n options?: {\n avatar: BigString | undefined\n size?: ImageSize\n format?: ImageFormat\n },\n): string {\n return options?.avatar\n ? formatImageUrl(\n `https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`,\n options?.size ?? 128,\n options?.format,\n )\n : `https://cdn.discordapp.com/embed/avatars/${Number(discriminator) % 5}.png`\n}\n\n/**\n * Builds a URL to the guild banner stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildBannerUrl(\n guildId: BigString,\n options: {\n banner?: string | bigint\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return options.banner\n ? formatImageUrl(\n `https://cdn.discordapp.com/banners/${guildId}/${typeof options.banner === 'string' ? options.banner : iconBigintToHash(options.banner)}`,\n options.size ?? 128,\n options.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild icon stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildIconUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/icons/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds the URL to a guild splash stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the splash of.\n * @param imageHash - The hash identifying the splash image.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if the guild does not have a splash image set.\n */\nexport function guildSplashUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/splashes/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild widget image stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the widget image for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function getWidgetImageUrl(guildId: BigString, options?: GetGuildWidgetImageQuery): string {\n let url = `https://discordapp.com/api/guilds/${guildId}/widget.png`\n\n if (options?.style) {\n url += `?style=${options.style}`\n }\n\n return url\n}\n"],"names":["iconBigintToHash","formatImageUrl","url","size","format","includes","emojiUrl","emojiId","animated","avatarUrl","userId","discriminator","options","avatar","Number","guildBannerUrl","guildId","banner","undefined","guildIconUrl","imageHash","guildSplashUrl","getWidgetImageUrl","style"],"mappings":"AAAA,mEAAmE,GAEnE,SAASA,gBAAgB,QAAQ,YAAW;AAE5C,8BAA8B,GAC9B,OAAO,SAASC,eAAeC,GAAW,EAAEC,OAAkB,GAAG,EAAEC,MAAoB,EAAU;IAC/F,OAAO,CAAC,EAAEF,IAAI,CAAC,EAAEE,UAAWF,CAAAA,IAAIG,QAAQ,CAAC,SAAS,QAAQ,KAAK,AAAD,EAAG,MAAM,EAAEF,KAAK,CAAC;AACjF,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASG,SAASC,OAAkB,EAAEC,WAAW,KAAK,EAAU;IACrE,OAAO,CAAC,kCAAkC,EAAED,QAAQ,CAAC,EAAEC,WAAW,QAAQ,KAAK,CAAC,CAAC;AACnF,CAAC;AAED;;;;;;;CAOC,GACD,OAAO,SAASC,UACdC,MAAiB,EACjBC,aAAqB,EACrBC,OAIC,EACO;IACR,OAAOA,SAASC,SACZZ,eACE,CAAC,mCAAmC,EAAES,OAAO,CAAC,EAAE,OAAOE,QAAQC,MAAM,KAAK,WAAWD,QAAQC,MAAM,GAAGb,iBAAiBY,QAAQC,MAAM,CAAC,CAAC,CAAC,EACxID,SAAST,QAAQ,KACjBS,SAASR,UAEX,CAAC,yCAAyC,
|
|
1
|
+
{"version":3,"sources":["../src/images.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport type { BigString, GetGuildWidgetImageQuery, ImageFormat, ImageSize } from '@discordeno/types'\nimport { iconBigintToHash } from './hash.js'\n\n/** Help format an image url. */\nexport function formatImageUrl(url: string, size: ImageSize = 128, format?: ImageFormat): string {\n return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`\n}\n\n/**\n * Get the url for an emoji.\n *\n * @param emojiId The id of the emoji\n * @param animated Whether or not the emoji is animated\n * @returns string\n */\nexport function emojiUrl(emojiId: BigString, animated = false): string {\n return `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'png'}`\n}\n\n/**\n * Builds a URL to a user's avatar stored in the Discord CDN.\n *\n * @param userId - The ID of the user to get the avatar of.\n * @param discriminator - The user's discriminator. (4-digit tag after the hashtag.)\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function avatarUrl(\n userId: BigString,\n discriminator: string,\n options?: {\n avatar: BigString | undefined\n size?: ImageSize\n format?: ImageFormat\n },\n): string {\n return options?.avatar\n ? formatImageUrl(\n `https://cdn.discordapp.com/avatars/${userId}/${typeof options.avatar === 'string' ? options.avatar : iconBigintToHash(options.avatar)}`,\n options?.size ?? 128,\n options?.format,\n )\n : `https://cdn.discordapp.com/embed/avatars/${discriminator === '0' ? (BigInt(userId) >> BigInt(22)) % BigInt(6) : Number(discriminator) % 5}.png`\n}\n\n/**\n * Builds a URL to the guild banner stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildBannerUrl(\n guildId: BigString,\n options: {\n banner?: string | bigint\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return options.banner\n ? formatImageUrl(\n `https://cdn.discordapp.com/banners/${guildId}/${typeof options.banner === 'string' ? options.banner : iconBigintToHash(options.banner)}`,\n options.size ?? 128,\n options.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild icon stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the banner for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if no banner has been set.\n */\nexport function guildIconUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/icons/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds the URL to a guild splash stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the splash of.\n * @param imageHash - The hash identifying the splash image.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource or `undefined` if the guild does not have a splash image set.\n */\nexport function guildSplashUrl(\n guildId: BigString,\n imageHash: BigString | undefined,\n options?: {\n size?: ImageSize\n format?: ImageFormat\n },\n): string | undefined {\n return imageHash\n ? formatImageUrl(\n `https://cdn.discordapp.com/splashes/${guildId}/${typeof imageHash === 'string' ? imageHash : iconBigintToHash(imageHash)}`,\n options?.size ?? 128,\n options?.format,\n )\n : undefined\n}\n\n/**\n * Builds a URL to the guild widget image stored in the Discord CDN.\n *\n * @param guildId - The ID of the guild to get the link to the widget image for.\n * @param options - The parameters for the building of the URL.\n * @returns The link to the resource.\n */\nexport function getWidgetImageUrl(guildId: BigString, options?: GetGuildWidgetImageQuery): string {\n let url = `https://discordapp.com/api/guilds/${guildId}/widget.png`\n\n if (options?.style) {\n url += `?style=${options.style}`\n }\n\n return url\n}\n"],"names":["iconBigintToHash","formatImageUrl","url","size","format","includes","emojiUrl","emojiId","animated","avatarUrl","userId","discriminator","options","avatar","BigInt","Number","guildBannerUrl","guildId","banner","undefined","guildIconUrl","imageHash","guildSplashUrl","getWidgetImageUrl","style"],"mappings":"AAAA,mEAAmE,GAEnE,SAASA,gBAAgB,QAAQ,YAAW;AAE5C,8BAA8B,GAC9B,OAAO,SAASC,eAAeC,GAAW,EAAEC,OAAkB,GAAG,EAAEC,MAAoB,EAAU;IAC/F,OAAO,CAAC,EAAEF,IAAI,CAAC,EAAEE,UAAWF,CAAAA,IAAIG,QAAQ,CAAC,SAAS,QAAQ,KAAK,AAAD,EAAG,MAAM,EAAEF,KAAK,CAAC;AACjF,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASG,SAASC,OAAkB,EAAEC,WAAW,KAAK,EAAU;IACrE,OAAO,CAAC,kCAAkC,EAAED,QAAQ,CAAC,EAAEC,WAAW,QAAQ,KAAK,CAAC,CAAC;AACnF,CAAC;AAED;;;;;;;CAOC,GACD,OAAO,SAASC,UACdC,MAAiB,EACjBC,aAAqB,EACrBC,OAIC,EACO;IACR,OAAOA,SAASC,SACZZ,eACE,CAAC,mCAAmC,EAAES,OAAO,CAAC,EAAE,OAAOE,QAAQC,MAAM,KAAK,WAAWD,QAAQC,MAAM,GAAGb,iBAAiBY,QAAQC,MAAM,CAAC,CAAC,CAAC,EACxID,SAAST,QAAQ,KACjBS,SAASR,UAEX,CAAC,yCAAyC,EAAEO,kBAAkB,MAAM,AAACG,CAAAA,OAAOJ,WAAWI,OAAO,GAAE,IAAKA,OAAO,KAAKC,OAAOJ,iBAAiB,CAAC,CAAC,IAAI,CAAC;AACtJ,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASK,eACdC,OAAkB,EAClBL,OAIC,EACmB;IACpB,OAAOA,QAAQM,MAAM,GACjBjB,eACE,CAAC,mCAAmC,EAAEgB,QAAQ,CAAC,EAAE,OAAOL,QAAQM,MAAM,KAAK,WAAWN,QAAQM,MAAM,GAAGlB,iBAAiBY,QAAQM,MAAM,CAAC,CAAC,CAAC,EACzIN,QAAQT,IAAI,IAAI,KAChBS,QAAQR,MAAM,IAEhBe,SAAS;AACf,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASC,aACdH,OAAkB,EAClBI,SAAgC,EAChCT,OAGC,EACmB;IACpB,OAAOS,YACHpB,eACE,CAAC,iCAAiC,EAAEgB,QAAQ,CAAC,EAAE,OAAOI,cAAc,WAAWA,YAAYrB,iBAAiBqB,UAAU,CAAC,CAAC,EACxHT,SAAST,QAAQ,KACjBS,SAASR,UAEXe,SAAS;AACf,CAAC;AAED;;;;;;;CAOC,GACD,OAAO,SAASG,eACdL,OAAkB,EAClBI,SAAgC,EAChCT,OAGC,EACmB;IACpB,OAAOS,YACHpB,eACE,CAAC,oCAAoC,EAAEgB,QAAQ,CAAC,EAAE,OAAOI,cAAc,WAAWA,YAAYrB,iBAAiBqB,UAAU,CAAC,CAAC,EAC3HT,SAAST,QAAQ,KACjBS,SAASR,UAEXe,SAAS;AACf,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASI,kBAAkBN,OAAkB,EAAEL,OAAkC,EAAU;IAChG,IAAIV,MAAM,CAAC,kCAAkC,EAAEe,QAAQ,WAAW,CAAC;IAEnE,IAAIL,SAASY,OAAO;QAClBtB,OAAO,CAAC,OAAO,EAAEU,QAAQY,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAOtB;AACT,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
export * from './Collection.js';
|
|
1
2
|
export * from './base64.js';
|
|
2
3
|
export * from './bucket.js';
|
|
3
4
|
export * from './casing.js';
|
|
4
|
-
export * from './Collection.js';
|
|
5
5
|
export * from './colors.js';
|
|
6
6
|
export * from './hash.js';
|
|
7
7
|
export * from './images.js';
|
|
8
|
+
export * from './interactions.js';
|
|
8
9
|
export * from './logger.js';
|
|
10
|
+
export * from './oauth2.js';
|
|
9
11
|
export * from './permissions.js';
|
|
10
12
|
export * from './reactions.js';
|
|
11
13
|
export * from './token.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
export * from './Collection.js';
|
|
1
2
|
export * from './base64.js';
|
|
2
3
|
export * from './bucket.js';
|
|
3
4
|
export * from './casing.js';
|
|
4
|
-
export * from './Collection.js';
|
|
5
5
|
export * from './colors.js';
|
|
6
6
|
export * from './hash.js';
|
|
7
7
|
export * from './images.js';
|
|
8
|
+
export * from './interactions.js';
|
|
8
9
|
export * from './logger.js';
|
|
10
|
+
export * from './oauth2.js';
|
|
9
11
|
export * from './permissions.js';
|
|
10
12
|
export * from './reactions.js';
|
|
11
13
|
export * from './token.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './Collection.js'\nexport * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './colors.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './interactions.js'\nexport * from './logger.js'\nexport * from './oauth2.js'\nexport * from './permissions.js'\nexport * from './reactions.js'\nexport * from './token.js'\nexport * from './typeguards.js'\nexport * from './urlToBase64.js'\nexport * from './utils.js'\n"],"names":[],"mappings":"AAAA,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,oBAAmB;AACjC,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
|
package/dist/oauth2.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BigString, OAuth2Scope, PermissionStrings } from '@discordeno/types';
|
|
2
|
+
export declare function createOAuth2Link(options: CreateOAuth2LinkOptions): string;
|
|
3
|
+
export interface CreateOAuth2LinkOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The type of response
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Should be defined only if using either OAuth2 authorization, implicit or not, or [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)
|
|
9
|
+
*/
|
|
10
|
+
responseType?: 'code' | 'token';
|
|
11
|
+
/** The id of the application */
|
|
12
|
+
clientId: BigString;
|
|
13
|
+
/** The scopes for the application */
|
|
14
|
+
scope: OAuth2Scope[];
|
|
15
|
+
/**
|
|
16
|
+
* The optional state for security
|
|
17
|
+
*
|
|
18
|
+
* @see https://discord.com/developers/docs/topics/oauth2#state-and-security
|
|
19
|
+
*/
|
|
20
|
+
state?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The redirect uri for after the authentication
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Should be defined only if using either OAuth2 authorization, implicit or not, or [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)
|
|
26
|
+
*/
|
|
27
|
+
redirectUri?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The type of prompt to give to the user
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* If set to `none`, it will skip the authorization screen and redirect them back to your redirect URI without requesting their authorization.
|
|
33
|
+
* For passthrough scopes, like bot and webhook.incoming, authorization is always required.
|
|
34
|
+
*/
|
|
35
|
+
prompt?: 'consent' | 'none';
|
|
36
|
+
/**
|
|
37
|
+
* The permissions of the invited bot
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow) or with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)
|
|
41
|
+
*/
|
|
42
|
+
permissions?: BigString | PermissionStrings[];
|
|
43
|
+
/**
|
|
44
|
+
* Pre-fills the dropdown picker with a guild for the user
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow) or with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization) or with the `webhook.incoming` scope
|
|
48
|
+
*/
|
|
49
|
+
guildId?: BigString;
|
|
50
|
+
/**
|
|
51
|
+
* Disallows the user from changing the guild dropdown if set to true
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow), with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization) or with the `webhook.incoming` scope
|
|
55
|
+
*/
|
|
56
|
+
disableGuildSelect?: boolean;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=oauth2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../src/oauth2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAGlF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAezE;AAED,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,gCAAgC;IAChC,QAAQ,EAAE,SAAS,CAAA;IACnB,qCAAqC;IACrC,KAAK,EAAE,WAAW,EAAE,CAAA;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;IAC3B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,SAAS,GAAG,iBAAiB,EAAE,CAAA;IAC7C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B"}
|
package/dist/oauth2.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { calculateBits } from './permissions.js';
|
|
2
|
+
export function createOAuth2Link(options) {
|
|
3
|
+
const joinedScopeString = options.scope.join(' ');
|
|
4
|
+
let url = `https://discord.com/oauth2/authorize?client_id=${options.clientId}&scope=${joinedScopeString}`;
|
|
5
|
+
if (options.responseType) url += `&response_type=${options.responseType}`;
|
|
6
|
+
if (options.state) url += `&state=${encodeURIComponent(options.state)}`;
|
|
7
|
+
if (options.redirectUri) url += `&redirect_uri=${encodeURIComponent(options.redirectUri)}`;
|
|
8
|
+
if (options.prompt) url += `&prompt=${options.prompt}`;
|
|
9
|
+
if (options.permissions) url += `&permissions=${Array.isArray(options.permissions) ? calculateBits(options.permissions) : options.permissions}`;
|
|
10
|
+
if (options.guildId) url += `&guild_id=${options.guildId}`;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
12
|
+
if (options.disableGuildSelect !== undefined) url += `&disable_guild_select=${options.disableGuildSelect}`;
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=oauth2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/oauth2.ts"],"sourcesContent":["import type { BigString, OAuth2Scope, PermissionStrings } from '@discordeno/types'\nimport { calculateBits } from './permissions.js'\n\nexport function createOAuth2Link(options: CreateOAuth2LinkOptions): string {\n const joinedScopeString = options.scope.join(' ')\n\n let url = `https://discord.com/oauth2/authorize?client_id=${options.clientId}&scope=${joinedScopeString}`\n\n if (options.responseType) url += `&response_type=${options.responseType}`\n if (options.state) url += `&state=${encodeURIComponent(options.state)}`\n if (options.redirectUri) url += `&redirect_uri=${encodeURIComponent(options.redirectUri)}`\n if (options.prompt) url += `&prompt=${options.prompt}`\n if (options.permissions) url += `&permissions=${Array.isArray(options.permissions) ? calculateBits(options.permissions) : options.permissions}`\n if (options.guildId) url += `&guild_id=${options.guildId}`\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n if (options.disableGuildSelect !== undefined) url += `&disable_guild_select=${options.disableGuildSelect}`\n\n return url\n}\n\nexport interface CreateOAuth2LinkOptions {\n /**\n * The type of response\n *\n * @remarks\n * Should be defined only if using either OAuth2 authorization, implicit or not, or [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)\n */\n responseType?: 'code' | 'token'\n /** The id of the application */\n clientId: BigString\n /** The scopes for the application */\n scope: OAuth2Scope[]\n /**\n * The optional state for security\n *\n * @see https://discord.com/developers/docs/topics/oauth2#state-and-security\n */\n state?: string\n /**\n * The redirect uri for after the authentication\n *\n * @remarks\n * Should be defined only if using either OAuth2 authorization, implicit or not, or [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)\n */\n redirectUri?: string\n /**\n * The type of prompt to give to the user\n *\n * @remarks\n * If set to `none`, it will skip the authorization screen and redirect them back to your redirect URI without requesting their authorization.\n * For passthrough scopes, like bot and webhook.incoming, authorization is always required.\n */\n prompt?: 'consent' | 'none'\n /**\n * The permissions of the invited bot\n *\n * @remarks\n * Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow) or with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization)\n */\n permissions?: BigString | PermissionStrings[]\n /**\n * Pre-fills the dropdown picker with a guild for the user\n *\n * @remarks\n * Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow) or with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization) or with the `webhook.incoming` scope\n */\n guildId?: BigString\n /**\n * Disallows the user from changing the guild dropdown if set to true\n *\n * @remarks\n * Should be defined only in a [bot authorization flow](https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow), with [advanced bot authorization](https://discord.com/developers/docs/topics/oauth2#advanced-bot-authorization) or with the `webhook.incoming` scope\n */\n disableGuildSelect?: boolean\n}\n"],"names":["calculateBits","createOAuth2Link","options","joinedScopeString","scope","join","url","clientId","responseType","state","encodeURIComponent","redirectUri","prompt","permissions","Array","isArray","guildId","disableGuildSelect","undefined"],"mappings":"AACA,SAASA,aAAa,QAAQ,mBAAkB;AAEhD,OAAO,SAASC,iBAAiBC,OAAgC,EAAU;IACzE,MAAMC,oBAAoBD,QAAQE,KAAK,CAACC,IAAI,CAAC;IAE7C,IAAIC,MAAM,CAAC,+CAA+C,EAAEJ,QAAQK,QAAQ,CAAC,OAAO,EAAEJ,kBAAkB,CAAC;IAEzG,IAAID,QAAQM,YAAY,EAAEF,OAAO,CAAC,eAAe,EAAEJ,QAAQM,YAAY,CAAC,CAAC;IACzE,IAAIN,QAAQO,KAAK,EAAEH,OAAO,CAAC,OAAO,EAAEI,mBAAmBR,QAAQO,KAAK,EAAE,CAAC;IACvE,IAAIP,QAAQS,WAAW,EAAEL,OAAO,CAAC,cAAc,EAAEI,mBAAmBR,QAAQS,WAAW,EAAE,CAAC;IAC1F,IAAIT,QAAQU,MAAM,EAAEN,OAAO,CAAC,QAAQ,EAAEJ,QAAQU,MAAM,CAAC,CAAC;IACtD,IAAIV,QAAQW,WAAW,EAAEP,OAAO,CAAC,aAAa,EAAEQ,MAAMC,OAAO,CAACb,QAAQW,WAAW,IAAIb,cAAcE,QAAQW,WAAW,IAAIX,QAAQW,WAAW,CAAC,CAAC;IAC/I,IAAIX,QAAQc,OAAO,EAAEV,OAAO,CAAC,UAAU,EAAEJ,QAAQc,OAAO,CAAC,CAAC;IAC1D,4EAA4E;IAC5E,IAAId,QAAQe,kBAAkB,KAAKC,WAAWZ,OAAO,CAAC,sBAAsB,EAAEJ,QAAQe,kBAAkB,CAAC,CAAC;IAE1G,OAAOX;AACT,CAAC"}
|
package/dist/token.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Removes the Bot before the token. */
|
|
1
|
+
/** Removes the Bot/Bearer before the token. */
|
|
2
2
|
export declare function removeTokenPrefix(token?: string, type?: 'GATEWAY' | 'REST'): string;
|
|
3
3
|
/** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */
|
|
4
4
|
export declare function getBotIdFromToken(token: string): bigint;
|
package/dist/token.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAIA,+CAA+C;AAC/C,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE,SAAS,GAAG,MAAe,GAAG,MAAM,CAY3F;AAED,0LAA0L;AAC1L,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD"}
|
package/dist/token.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
|
|
2
|
+
const validTokenPrefixes = [
|
|
3
|
+
'Bot',
|
|
4
|
+
'Bearer'
|
|
5
|
+
];
|
|
6
|
+
/** Removes the Bot/Bearer before the token. */ export function removeTokenPrefix(token, type = 'REST') {
|
|
3
7
|
// If no token is provided, throw an error
|
|
4
8
|
if (token === undefined) {
|
|
5
9
|
throw new Error(`The ${type} was not given a token. Please provide a token and try again.`);
|
|
6
10
|
}
|
|
11
|
+
const splittedToken = token.split(' ');
|
|
7
12
|
// If the token does not have a prefix just return token
|
|
8
|
-
if (!
|
|
13
|
+
if (splittedToken.length < 2 || !validTokenPrefixes.includes(splittedToken[0])) return token;
|
|
9
14
|
// Remove the prefix and return only the token.
|
|
10
|
-
return
|
|
15
|
+
return splittedToken.splice(1).join(' ');
|
|
11
16
|
}
|
|
12
17
|
/** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */ export function getBotIdFromToken(token) {
|
|
13
18
|
return BigInt(Buffer.from(token.split('.')[0], 'base64').toString());
|
package/dist/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/token.ts"],"sourcesContent":["import { Buffer } from 'node:buffer'\n\n/** Removes the Bot before the token. */\nexport function removeTokenPrefix(token?: string, type: 'GATEWAY' | 'REST' = 'REST'): string {\n // If no token is provided, throw an error\n if (token === undefined) {\n throw new Error(`The ${type} was not given a token. Please provide a token and try again.`)\n }\n // If the token does not have a prefix just return token\n if (!
|
|
1
|
+
{"version":3,"sources":["../src/token.ts"],"sourcesContent":["import { Buffer } from 'node:buffer'\n\nconst validTokenPrefixes = ['Bot', 'Bearer']\n\n/** Removes the Bot/Bearer before the token. */\nexport function removeTokenPrefix(token?: string, type: 'GATEWAY' | 'REST' = 'REST'): string {\n // If no token is provided, throw an error\n if (token === undefined) {\n throw new Error(`The ${type} was not given a token. Please provide a token and try again.`)\n }\n\n const splittedToken = token.split(' ')\n\n // If the token does not have a prefix just return token\n if (splittedToken.length < 2 || !validTokenPrefixes.includes(splittedToken[0])) return token\n // Remove the prefix and return only the token.\n return splittedToken.splice(1).join(' ')\n}\n\n/** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */\nexport function getBotIdFromToken(token: string): bigint {\n return BigInt(Buffer.from(token.split('.')[0], 'base64').toString())\n}\n"],"names":["Buffer","validTokenPrefixes","removeTokenPrefix","token","type","undefined","Error","splittedToken","split","length","includes","splice","join","getBotIdFromToken","BigInt","from","toString"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAa;AAEpC,MAAMC,qBAAqB;IAAC;IAAO;CAAS;AAE5C,6CAA6C,GAC7C,OAAO,SAASC,kBAAkBC,KAAc,EAAEC,OAA2B,MAAM,EAAU;IAC3F,0CAA0C;IAC1C,IAAID,UAAUE,WAAW;QACvB,MAAM,IAAIC,MAAM,CAAC,IAAI,EAAEF,KAAK,6DAA6D,CAAC,EAAC;IAC7F,CAAC;IAED,MAAMG,gBAAgBJ,MAAMK,KAAK,CAAC;IAElC,wDAAwD;IACxD,IAAID,cAAcE,MAAM,GAAG,KAAK,CAACR,mBAAmBS,QAAQ,CAACH,aAAa,CAAC,EAAE,GAAG,OAAOJ;IACvF,+CAA+C;IAC/C,OAAOI,cAAcI,MAAM,CAAC,GAAGC,IAAI,CAAC;AACtC,CAAC;AAED,wLAAwL,GACxL,OAAO,SAASC,kBAAkBV,KAAa,EAAU;IACvD,OAAOW,OAAOd,OAAOe,IAAI,CAACZ,MAAMK,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,UAAUQ,QAAQ;AACnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlToBase64.d.ts","sourceRoot":"","sources":["../src/urlToBase64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"urlToBase64.d.ts","sourceRoot":"","sources":["../src/urlToBase64.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9D"}
|
package/dist/urlToBase64.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
1
|
import { encode } from './base64.js';
|
|
3
2
|
/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */ export async function urlToBase64(url) {
|
|
4
3
|
const buffer = await fetch(url).then(async (res)=>await res.arrayBuffer());
|
package/dist/urlToBase64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/urlToBase64.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/urlToBase64.ts"],"sourcesContent":["import { encode } from './base64.js'\n\n/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */\nexport async function urlToBase64(url: string): Promise<string> {\n const buffer = await fetch(url).then(async (res) => await res.arrayBuffer())\n const imageStr = encode(buffer)\n const type = url.substring(url.lastIndexOf('.') + 1)\n return `data:image/${type};base64,${imageStr}`\n}\n"],"names":["encode","urlToBase64","url","buffer","fetch","then","res","arrayBuffer","imageStr","type","substring","lastIndexOf"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAa;AAEpC,qFAAqF,GACrF,OAAO,eAAeC,YAAYC,GAAW,EAAmB;IAC9D,MAAMC,SAAS,MAAMC,MAAMF,KAAKG,IAAI,CAAC,OAAOC,MAAQ,MAAMA,IAAIC,WAAW;IACzE,MAAMC,WAAWR,OAAOG;IACxB,MAAMM,OAAOP,IAAIQ,SAAS,CAACR,IAAIS,WAAW,CAAC,OAAO;IAClD,OAAO,CAAC,WAAW,EAAEF,KAAK,QAAQ,EAAED,SAAS,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordeno/utils",
|
|
3
|
-
"version": "19.0.0-next.
|
|
3
|
+
"version": "19.0.0-next.f34c0c3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
"test:test-type": "tsc --project tsconfig.test.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@discordeno/types": "19.0.0-next.
|
|
27
|
-
"node-fetch": "^3.3.1",
|
|
26
|
+
"@discordeno/types": "19.0.0-next.f34c0c3",
|
|
28
27
|
"tweetnacl": "^1.0.3"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|