@discordeno/utils 19.0.0-next.6e231b5 → 19.0.0-next.6e8f155

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/index.d.ts CHANGED
@@ -1,11 +1,12 @@
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
8
  export * from './logger.js';
9
+ export * from './oauth2.js';
9
10
  export * from './permissions.js';
10
11
  export * from './reactions.js';
11
12
  export * from './token.js';
@@ -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,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"}
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,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,12 @@
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
8
  export * from './logger.js';
9
+ export * from './oauth2.js';
9
10
  export * from './permissions.js';
10
11
  export * from './reactions.js';
11
12
  export * from './token.js';
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 './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"}
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 './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,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,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;
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAEA,wCAAwC;AACxC,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE,SAAS,GAAG,MAAe,GAAG,MAAM,CAS3F;AAED,0LAA0L;AAC1L,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD"}
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
- /** Removes the Bot before the token. */ export function removeTokenPrefix(token, type = 'REST') {
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 (!token.startsWith('Bot ')) return token;
13
+ if (splittedToken.length < 2 || !validTokenPrefixes.includes(splittedToken[0])) return token;
9
14
  // Remove the prefix and return only the token.
10
- return token.substring(token.indexOf(' ') + 1);
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 (!token.startsWith('Bot ')) return token\n // Remove the prefix and return only the token.\n return token.substring(token.indexOf(' ') + 1)\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","removeTokenPrefix","token","type","undefined","Error","startsWith","substring","indexOf","getBotIdFromToken","BigInt","from","split","toString"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAa;AAEpC,sCAAsC,GACtC,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;IACD,wDAAwD;IACxD,IAAI,CAACD,MAAMI,UAAU,CAAC,SAAS,OAAOJ;IACtC,+CAA+C;IAC/C,OAAOA,MAAMK,SAAS,CAACL,MAAMM,OAAO,CAAC,OAAO;AAC9C,CAAC;AAED,wLAAwL,GACxL,OAAO,SAASC,kBAAkBP,KAAa,EAAU;IACvD,OAAOQ,OAAOV,OAAOW,IAAI,CAACT,MAAMU,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,UAAUC,QAAQ;AACnE,CAAC"}
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,6 +1,7 @@
1
- import type { GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, GetMessagesOptions } from '@discordeno/types';
1
+ import type { DiscordInviteCreate, DiscordInviteMetadata, GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, GetMessagesOptions } from '@discordeno/types';
2
2
  export declare function isGetMessagesAfter(options: GetMessagesOptions): options is GetMessagesAfter;
3
3
  export declare function isGetMessagesBefore(options: GetMessagesOptions): options is GetMessagesBefore;
4
4
  export declare function isGetMessagesAround(options: GetMessagesOptions): options is GetMessagesAround;
5
5
  export declare function isGetMessagesLimit(options: GetMessagesOptions): options is GetMessagesLimit;
6
+ export declare function isInviteWithMetadata(options: DiscordInviteCreate | DiscordInviteMetadata): options is DiscordInviteMetadata;
6
7
  //# sourceMappingURL=typeguards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeguards.d.ts","sourceRoot":"","sources":["../src/typeguards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAGrI,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F"}
1
+ {"version":3,"file":"typeguards.d.ts","sourceRoot":"","sources":["../src/typeguards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAG1B,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,OAAO,IAAI,qBAAqB,CAE3H"}
@@ -11,5 +11,8 @@ export function isGetMessagesAround(options) {
11
11
  export function isGetMessagesLimit(options) {
12
12
  return hasProperty(options, 'limit');
13
13
  }
14
+ export function isInviteWithMetadata(options) {
15
+ return !hasProperty(options, 'channel_id');
16
+ }
14
17
 
15
18
  //# sourceMappingURL=typeguards.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/typeguards.ts"],"sourcesContent":["import type { GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, GetMessagesOptions } from '@discordeno/types'\nimport { hasProperty } from './utils.js'\n\nexport function isGetMessagesAfter(options: GetMessagesOptions): options is GetMessagesAfter {\n return hasProperty(options, 'after')\n}\n\nexport function isGetMessagesBefore(options: GetMessagesOptions): options is GetMessagesBefore {\n return hasProperty(options, 'before')\n}\n\nexport function isGetMessagesAround(options: GetMessagesOptions): options is GetMessagesAround {\n return hasProperty(options, 'around')\n}\n\nexport function isGetMessagesLimit(options: GetMessagesOptions): options is GetMessagesLimit {\n return hasProperty(options, 'limit')\n}\n"],"names":["hasProperty","isGetMessagesAfter","options","isGetMessagesBefore","isGetMessagesAround","isGetMessagesLimit"],"mappings":"AACA,SAASA,WAAW,QAAQ,aAAY;AAExC,OAAO,SAASC,mBAAmBC,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASC,oBAAoBD,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASE,oBAAoBF,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASG,mBAAmBH,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC"}
1
+ {"version":3,"sources":["../src/typeguards.ts"],"sourcesContent":["import type {\n DiscordInviteCreate,\n DiscordInviteMetadata,\n GetMessagesAfter,\n GetMessagesAround,\n GetMessagesBefore,\n GetMessagesLimit,\n GetMessagesOptions,\n} from '@discordeno/types'\nimport { hasProperty } from './utils.js'\n\nexport function isGetMessagesAfter(options: GetMessagesOptions): options is GetMessagesAfter {\n return hasProperty(options, 'after')\n}\n\nexport function isGetMessagesBefore(options: GetMessagesOptions): options is GetMessagesBefore {\n return hasProperty(options, 'before')\n}\n\nexport function isGetMessagesAround(options: GetMessagesOptions): options is GetMessagesAround {\n return hasProperty(options, 'around')\n}\n\nexport function isGetMessagesLimit(options: GetMessagesOptions): options is GetMessagesLimit {\n return hasProperty(options, 'limit')\n}\n\nexport function isInviteWithMetadata(options: DiscordInviteCreate | DiscordInviteMetadata): options is DiscordInviteMetadata {\n return !hasProperty(options, 'channel_id')\n}\n"],"names":["hasProperty","isGetMessagesAfter","options","isGetMessagesBefore","isGetMessagesAround","isGetMessagesLimit","isInviteWithMetadata"],"mappings":"AASA,SAASA,WAAW,QAAQ,aAAY;AAExC,OAAO,SAASC,mBAAmBC,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASC,oBAAoBD,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASE,oBAAoBF,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASG,mBAAmBH,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASI,qBAAqBJ,OAAoD,EAAoC;IAC3H,OAAO,CAACF,YAAYE,SAAS;AAC/B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discordeno/utils",
3
- "version": "19.0.0-next.6e231b5",
3
+ "version": "19.0.0-next.6e8f155",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "test:test-type": "tsc --project tsconfig.test.json"
24
24
  },
25
25
  "dependencies": {
26
- "@discordeno/types": "19.0.0-next.6e231b5",
26
+ "@discordeno/types": "19.0.0-next.6e8f155",
27
27
  "tweetnacl": "^1.0.3"
28
28
  },
29
29
  "devDependencies": {
@@ -1,3 +0,0 @@
1
- import { type DiscordInteraction } from '@discordeno/types';
2
- export declare function commandOptionsParser(interaction: DiscordInteraction, options?: NonNullable<DiscordInteraction['data']>['options']): Record<string, any>;
3
- //# sourceMappingURL=interactions.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,41 +0,0 @@
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
@@ -1 +0,0 @@
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"}