@discordeno/utils 19.0.0-next.fdf0d53 → 19.0.0-next.fe00a6f
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/casing.d.ts.map +1 -1
- package/dist/casing.js.map +1 -1
- package/dist/images.js +1 -1
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/interactions.d.ts +3 -0
- package/dist/interactions.d.ts.map +1 -0
- package/dist/interactions.js +41 -0
- package/dist/interactions.js.map +1 -0
- 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/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/casing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../src/casing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE5D,wBAAgB,QAAQ,
|
|
1
|
+
{"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../src/casing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE5D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAclD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAcpD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAepD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAapD"}
|
package/dist/casing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Camelize, Snakelize } from '@discordeno/types'\n\nexport function camelize
|
|
1
|
+
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Camelize, Snakelize } from '@discordeno/types'\n\nexport function camelize<T>(object: T): Camelize<T> {\n if (Array.isArray(object)) {\n return object.map((element) => camelize(element)) as Camelize<T>\n }\n\n if (typeof object === 'object' && object !== null) {\n const obj = {} as Camelize<T>\n ;(Object.keys(object) as Array<keyof T>).forEach((key) => {\n // @ts-expect-error js hack\n ;(obj[snakeToCamelCase(key)] as Camelize<(T & object)[keyof T]>) = camelize(object[key])\n })\n return obj\n }\n return object as Camelize<T>\n}\n\nexport function snakelize<T>(object: T): Snakelize<T> {\n if (Array.isArray(object)) {\n return object.map((element) => snakelize(element)) as Snakelize<T>\n }\n\n if (typeof object === 'object' && object !== null) {\n const obj = {} as Snakelize<T>\n ;(Object.keys(object) as Array<keyof T>).forEach((key) => {\n // @ts-expect-error js hack\n ;(obj[camelToSnakeCase(key)] as Snakelize<(T & object)[keyof T]>) = snakelize(object[key])\n })\n return obj\n }\n return object as Snakelize<T>\n}\n\nexport function snakeToCamelCase(str: string): string {\n if (!str.includes('_')) return str\n\n let result = ''\n for (let i = 0, len = str.length; i < len; ++i) {\n if (str[i] === '_') {\n result += str[++i].toUpperCase()\n\n continue\n }\n\n result += str[i]\n }\n\n return result\n}\n\nexport function camelToSnakeCase(str: string): string {\n let result = ''\n for (let i = 0, len = str.length; i < len; ++i) {\n if (str[i] >= 'A' && str[i] <= 'Z') {\n result += `_${str[i].toLowerCase()}`\n\n continue\n }\n\n result += str[i]\n }\n\n return result\n}\n"],"names":["camelize","object","Array","isArray","map","element","obj","Object","keys","forEach","key","snakeToCamelCase","snakelize","camelToSnakeCase","str","includes","result","i","len","length","toUpperCase","toLowerCase"],"mappings":"AAEA,OAAO,SAASA,SAAYC,MAAS,EAAe;IAClD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYL,SAASK;IAC1C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAEtDJ,GAAG,CAACK,iBAAiBD,KAAK,GAAuCV,SAASC,MAAM,CAACS,IAAI;QACzF;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASW,UAAaX,MAAS,EAAgB;IACpD,IAAIC,MAAMC,OAAO,CAACF,SAAS;QACzB,OAAOA,OAAOG,GAAG,CAAC,CAACC,UAAYO,UAAUP;IAC3C,CAAC;IAED,IAAI,OAAOJ,WAAW,YAAYA,WAAW,IAAI,EAAE;QACjD,MAAMK,MAAM,CAAC;QACXC,OAAOC,IAAI,CAACP,QAA2BQ,OAAO,CAAC,CAACC,MAAQ;YAEtDJ,GAAG,CAACO,iBAAiBH,KAAK,GAAwCE,UAAUX,MAAM,CAACS,IAAI;QAC3F;QACA,OAAOJ;IACT,CAAC;IACD,OAAOL;AACT,CAAC;AAED,OAAO,SAASU,iBAAiBG,GAAW,EAAU;IACpD,IAAI,CAACA,IAAIC,QAAQ,CAAC,MAAM,OAAOD;IAE/B,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,KAAK,KAAK;YAClBD,UAAUF,GAAG,CAAC,EAAEG,EAAE,CAACG,WAAW;YAE9B,QAAQ;QACV,CAAC;QAEDJ,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC;AAED,OAAO,SAASH,iBAAiBC,GAAW,EAAU;IACpD,IAAIE,SAAS;IACb,IAAK,IAAIC,IAAI,GAAGC,MAAMJ,IAAIK,MAAM,EAAEF,IAAIC,KAAK,EAAED,EAAG;QAC9C,IAAIH,GAAG,CAACG,EAAE,IAAI,OAAOH,GAAG,CAACG,EAAE,IAAI,KAAK;YAClCD,UAAU,CAAC,CAAC,EAAEF,GAAG,CAACG,EAAE,CAACI,WAAW,GAAG,CAAC;YAEpC,QAAQ;QACV,CAAC;QAEDL,UAAUF,GAAG,CAACG,EAAE;IAClB;IAEA,OAAOD;AACT,CAAC"}
|
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
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,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './Collection.js'\nexport * from './colors.js'\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './Collection.js'\nexport * from './colors.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './logger.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,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../src/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE1F,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAwCvJ"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApplicationCommandOptionTypes } from '@discordeno/types';
|
|
2
|
+
export function commandOptionsParser(interaction, options) {
|
|
3
|
+
if (!interaction.data) return {};
|
|
4
|
+
if (!options) options = interaction.data.options ?? [];
|
|
5
|
+
const args = {};
|
|
6
|
+
for (const option of options){
|
|
7
|
+
switch(option.type){
|
|
8
|
+
case ApplicationCommandOptionTypes.SubCommandGroup:
|
|
9
|
+
case ApplicationCommandOptionTypes.SubCommand:
|
|
10
|
+
args[option.name] = commandOptionsParser(interaction, option.options);
|
|
11
|
+
break;
|
|
12
|
+
case ApplicationCommandOptionTypes.Channel:
|
|
13
|
+
args[option.name] = interaction.data.resolved?.channels?.[option.value];
|
|
14
|
+
break;
|
|
15
|
+
case ApplicationCommandOptionTypes.Role:
|
|
16
|
+
args[option.name] = interaction.data.resolved?.roles?.[option.value];
|
|
17
|
+
break;
|
|
18
|
+
case ApplicationCommandOptionTypes.User:
|
|
19
|
+
args[option.name] = {
|
|
20
|
+
user: interaction.data.resolved?.users?.[option.value],
|
|
21
|
+
member: interaction.data.resolved?.members?.[option.value]
|
|
22
|
+
};
|
|
23
|
+
break;
|
|
24
|
+
case ApplicationCommandOptionTypes.Attachment:
|
|
25
|
+
args[option.name] = interaction.data.resolved?.attachments?.[option.value];
|
|
26
|
+
break;
|
|
27
|
+
case ApplicationCommandOptionTypes.Mentionable:
|
|
28
|
+
// Mentionable are roles or users
|
|
29
|
+
args[option.name] = interaction.data.resolved?.roles?.[option.value] ?? {
|
|
30
|
+
user: interaction.data.resolved?.users?.[option.value],
|
|
31
|
+
member: interaction.data.resolved?.members?.[option.value]
|
|
32
|
+
};
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
args[option.name] = option.value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return args;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interactions.ts"],"sourcesContent":["import { ApplicationCommandOptionTypes, type DiscordInteraction } from '@discordeno/types'\n\nexport function commandOptionsParser(interaction: DiscordInteraction, options?: NonNullable<DiscordInteraction['data']>['options']): Record<string, any> {\n if (!interaction.data) return {}\n if (!options) options = interaction.data.options ?? []\n\n const args: Record<string, any> = {}\n\n for (const option of options) {\n switch (option.type) {\n case ApplicationCommandOptionTypes.SubCommandGroup:\n case ApplicationCommandOptionTypes.SubCommand:\n args[option.name] = commandOptionsParser(interaction, option.options)\n break\n case ApplicationCommandOptionTypes.Channel:\n args[option.name] = interaction.data.resolved?.channels?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.Role:\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.User:\n args[option.name] = {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n case ApplicationCommandOptionTypes.Attachment:\n args[option.name] = interaction.data.resolved?.attachments?.[option.value as string]\n break;\n case ApplicationCommandOptionTypes.Mentionable:\n // Mentionable are roles or users\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string] ?? {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n default:\n args[option.name] = option.value\n }\n }\n\n return args\n}\n"],"names":["ApplicationCommandOptionTypes","commandOptionsParser","interaction","options","data","args","option","type","SubCommandGroup","SubCommand","name","Channel","resolved","channels","value","Role","roles","User","user","users","member","members","Attachment","attachments","Mentionable"],"mappings":"AAAA,SAASA,6BAA6B,QAAiC,oBAAmB;AAE1F,OAAO,SAASC,qBAAqBC,WAA+B,EAAEC,OAA4D,EAAuB;IACvJ,IAAI,CAACD,YAAYE,IAAI,EAAE,OAAO,CAAC;IAC/B,IAAI,CAACD,SAASA,UAAUD,YAAYE,IAAI,CAACD,OAAO,IAAI,EAAE;IAEtD,MAAME,OAA4B,CAAC;IAEnC,KAAK,MAAMC,UAAUH,QAAS;QAC5B,OAAQG,OAAOC,IAAI;YACjB,KAAKP,8BAA8BQ,eAAe;YAClD,KAAKR,8BAA8BS,UAAU;gBAC3CJ,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGT,qBAAqBC,aAAaI,OAAOH,OAAO;gBACpE,KAAK;YACP,KAAKH,8BAA8BW,OAAO;gBACxCN,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEC,UAAU,CAACP,OAAOQ,KAAK,CAAW;gBACjF,KAAK;YACP,KAAKd,8BAA8Be,IAAI;gBACrCV,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEI,OAAO,CAACV,OAAOQ,KAAK,CAAW;gBAC9E,KAAK;YACP,KAAKd,8BAA8BiB,IAAI;gBACrCZ,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAG;oBAClBQ,MAAMhB,YAAYE,IAAI,CAACQ,QAAQ,EAAEO,OAAO,CAACb,OAAOQ,KAAK,CAAW;oBAChEM,QAAQlB,YAAYE,IAAI,CAACQ,QAAQ,EAAES,SAAS,CAACf,OAAOQ,KAAK,CAAW;gBACtE;gBACA,KAAK;YACP,KAAKd,8BAA8BsB,UAAU;gBAC3CjB,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEW,aAAa,CAACjB,OAAOQ,KAAK,CAAW;gBACpF,KAAM;YACR,KAAKd,8BAA8BwB,WAAW;gBAC5C,iCAAiC;gBACjCnB,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEI,OAAO,CAACV,OAAOQ,KAAK,CAAW,IAAI;oBAChFI,MAAMhB,YAAYE,IAAI,CAACQ,QAAQ,EAAEO,OAAO,CAACb,OAAOQ,KAAK,CAAW;oBAChEM,QAAQlB,YAAYE,IAAI,CAACQ,QAAQ,EAAES,SAAS,CAACf,OAAOQ,KAAK,CAAW;gBACtE;gBACA,KAAK;YACP;gBACET,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGJ,OAAOQ,KAAK;QACpC;IACF;IAEA,OAAOT;AACT,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.fe00a6f",
|
|
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.fe00a6f",
|
|
28
27
|
"tweetnacl": "^1.0.3"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
package/dist/files.d.ts
DELETED
package/dist/files.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,EAAE,CAOtD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAyBxE"}
|
package/dist/files.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { decode } from './base64.js';
|
|
2
|
-
export function findFiles(file) {
|
|
3
|
-
if (!file) {
|
|
4
|
-
return [];
|
|
5
|
-
}
|
|
6
|
-
const files = Array.isArray(file) ? file : [
|
|
7
|
-
file
|
|
8
|
-
];
|
|
9
|
-
return files.filter(coerceToFileContent);
|
|
10
|
-
}
|
|
11
|
-
export function coerceToFileContent(value) {
|
|
12
|
-
if (!value || typeof value !== 'object') {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const file = value;
|
|
16
|
-
if (typeof file.name !== 'string') {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
switch(typeof file.blob){
|
|
20
|
-
case 'string':
|
|
21
|
-
{
|
|
22
|
-
const match = file.blob.match(/^data:(?<mimeType>[a-zA-Z0-9/]*);base64,(?<content>.*)$/);
|
|
23
|
-
if (match?.groups === undefined) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const { mimeType , content } = match.groups;
|
|
27
|
-
file.blob = new Blob([
|
|
28
|
-
decode(content)
|
|
29
|
-
], {
|
|
30
|
-
type: mimeType
|
|
31
|
-
});
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
case 'object':
|
|
35
|
-
return file.blob instanceof Blob;
|
|
36
|
-
default:
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=files.js.map
|
package/dist/files.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/files.ts"],"sourcesContent":["import type { FileContent } from '@discordeno/types'\nimport { decode } from './base64.js'\n\nexport function findFiles(file: unknown): FileContent[] {\n if (!file) {\n return []\n }\n\n const files: unknown[] = Array.isArray(file) ? file : [file]\n return files.filter(coerceToFileContent)\n}\n\nexport function coerceToFileContent(value: unknown): value is FileContent {\n if (!value || typeof value !== 'object') {\n return false\n }\n\n const file = value as Record<string, unknown>\n if (typeof file.name !== 'string') {\n return false\n }\n\n switch (typeof file.blob) {\n case 'string': {\n const match = file.blob.match(/^data:(?<mimeType>[a-zA-Z0-9/]*);base64,(?<content>.*)$/)\n if (match?.groups === undefined) {\n return false\n }\n const { mimeType, content } = match.groups\n file.blob = new Blob([decode(content)], { type: mimeType })\n return true\n }\n case 'object':\n return file.blob instanceof Blob\n default:\n return false\n }\n}\n"],"names":["decode","findFiles","file","files","Array","isArray","filter","coerceToFileContent","value","name","blob","match","groups","undefined","mimeType","content","Blob","type"],"mappings":"AACA,SAASA,MAAM,QAAQ,cAAa;AAEpC,OAAO,SAASC,UAAUC,IAAa,EAAiB;IACtD,IAAI,CAACA,MAAM;QACT,OAAO,EAAE;IACX,CAAC;IAED,MAAMC,QAAmBC,MAAMC,OAAO,CAACH,QAAQA,OAAO;QAACA;KAAK;IAC5D,OAAOC,MAAMG,MAAM,CAACC;AACtB,CAAC;AAED,OAAO,SAASA,oBAAoBC,KAAc,EAAwB;IACxE,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAO,KAAK;IACd,CAAC;IAED,MAAMN,OAAOM;IACb,IAAI,OAAON,KAAKO,IAAI,KAAK,UAAU;QACjC,OAAO,KAAK;IACd,CAAC;IAED,OAAQ,OAAOP,KAAKQ,IAAI;QACtB,KAAK;YAAU;gBACb,MAAMC,QAAQT,KAAKQ,IAAI,CAACC,KAAK,CAAC;gBAC9B,IAAIA,OAAOC,WAAWC,WAAW;oBAC/B,OAAO,KAAK;gBACd,CAAC;gBACD,MAAM,EAAEC,SAAQ,EAAEC,QAAO,EAAE,GAAGJ,MAAMC,MAAM;gBAC1CV,KAAKQ,IAAI,GAAG,IAAIM,KAAK;oBAAChB,OAAOe;iBAAS,EAAE;oBAAEE,MAAMH;gBAAS;gBACzD,OAAO,IAAI;YACb;QACA,KAAK;YACH,OAAOZ,KAAKQ,IAAI,YAAYM;QAC9B;YACE,OAAO,KAAK;IAChB;AACF,CAAC"}
|