From 1ce9f246f0828db1a3a404c4e8714b3b12c61ac1 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 13:59:02 +0630 Subject: [PATCH 01/49] Add user commands --- index.d.ts | 1 + lib/Client.js | 1 + lib/structures/ApplicationCommand.js | 1 + 3 files changed, 3 insertions(+) diff --git a/index.d.ts b/index.d.ts index c35e9c26c..2082e08a1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,6 +224,7 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; + contexts: Number[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { diff --git a/lib/Client.js b/lib/Client.js index acc29ecf2..7b880264a 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -641,6 +641,7 @@ class Client extends EventEmitter { * @arg {Boolean} [command.nsfw=false] Whether the command is age-restricted * @arg {Array} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure) * @arg {Number} [command.type=1] The command type, either `1` for `CHAT_INPUT`, `2` for `USER` or `3` for `MESSAGE` + * @arg {Number[]} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @returns {Promise} Resolves with the created application command */ createCommand(command) { diff --git a/lib/structures/ApplicationCommand.js b/lib/structures/ApplicationCommand.js index 4199c486f..73d37a29e 100644 --- a/lib/structures/ApplicationCommand.js +++ b/lib/structures/ApplicationCommand.js @@ -19,6 +19,7 @@ const Permission = require("./Permission"); * @prop {Array?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command * @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) * @prop {String} version The ID of the version of this command + * @prop {Number[]} contexts The context of the command (if the command is a user-installable or a guild-installable) */ class ApplicationCommand extends Base { constructor(data, client) { From e4de85c29a10d666872841e380a6d701c732b490 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 14:00:02 +0630 Subject: [PATCH 02/49] assign contexts to application command constructor --- lib/structures/ApplicationCommand.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/structures/ApplicationCommand.js b/lib/structures/ApplicationCommand.js index 73d37a29e..03f5a70a7 100644 --- a/lib/structures/ApplicationCommand.js +++ b/lib/structures/ApplicationCommand.js @@ -19,7 +19,7 @@ const Permission = require("./Permission"); * @prop {Array?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command * @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) * @prop {String} version The ID of the version of this command - * @prop {Number[]} contexts The context of the command (if the command is a user-installable or a guild-installable) + * @prop {Number[]?} contexts The context of the command (if the command is a user-installable or a guild-installable) */ class ApplicationCommand extends Base { constructor(data, client) { @@ -57,6 +57,9 @@ class ApplicationCommand extends Base { if(data.nsfw !== undefined) { this.nsfw = data.nsfw; } + if(data.contexts !== undefined) { + this.contexts = data.contexts + } } /** From 647344132e131dbdf2e9746a9f06371b1d9345e8 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 14:23:06 +0630 Subject: [PATCH 03/49] add context type to commandinteraction --- lib/structures/CommandInteraction.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index c83c1cc74..1596f1f75 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -34,6 +34,7 @@ const {InteractionResponseTypes} = require("../Constants"); * @prop {String?} guildID The ID of the guild in which the interaction was created * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild) * @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm) + * @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) */ class CommandInteraction extends Interaction { constructor(data, client) { @@ -45,6 +46,8 @@ class CommandInteraction extends Interaction { this.data = JSON.parse(JSON.stringify(data.data)); + this.context = data.context + if(data.data.resolved !== undefined) { //Users if(data.data.resolved.users !== undefined) { From 431381df802c322721854ea42b947a9ceead4941 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 21:08:53 +0630 Subject: [PATCH 04/49] Add context constants --- lib/Constants.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Constants.js b/lib/Constants.js index 4b308ad55..a6671284a 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -15,6 +15,12 @@ module.exports.ActivityFlags = { EMBEDDED: 1 << 8 }; +module.exports.ApplicationCommandContextType = { + GUILD: 0, + BOT_DM: 1, + PRIVATE: 2 +} + module.exports.ActivityTypes = { GAME: 0, STREAMING: 1, From 743ac7e7ea9b79cfea8ea0cea1baeb6e944f1110 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 21:09:18 +0630 Subject: [PATCH 05/49] Format: ApplicationCommandContextType --- lib/Constants.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Constants.js b/lib/Constants.js index a6671284a..a2099b43d 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -16,8 +16,8 @@ module.exports.ActivityFlags = { }; module.exports.ApplicationCommandContextType = { - GUILD: 0, - BOT_DM: 1, + GUILD: 0, + BOT_DM: 1, PRIVATE: 2 } From d58b66c3416e779c3d06281d1f9fa7f1a3625397 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 21:51:23 +0630 Subject: [PATCH 06/49] add testing for user installable --- examples/userCommand.js | 43 ++++++++++++++++++++++++++++ index.d.ts | 6 ++++ lib/structures/CommandInteraction.js | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 examples/userCommand.js diff --git a/examples/userCommand.js b/examples/userCommand.js new file mode 100644 index 000000000..fd2bf6f39 --- /dev/null +++ b/examples/userCommand.js @@ -0,0 +1,43 @@ +const Eris = require("eris"); + +const Constants = Eris.Constants; + +const bot = new Eris("Bot token", { + intents: [] +}); + +bot.on("ready", () => { + console.log("connected!") + bot.createCommand({ + type: Constants.ApplicationCommandTypes.CHAT_INPUT, + name: "ping", + description: "Reply with pong", + options: [], + contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE] + }) +}) + +bot.on("interactionCreate", (interaction) => { + if(interaction instanceof Eris.CommandInteraction) { + if(interaction.data.name === "ping") { + let where = "" + const context = interaction.context + + console.log(interaction) + + if(context === Constants.ApplicationCommandContextType.GUILD) { + where = "as a server interaction." + } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { + where = "as a bot DM interaction." + } else if(context === Constants.ApplicationCommandContextType.PRIVATE) { + where = "as a private interaction (user installable)." + } else { + where = "as a server interaction." + } + + interaction.createMessage(`🏓 pong ${where}`) + } + } +}) + +bot.connect() \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 2082e08a1..e21302485 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1898,6 +1898,11 @@ declare namespace Eris { interface Constants { GATEWAY_VERSION: 9; REST_VERSION: 9; + ApplicationCommandContextType: { + GUILD: 0, + BOT_DM: 1, + PRIVATE: 2 + } ActivityFlags: { INSTANCE: 1; JOIN: 2; @@ -3515,6 +3520,7 @@ declare namespace Eris { member: T extends AnyGuildChannel ? Member : undefined; type: Constants["InteractionTypes"]["APPLICATION_COMMAND"]; user: T extends AnyGuildChannel ? undefined : User; + context?: number acknowledge(flags?: number): Promise; createFollowup(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; createMessage(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 1596f1f75..8f332bc22 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -108,7 +108,7 @@ class CommandInteraction extends Interaction { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { const guild = this._client.guilds.get(data.guild_id); - this.member = guild.members.update(data.member, guild); + this.member = guild?.members?.update(data.member, guild); } } From b5f05a3ecb377c2f48d0cf5b086a8a0c2abc3c9b Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:03:49 +0630 Subject: [PATCH 07/49] Fix: user installables not registering properly --- examples/userCommand.js | 4 +++- index.d.ts | 4 ++++ lib/Client.js | 3 ++- lib/Constants.js | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index fd2bf6f39..2fff002b6 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -13,7 +13,9 @@ bot.on("ready", () => { name: "ping", description: "Reply with pong", options: [], - contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE] + /** The following 2 lines set the state of the application command as both user installable and guild installable */ + contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE], + integration_types: [Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, Constants.ApplicationCommandIntegrationTypes.USER_INSTALL] }) }) diff --git a/index.d.ts b/index.d.ts index e21302485..649b96f18 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1903,6 +1903,10 @@ declare namespace Eris { BOT_DM: 1, PRIVATE: 2 } + ApplicationCommandIntegrationTypes: { + GUILD_INSTALL: 0, + USER_INSTALL: 1 + } ActivityFlags: { INSTANCE: 1; JOIN: 2; diff --git a/lib/Client.js b/lib/Client.js index 7b880264a..00c94c4f8 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -641,7 +641,8 @@ class Client extends EventEmitter { * @arg {Boolean} [command.nsfw=false] Whether the command is age-restricted * @arg {Array} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure) * @arg {Number} [command.type=1] The command type, either `1` for `CHAT_INPUT`, `2` for `USER` or `3` for `MESSAGE` - * @arg {Number[]} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) + * @arg {Number[]?} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) + * @arg {Number[]?} [command.integration_types] Configure the installation state of the slash command GUILD_INSTALL=0 USER_INSTALL=1 [more info](https://discord.com/developers/docs/resources/application#application-object-application-integration-types) * @returns {Promise} Resolves with the created application command */ createCommand(command) { diff --git a/lib/Constants.js b/lib/Constants.js index a2099b43d..b6d29112a 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -21,6 +21,11 @@ module.exports.ApplicationCommandContextType = { PRIVATE: 2 } +module.exports.ApplicationCommandIntegrationTypes = { + GUILD_INSTALL: 0, + USER_INSTALL: 1 +} + module.exports.ActivityTypes = { GAME: 0, STREAMING: 1, From 7247cbfd4ef8e160461b9235144a681b4b6c9704 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:04:54 +0630 Subject: [PATCH 08/49] Add integration_types to ApplicationCommandCreateOptions type --- index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.d.ts b/index.d.ts index 649b96f18..c51961825 100644 --- a/index.d.ts +++ b/index.d.ts @@ -225,6 +225,7 @@ declare namespace Eris { name: string; type?: U; contexts: Number[]; + integration_types: Number[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { From 8c0f31bf7f246e97d326a29a4731345d2f3ce613 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:08:57 +0630 Subject: [PATCH 09/49] make the example more verbose --- examples/userCommand.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 2fff002b6..075837740 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -13,7 +13,7 @@ bot.on("ready", () => { name: "ping", description: "Reply with pong", options: [], - /** The following 2 lines set the state of the application command as both user installable and guild installable */ + /* The following 2 lines set the state of the application command as both user installable and guild installable */ contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE], integration_types: [Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, Constants.ApplicationCommandIntegrationTypes.USER_INSTALL] }) @@ -23,10 +23,15 @@ bot.on("interactionCreate", (interaction) => { if(interaction instanceof Eris.CommandInteraction) { if(interaction.data.name === "ping") { let where = "" + /** + * .context includes information of where the command was executed. + * if .context matches ... + * Constants.ApplicationCommandContextType.GUILD it means it is executed from a server + * Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM + * Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable + */ const context = interaction.context - console.log(interaction) - if(context === Constants.ApplicationCommandContextType.GUILD) { where = "as a server interaction." } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { From d15710d9ecb9e07f0d0e4783c7aec4c7bcf18deb Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:14:40 +0630 Subject: [PATCH 10/49] add a warning to the example --- examples/userCommand.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/userCommand.js b/examples/userCommand.js index 075837740..a4804be43 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -29,6 +29,8 @@ bot.on("interactionCreate", (interaction) => { * Constants.ApplicationCommandContextType.GUILD it means it is executed from a server * Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM * Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable + * + * Incase of BOT_DM and PRIVATE, the CommandInteraction will lose all its guild related properties such as the guild information and member data */ const context = interaction.context From 0295152e35cde0856249945c04158e3a72a067e9 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:21:57 +0630 Subject: [PATCH 11/49] chore: lint --- examples/userCommand.js | 49 ++++++++++++++++------------ index.d.ts | 21 ++++++------ lib/Constants.js | 4 +-- lib/structures/ApplicationCommand.js | 4 +-- lib/structures/CommandInteraction.js | 2 +- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index a4804be43..7ffd93c9c 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -3,50 +3,57 @@ const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot token", { - intents: [] + intents: [], }); bot.on("ready", () => { - console.log("connected!") + console.log("connected!"); bot.createCommand({ type: Constants.ApplicationCommandTypes.CHAT_INPUT, name: "ping", description: "Reply with pong", options: [], /* The following 2 lines set the state of the application command as both user installable and guild installable */ - contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE], - integration_types: [Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, Constants.ApplicationCommandIntegrationTypes.USER_INSTALL] - }) -}) + contexts: [ + Constants.ApplicationCommandContextType.GUILD, + Constants.ApplicationCommandContextType.BOT_DM, + Constants.ApplicationCommandContextType.PRIVATE, + ], + integration_types: [ + Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, + Constants.ApplicationCommandIntegrationTypes.USER_INSTALL, + ], + }); +}); bot.on("interactionCreate", (interaction) => { - if(interaction instanceof Eris.CommandInteraction) { - if(interaction.data.name === "ping") { - let where = "" + if (interaction instanceof Eris.CommandInteraction) { + if (interaction.data.name === "ping") { + let where = ""; /** * .context includes information of where the command was executed. * if .context matches ... * Constants.ApplicationCommandContextType.GUILD it means it is executed from a server * Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM * Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable - * + * * Incase of BOT_DM and PRIVATE, the CommandInteraction will lose all its guild related properties such as the guild information and member data */ - const context = interaction.context + const context = interaction.context; - if(context === Constants.ApplicationCommandContextType.GUILD) { - where = "as a server interaction." - } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { - where = "as a bot DM interaction." - } else if(context === Constants.ApplicationCommandContextType.PRIVATE) { - where = "as a private interaction (user installable)." + if (context === Constants.ApplicationCommandContextType.GUILD) { + where = "as a server interaction."; + } else if (context === Constants.ApplicationCommandContextType.BOT_DM) { + where = "as a bot DM interaction."; + } else if (context === Constants.ApplicationCommandContextType.PRIVATE) { + where = "as a private interaction (user installable)."; } else { - where = "as a server interaction." + where = "as a server interaction."; } - interaction.createMessage(`🏓 pong ${where}`) + interaction.createMessage(`🏓 pong ${where}`); } } -}) +}); -bot.connect() \ No newline at end of file +bot.connect(); diff --git a/index.d.ts b/index.d.ts index c51961825..d65a05109 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,8 +224,8 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; - contexts: Number[]; - integration_types: Number[]; + contexts: number[]; + integration_types: number[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { @@ -1900,14 +1900,14 @@ declare namespace Eris { GATEWAY_VERSION: 9; REST_VERSION: 9; ApplicationCommandContextType: { - GUILD: 0, - BOT_DM: 1, - PRIVATE: 2 - } + GUILD: 0; + BOT_DM: 1; + PRIVATE: 2; + }; ApplicationCommandIntegrationTypes: { - GUILD_INSTALL: 0, - USER_INSTALL: 1 - } + GUILD_INSTALL: 0; + USER_INSTALL: 1; + }; ActivityFlags: { INSTANCE: 1; JOIN: 2; @@ -3520,12 +3520,13 @@ declare namespace Eris { export class CommandInteraction extends Interaction { appPermissions?: Permission; channel: T; + context?: number; data: CommandInteractionData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; type: Constants["InteractionTypes"]["APPLICATION_COMMAND"]; user: T extends AnyGuildChannel ? undefined : User; - context?: number + acknowledge(flags?: number): Promise; createFollowup(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; createMessage(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; diff --git a/lib/Constants.js b/lib/Constants.js index b6d29112a..4b5da125c 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -19,12 +19,12 @@ module.exports.ApplicationCommandContextType = { GUILD: 0, BOT_DM: 1, PRIVATE: 2 -} +}; module.exports.ApplicationCommandIntegrationTypes = { GUILD_INSTALL: 0, USER_INSTALL: 1 -} +}; module.exports.ActivityTypes = { GAME: 0, diff --git a/lib/structures/ApplicationCommand.js b/lib/structures/ApplicationCommand.js index 03f5a70a7..456074002 100644 --- a/lib/structures/ApplicationCommand.js +++ b/lib/structures/ApplicationCommand.js @@ -58,8 +58,8 @@ class ApplicationCommand extends Base { this.nsfw = data.nsfw; } if(data.contexts !== undefined) { - this.contexts = data.contexts - } + this.contexts = data.contexts; + } } /** diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 8f332bc22..6257390ca 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -46,7 +46,7 @@ class CommandInteraction extends Interaction { this.data = JSON.parse(JSON.stringify(data.data)); - this.context = data.context + this.context = data.context; if(data.data.resolved !== undefined) { //Users From f1f47330a9a493a09167d70517e7fdeb4eb582a7 Mon Sep 17 00:00:00 2001 From: Retro Date: Sun, 25 Aug 2024 22:32:08 +0630 Subject: [PATCH 12/49] Update typings to be optional --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index d65a05109..17308b6a5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,8 +224,8 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; - contexts: number[]; - integration_types: number[]; + contexts?: number[]; + integration_types?: number[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { From df8a692d0d152c95e84c776fcfdb49261cef43e9 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Mon, 26 Aug 2024 06:56:15 +0630 Subject: [PATCH 13/49] Update index.d.ts Co-authored-by: bsian03 --- index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 17308b6a5..a60bdada8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3526,7 +3526,6 @@ declare namespace Eris { member: T extends AnyGuildChannel ? Member : undefined; type: Constants["InteractionTypes"]["APPLICATION_COMMAND"]; user: T extends AnyGuildChannel ? undefined : User; - acknowledge(flags?: number): Promise; createFollowup(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; createMessage(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise; From bdf0330e39086a5f2d3dab1e8c3180ae644dd240 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 07:22:13 +0630 Subject: [PATCH 14/49] chore: lint (again: prettier added the commans for some reason) --- examples/userCommand.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 7ffd93c9c..8dcaa73c7 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -3,7 +3,7 @@ const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot token", { - intents: [], + intents: [] }); bot.on("ready", () => { @@ -17,18 +17,18 @@ bot.on("ready", () => { contexts: [ Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, - Constants.ApplicationCommandContextType.PRIVATE, + Constants.ApplicationCommandContextType.PRIVATE ], integration_types: [ Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, - Constants.ApplicationCommandIntegrationTypes.USER_INSTALL, - ], + Constants.ApplicationCommandIntegrationTypes.USER_INSTALL + ] }); }); bot.on("interactionCreate", (interaction) => { - if (interaction instanceof Eris.CommandInteraction) { - if (interaction.data.name === "ping") { + if(interaction instanceof Eris.CommandInteraction) { + if(interaction.data.name === "ping") { let where = ""; /** * .context includes information of where the command was executed. @@ -41,11 +41,11 @@ bot.on("interactionCreate", (interaction) => { */ const context = interaction.context; - if (context === Constants.ApplicationCommandContextType.GUILD) { + if(context === Constants.ApplicationCommandContextType.GUILD) { where = "as a server interaction."; - } else if (context === Constants.ApplicationCommandContextType.BOT_DM) { + } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { where = "as a bot DM interaction."; - } else if (context === Constants.ApplicationCommandContextType.PRIVATE) { + } else if(context === Constants.ApplicationCommandContextType.PRIVATE) { where = "as a private interaction (user installable)."; } else { where = "as a server interaction."; From b052b0f76a6da4d8ff2b684091e385aea58f8bc8 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 07:30:06 +0630 Subject: [PATCH 15/49] alphabetical order --- examples/userCommand.js | 2 +- index.d.ts | 4 ++-- lib/Client.js | 5 +++-- lib/structures/ApplicationCommand.js | 6 +++++- lib/structures/CommandInteraction.js | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 8dcaa73c7..0af734e06 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -19,7 +19,7 @@ bot.on("ready", () => { Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE ], - integration_types: [ + integrationTypes: [ Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, Constants.ApplicationCommandIntegrationTypes.USER_INSTALL ] diff --git a/index.d.ts b/index.d.ts index a60bdada8..0f2334863 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,8 +224,8 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; - contexts?: number[]; - integration_types?: number[]; + contexts?: Constants['ApplicationCommandContextType'][]; + integrationTypes?: Constants['ApplicationCommandIntegrationTypes'][]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { diff --git a/lib/Client.js b/lib/Client.js index 00c94c4f8..95d103964 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -631,18 +631,18 @@ class Client extends EventEmitter { /** * Create a global application command * @arg {Object} command A command object + * @arg {Number[]?} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @arg {BigInt | Number | String | Permission?} command.defaultMemberPermissions The default permissions the user must have to use the command * @arg {Boolean} [command.defaultPermission=true] [DEPRECATED] Whether the command is enabled by default when the application is added to a guild. Replaced by `defaultMemberPermissions` * @arg {String} [command.description] The command description, required for `CHAT_INPUT` commands * @arg {Object?} [command.descriptionLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command description * @arg {Boolean?} [command.dmPermission=true] Whether the command is available in DMs with the app + * @arg {Number[]?} [command.integrationTypes] Configure the installation state of the slash command GUILD_INSTALL=0 USER_INSTALL=1 [more info](https://discord.com/developers/docs/resources/application#application-object-application-integration-types) * @arg {String} command.name The command name * @arg {Object?} [command.nameLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command name * @arg {Boolean} [command.nsfw=false] Whether the command is age-restricted * @arg {Array} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure) * @arg {Number} [command.type=1] The command type, either `1` for `CHAT_INPUT`, `2` for `USER` or `3` for `MESSAGE` - * @arg {Number[]?} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) - * @arg {Number[]?} [command.integration_types] Configure the installation state of the slash command GUILD_INSTALL=0 USER_INSTALL=1 [more info](https://discord.com/developers/docs/resources/application#application-object-application-integration-types) * @returns {Promise} Resolves with the created application command */ createCommand(command) { @@ -663,6 +663,7 @@ class Client extends EventEmitter { command.default_permission = command.defaultPermission; } command.dm_permission = command.dmPermission; + command.integration_types = command.integrationTypes return this.requestHandler.request("POST", Endpoints.COMMANDS(this.application.id), true, command).then((command) => new ApplicationCommand(command, this)); } diff --git a/lib/structures/ApplicationCommand.js b/lib/structures/ApplicationCommand.js index 456074002..74a5de9af 100644 --- a/lib/structures/ApplicationCommand.js +++ b/lib/structures/ApplicationCommand.js @@ -6,6 +6,7 @@ const Permission = require("./Permission"); /** * Represents an application command * @prop {String} applicationID The ID of the application that this command belongs to + * @prop {Number[]?} contexts The context of the command (if the command is a user-installable or a guild-installable) * @prop {Permission?} defaultMemberPermissions The permissions required by default for this command to be usable * @prop {Boolean?} defaultPermission [DEPRECATED] Indicates whether the command is enabled by default when the application is added to a guild * @prop {String} description The description of the command (empty for user & message commands) @@ -13,13 +14,13 @@ const Permission = require("./Permission"); * @prop {Boolean?} dmPermission If this command can be used in direct messages (global commands only) * @prop {Guild?} guild The guild associated with this command (guild commands only) * @prop {String} id The ID of the application command + * @prop {Number[]?} integrationTypes The installation state of the slash command GUILD_INSTALL=0 USER_INSTALL=1 [more info](https://discord.com/developers/docs/resources/application#application-object-application-integration-types) * @prop {String} name The name of the command * @prop {Object?} nameLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to names for that locale * @prop {Boolean?} nsfw Indicates whether the command is age-restricted * @prop {Array?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command * @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) * @prop {String} version The ID of the version of this command - * @prop {Number[]?} contexts The context of the command (if the command is a user-installable or a guild-installable) */ class ApplicationCommand extends Base { constructor(data, client) { @@ -60,6 +61,9 @@ class ApplicationCommand extends Base { if(data.contexts !== undefined) { this.contexts = data.contexts; } + if(data.integration_types !== undefined) { + this.integrationTypes = data.integration_types + } } /** diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 6257390ca..fa0cc1b38 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -16,6 +16,7 @@ const {InteractionResponseTypes} = require("../Constants"); * @extends Interaction * @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached + * @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @prop {Object} data The data attached to the interaction * @prop {String} data.id The ID of the Application Command * @prop {String} data.name The command name @@ -34,7 +35,6 @@ const {InteractionResponseTypes} = require("../Constants"); * @prop {String?} guildID The ID of the guild in which the interaction was created * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild) * @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm) - * @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) */ class CommandInteraction extends Interaction { constructor(data, client) { From c0c23d999f3f7862015598e2bd94f0027dd39b28 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 07:31:15 +0630 Subject: [PATCH 16/49] remove spacing --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0f2334863..2aa9bda35 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1905,8 +1905,8 @@ declare namespace Eris { PRIVATE: 2; }; ApplicationCommandIntegrationTypes: { - GUILD_INSTALL: 0; - USER_INSTALL: 1; + GUILD_INSTALL: 0; + USER_INSTALL: 1; }; ActivityFlags: { INSTANCE: 1; From 1a81f4bb98b17313de1616dacee2d86ac900f6b6 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 07:34:31 +0630 Subject: [PATCH 17/49] fix: spacing yet again --- examples/userCommand.js | 2 ++ index.d.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 0af734e06..56597fc78 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -41,6 +41,8 @@ bot.on("interactionCreate", (interaction) => { */ const context = interaction.context; + console.log(interaction) + if(context === Constants.ApplicationCommandContextType.GUILD) { where = "as a server interaction."; } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { diff --git a/index.d.ts b/index.d.ts index 2aa9bda35..974956649 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1906,7 +1906,7 @@ declare namespace Eris { }; ApplicationCommandIntegrationTypes: { GUILD_INSTALL: 0; - USER_INSTALL: 1; + USER_INSTALL: 1; }; ActivityFlags: { INSTANCE: 1; From 8e566bf5fb718ca22570c0b15747e8989d761b60 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 08:12:23 +0630 Subject: [PATCH 18/49] Fix: Missing guild prop && Chore: lint --- examples/userCommand.js | 2 +- index.d.ts | 4 ++-- lib/Client.js | 2 +- lib/structures/ApplicationCommand.js | 2 +- lib/structures/CommandInteraction.js | 8 ++++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 56597fc78..fa273e9d4 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -41,7 +41,7 @@ bot.on("interactionCreate", (interaction) => { */ const context = interaction.context; - console.log(interaction) + console.log(interaction); if(context === Constants.ApplicationCommandContextType.GUILD) { where = "as a server interaction."; diff --git a/index.d.ts b/index.d.ts index 974956649..8883757d6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,8 +224,8 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; - contexts?: Constants['ApplicationCommandContextType'][]; - integrationTypes?: Constants['ApplicationCommandIntegrationTypes'][]; + contexts?: Constants["ApplicationCommandContextType"][]; + integrationTypes?: Constants["ApplicationCommandIntegrationTypes"][]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { diff --git a/lib/Client.js b/lib/Client.js index 95d103964..22569e861 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -663,7 +663,7 @@ class Client extends EventEmitter { command.default_permission = command.defaultPermission; } command.dm_permission = command.dmPermission; - command.integration_types = command.integrationTypes + command.integration_types = command.integrationTypes; return this.requestHandler.request("POST", Endpoints.COMMANDS(this.application.id), true, command).then((command) => new ApplicationCommand(command, this)); } diff --git a/lib/structures/ApplicationCommand.js b/lib/structures/ApplicationCommand.js index 74a5de9af..eb8cf3ba5 100644 --- a/lib/structures/ApplicationCommand.js +++ b/lib/structures/ApplicationCommand.js @@ -62,7 +62,7 @@ class ApplicationCommand extends Base { this.contexts = data.contexts; } if(data.integration_types !== undefined) { - this.integrationTypes = data.integration_types + this.integrationTypes = data.integration_types; } } diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index fa0cc1b38..29427983f 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -107,8 +107,12 @@ class CommandInteraction extends Interaction { data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id); - this.member = guild?.members?.update(data.member, guild); + let guild = this._client.guilds.get(data.guild_id); + if(!guild && this.context === 0) { + guild = this._client.guilds.update(data.guild, this._client); + data.member.id = data.member.user.id; + } + this.member = guild.members.update(data.member, guild); } } From 19ac5e6ce22bc41dc4a492c60a65ec4fb7d1f891 Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 09:52:10 +0630 Subject: [PATCH 19/49] remove magic number --- lib/structures/CommandInteraction.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 29427983f..4f73f7119 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -10,6 +10,7 @@ const Collection = require("../util/Collection"); const Permission = require("./Permission"); const {InteractionResponseTypes} = require("../Constants"); +const { Constants } = require("../.."); /** * Represents an application command interaction. See Interaction for more properties. @@ -108,7 +109,7 @@ class CommandInteraction extends Interaction { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { let guild = this._client.guilds.get(data.guild_id); - if(!guild && this.context === 0) { + if(!guild && this.context === Constants.ApplicationCommandContextType.GUILD) { guild = this._client.guilds.update(data.guild, this._client); data.member.id = data.member.user.id; } From 0c8a24a378cddd41bfe224e51a000ebb565c96cf Mon Sep 17 00:00:00 2001 From: Retro Date: Mon, 26 Aug 2024 10:10:54 +0630 Subject: [PATCH 20/49] update types --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8883757d6..741a14939 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,8 +224,8 @@ declare namespace Eris { description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; name: string; type?: U; - contexts?: Constants["ApplicationCommandContextType"][]; - integrationTypes?: Constants["ApplicationCommandIntegrationTypes"][]; + contexts?: (typeof Constants["ApplicationCommandContextType"][keyof typeof Constants["ApplicationCommandContextType"]])[]; + integrationTypes?: (typeof Constants["ApplicationCommandIntegrationTypes"][keyof typeof Constants["ApplicationCommandIntegrationTypes"]])[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { From 2afdb14db9c092861c73711f1e11649383cfa2b5 Mon Sep 17 00:00:00 2001 From: Retro Date: Tue, 27 Aug 2024 14:48:22 +0630 Subject: [PATCH 21/49] sort properties --- index.d.ts | 28 +++++++++++++++------------- lib/Constants.js | 22 +++++++++++----------- lib/structures/CommandInteraction.js | 5 ++--- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/index.d.ts b/index.d.ts index 741a14939..8954e9bfd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,6 +18,8 @@ declare namespace Eris { // TYPES // Application Commands + type ApplicationCommandContextTypes = (typeof Constants["ApplicationCommandContextType"][keyof typeof Constants["ApplicationCommandContextType"]]); + type ApplicationCommandIntegrationTypes = (typeof Constants["ApplicationCommandIntegrationTypes"][keyof typeof Constants["ApplicationCommandIntegrationTypes"]]); type ApplicationCommandOptions = ApplicationCommandOptionsSubCommand | ApplicationCommandOptionsSubCommandGroup | ApplicationCommandOptionsWithValue; type ApplicationCommandOptionsBoolean = ApplicationCommandOption; type ApplicationCommandOptionsChannel = ApplicationCommandOption; @@ -221,11 +223,10 @@ declare namespace Eris { } /** Generic T is `true` if creating Guild scoped commands, and `false` if not */ interface ApplicationCommandCreateOptions extends ApplicationCommandEditOptions { + contexts?: ApplicationCommandContextTypes[]; description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; + integrationTypes: ApplicationCommandIntegrationTypes[]; name: string; - type?: U; - contexts?: (typeof Constants["ApplicationCommandContextType"][keyof typeof Constants["ApplicationCommandContextType"]])[]; - integrationTypes?: (typeof Constants["ApplicationCommandIntegrationTypes"][keyof typeof Constants["ApplicationCommandIntegrationTypes"]])[]; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { @@ -1899,15 +1900,6 @@ declare namespace Eris { interface Constants { GATEWAY_VERSION: 9; REST_VERSION: 9; - ApplicationCommandContextType: { - GUILD: 0; - BOT_DM: 1; - PRIVATE: 2; - }; - ApplicationCommandIntegrationTypes: { - GUILD_INSTALL: 0; - USER_INSTALL: 1; - }; ActivityFlags: { INSTANCE: 1; JOIN: 2; @@ -1927,6 +1919,15 @@ declare namespace Eris { CUSTOM: 4; COMPETING: 5; }; + ApplicationCommandContextType: { + GUILD: 0; + BOT_DM: 1; + PRIVATE: 2; + }; + ApplicationCommandIntegrationTypes: { + GUILD_INSTALL: 0; + USER_INSTALL: 1; + }; ApplicationCommandOptionTypes: { SUB_COMMAND: 1; SUB_COMMAND_GROUP: 2; @@ -2634,6 +2635,7 @@ declare namespace Eris { /** Generic T is `true` if a Guild scoped command, and `false` if not */ export class ApplicationCommand extends Base { applicationID: string; + contexts: ApplicationCommandContextTypes[]; defaultMemberPermissions: Permission; /** @deprecated */ defaultPermission?: boolean | null; @@ -3520,7 +3522,7 @@ declare namespace Eris { export class CommandInteraction extends Interaction { appPermissions?: Permission; channel: T; - context?: number; + context?: ApplicationCommandContextTypes; data: CommandInteractionData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; diff --git a/lib/Constants.js b/lib/Constants.js index 4b5da125c..358af657c 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -15,17 +15,6 @@ module.exports.ActivityFlags = { EMBEDDED: 1 << 8 }; -module.exports.ApplicationCommandContextType = { - GUILD: 0, - BOT_DM: 1, - PRIVATE: 2 -}; - -module.exports.ApplicationCommandIntegrationTypes = { - GUILD_INSTALL: 0, - USER_INSTALL: 1 -}; - module.exports.ActivityTypes = { GAME: 0, STREAMING: 1, @@ -35,6 +24,17 @@ module.exports.ActivityTypes = { COMPETING: 5 }; +module.exports.ApplicationCommandContextType = { + GUILD: 0, + BOT_DM: 1, + PRIVATE: 2 +}; + +module.exports.ApplicationCommandIntegrationTypes = { + GUILD_INSTALL: 0, + USER_INSTALL: 1 +}; + module.exports.ApplicationCommandOptionTypes = { SUB_COMMAND: 1, SUB_COMMAND_GROUP: 2, diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 4f73f7119..3c27d4beb 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -9,8 +9,7 @@ const Message = require("./Message"); const Collection = require("../util/Collection"); const Permission = require("./Permission"); -const {InteractionResponseTypes} = require("../Constants"); -const { Constants } = require("../.."); +const {InteractionResponseTypes,ApplicationCommandContextType} = require("../Constants"); /** * Represents an application command interaction. See Interaction for more properties. @@ -109,7 +108,7 @@ class CommandInteraction extends Interaction { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { let guild = this._client.guilds.get(data.guild_id); - if(!guild && this.context === Constants.ApplicationCommandContextType.GUILD) { + if(!guild && this.context === ApplicationCommandContextType.GUILD) { guild = this._client.guilds.update(data.guild, this._client); data.member.id = data.member.user.id; } From ac00f71a0ee9730a808087c90d15d5187edc9fe7 Mon Sep 17 00:00:00 2001 From: Retro Date: Tue, 27 Aug 2024 15:56:41 +0630 Subject: [PATCH 22/49] Use a Guild instance chore(lint): add missing space --- lib/structures/CommandInteraction.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 3c27d4beb..691aad95b 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -8,8 +8,9 @@ const Channel = require("./Channel"); const Message = require("./Message"); const Collection = require("../util/Collection"); const Permission = require("./Permission"); +const Guild = require("./Guild"); -const {InteractionResponseTypes,ApplicationCommandContextType} = require("../Constants"); +const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); /** * Represents an application command interaction. See Interaction for more properties. @@ -109,7 +110,7 @@ class CommandInteraction extends Interaction { } else { let guild = this._client.guilds.get(data.guild_id); if(!guild && this.context === ApplicationCommandContextType.GUILD) { - guild = this._client.guilds.update(data.guild, this._client); + guild = new Guild(data.guild, this._client); data.member.id = data.member.user.id; } this.member = guild.members.update(data.member, guild); From 1cc3695cebf44466ca341d1ca2a7e83567eb5375 Mon Sep 17 00:00:00 2001 From: Retro Date: Tue, 27 Aug 2024 16:26:50 +0630 Subject: [PATCH 23/49] enhance user command example --- examples/userCommand.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index fa273e9d4..d75e9b935 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -41,8 +41,8 @@ bot.on("interactionCreate", (interaction) => { */ const context = interaction.context; - console.log(interaction); - + // Check where the command is sent from. + // Keep in mind, context will be the same for commands that are ran as user-installables and guild-invited bots unless user-installables are ran in DMs or are sent in the bot's DMs if(context === Constants.ApplicationCommandContextType.GUILD) { where = "as a server interaction."; } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { From a5fd831a58db7ad065d68caa764854cd5624c43a Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:31:00 +0630 Subject: [PATCH 24/49] fix: Guild not in cache on user-installables --- index.d.ts | 5 ++++- lib/structures/AutocompleteInteraction.js | 12 ++++++++++-- lib/structures/CommandInteraction.js | 5 ++++- lib/structures/ComponentInteraction.js | 12 ++++++++++-- lib/structures/ModalSubmitInteraction.js | 3 +++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8954e9bfd..508d55014 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3494,6 +3494,7 @@ declare namespace Eris { export class AutocompleteInteraction extends Interaction { appPermissions?: Permission; channel: T; + context: ApplicationCommandContextTypes; data: AutocompleteInteractionData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; @@ -3522,7 +3523,7 @@ declare namespace Eris { export class CommandInteraction extends Interaction { appPermissions?: Permission; channel: T; - context?: ApplicationCommandContextTypes; + context: ApplicationCommandContextTypes; data: CommandInteractionData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; @@ -3543,6 +3544,7 @@ declare namespace Eris { export class ComponentInteraction extends Interaction { appPermissions?: Permission; channel: T; + context: ApplicationCommandContextTypes; data: ComponentInteractionButtonData | ComponentInteractionSelectMenuData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; @@ -3720,6 +3722,7 @@ declare namespace Eris { export class ModalSubmitInteraction extends Interaction { channel: T; + context: ApplicationCommandContextTypes; data: ModalSubmitInteractionData; guildID: T extends AnyGuildChannel ? string : undefined; member: T extends AnyGuildChannel ? Member : undefined; diff --git a/lib/structures/AutocompleteInteraction.js b/lib/structures/AutocompleteInteraction.js index c825bc22e..ccac9ac74 100644 --- a/lib/structures/AutocompleteInteraction.js +++ b/lib/structures/AutocompleteInteraction.js @@ -2,13 +2,15 @@ const Interaction = require("./Interaction"); const Permission = require("./Permission"); -const {InteractionResponseTypes} = require("../Constants"); +const Guild = require("./Guild"); +const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); /** * Represents an application command autocomplete interaction. See Interaction for more properties. * @extends Interaction * @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached + * @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @prop {Object} data The data attached to the interaction * @prop {String} data.id The ID of the Application Command * @prop {String} data.name The command name @@ -32,6 +34,8 @@ class AutocompleteInteraction extends Interaction { id: data.channel_id }; + this.context = data.context; + this.data = data.data; if(data.guild_id !== undefined) { @@ -43,7 +47,11 @@ class AutocompleteInteraction extends Interaction { data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id); + let guild = this._client.guilds.get(data.guild_id); + if(!guild && this.context === ApplicationCommandContextType.GUILD) { + guild = new Guild(data.guild, this._client); + data.member.id = data.member.user.id; + } this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 691aad95b..8fe6aa243 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -67,7 +67,10 @@ class CommandInteraction extends Interaction { if(this.channel.guild) { membermap.set(id, this.channel.guild.members.update(member, this.channel.guild)); } else { - const guild = this._client.guilds.get(data.guild_id); + let guild = this._client.guilds.get(data.guild_id); + if(!guild && this.context === ApplicationCommandContextType.GUILD) { + guild = new Guild(data.guild, this._client); + } membermap.set(id, guild.members.update(member, guild)); } }); diff --git a/lib/structures/ComponentInteraction.js b/lib/structures/ComponentInteraction.js index 808364dc1..304a824b1 100644 --- a/lib/structures/ComponentInteraction.js +++ b/lib/structures/ComponentInteraction.js @@ -3,13 +3,15 @@ const Interaction = require("./Interaction"); const Message = require("./Message"); const Permission = require("./Permission"); -const {InteractionResponseTypes} = require("../Constants"); +const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); +const Guild = require("./Guild"); /** * Represents a message component interaction. See Interaction for more properties * @extends Interaction * @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached + * @prop {Number} context Where the component interaction is selected from. [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @prop {Object} data The data attached to the interaction * @prop {Number} data.component_type The type of Message Component * @prop {String} data.custom_id The ID of the Message Component @@ -27,6 +29,8 @@ class ComponentInteraction extends Interaction { id: data.channel_id }; + this.context = data.context; + this.data = data.data; if(data.guild_id !== undefined) { @@ -38,7 +42,11 @@ class ComponentInteraction extends Interaction { data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id); + let guild = this._client.guilds.get(data.guild_id); + if(!guild && data.context === ApplicationCommandContextType.GUILD) { + guild = new Guild(data.guild, this._client); + data.member.id = data.member.user.id; + } this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ModalSubmitInteraction.js b/lib/structures/ModalSubmitInteraction.js index fde21ece0..b7b2443e9 100644 --- a/lib/structures/ModalSubmitInteraction.js +++ b/lib/structures/ModalSubmitInteraction.js @@ -7,6 +7,7 @@ const {InteractionResponseTypes} = require("../Constants"); * Represents a modal submit interaction. See Interaction for more properties * @extends Interaction * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached + * @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types) * @prop {Object} data The data attached to the interaction * @prop {String} data.custom_id The ID of the Modal * @prop {Array} data.components The values submitted by the user @@ -24,6 +25,8 @@ class ModalSubmitInteraction extends Interaction { this.data = data.data; + this.context = data.context; + if(data.guild_id !== undefined) { this.guildID = data.guild_id; } From 62c2f9af3314778183fb4f6060c17f05a5bc5028 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:46:01 +0630 Subject: [PATCH 25/49] wrote guild assignment more efficiently --- lib/structures/AutocompleteInteraction.js | 10 +++------- lib/structures/CommandInteraction.js | 15 ++++----------- lib/structures/ComponentInteraction.js | 10 +++------- lib/structures/ModalSubmitInteraction.js | 5 +++-- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/structures/AutocompleteInteraction.js b/lib/structures/AutocompleteInteraction.js index ccac9ac74..7758eca0d 100644 --- a/lib/structures/AutocompleteInteraction.js +++ b/lib/structures/AutocompleteInteraction.js @@ -3,7 +3,7 @@ const Interaction = require("./Interaction"); const Permission = require("./Permission"); const Guild = require("./Guild"); -const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); +const {InteractionResponseTypes} = require("../Constants"); /** * Represents an application command autocomplete interaction. See Interaction for more properties. @@ -43,15 +43,11 @@ class AutocompleteInteraction extends Interaction { } if(data.member !== undefined) { + data.member.id = data.member.user.id; if(this.channel.guild) { - data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - let guild = this._client.guilds.get(data.guild_id); - if(!guild && this.context === ApplicationCommandContextType.GUILD) { - guild = new Guild(data.guild, this._client); - data.member.id = data.member.user.id; - } + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 8fe6aa243..316ee7418 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -10,7 +10,7 @@ const Collection = require("../util/Collection"); const Permission = require("./Permission"); const Guild = require("./Guild"); -const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); +const {InteractionResponseTypes} = require("../Constants"); /** * Represents an application command interaction. See Interaction for more properties. @@ -67,10 +67,7 @@ class CommandInteraction extends Interaction { if(this.channel.guild) { membermap.set(id, this.channel.guild.members.update(member, this.channel.guild)); } else { - let guild = this._client.guilds.get(data.guild_id); - if(!guild && this.context === ApplicationCommandContextType.GUILD) { - guild = new Guild(data.guild, this._client); - } + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); membermap.set(id, guild.members.update(member, guild)); } }); @@ -107,15 +104,11 @@ class CommandInteraction extends Interaction { } if(data.member !== undefined) { + data.member.id = data.member.user.id; if(this.channel.guild) { - data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - let guild = this._client.guilds.get(data.guild_id); - if(!guild && this.context === ApplicationCommandContextType.GUILD) { - guild = new Guild(data.guild, this._client); - data.member.id = data.member.user.id; - } + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ComponentInteraction.js b/lib/structures/ComponentInteraction.js index 304a824b1..aacfe97fb 100644 --- a/lib/structures/ComponentInteraction.js +++ b/lib/structures/ComponentInteraction.js @@ -3,7 +3,7 @@ const Interaction = require("./Interaction"); const Message = require("./Message"); const Permission = require("./Permission"); -const {InteractionResponseTypes, ApplicationCommandContextType} = require("../Constants"); +const {InteractionResponseTypes} = require("../Constants"); const Guild = require("./Guild"); /** @@ -38,15 +38,11 @@ class ComponentInteraction extends Interaction { } if(data.member !== undefined) { + data.member.id = data.member.user.id; if(this.channel.guild) { - data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - let guild = this._client.guilds.get(data.guild_id); - if(!guild && data.context === ApplicationCommandContextType.GUILD) { - guild = new Guild(data.guild, this._client); - data.member.id = data.member.user.id; - } + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ModalSubmitInteraction.js b/lib/structures/ModalSubmitInteraction.js index b7b2443e9..88e5f9e8f 100644 --- a/lib/structures/ModalSubmitInteraction.js +++ b/lib/structures/ModalSubmitInteraction.js @@ -2,6 +2,7 @@ const Interaction = require("./Interaction"); const {InteractionResponseTypes} = require("../Constants"); +const Guild = require("./Guild") /** * Represents a modal submit interaction. See Interaction for more properties @@ -32,11 +33,11 @@ class ModalSubmitInteraction extends Interaction { } if(data.member !== undefined) { + data.member.id = data.member.user.id; if(this.channel.guild) { - data.member.id = data.member.user.id; this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id); + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client);; this.member = guild.members.update(data.member, guild); } } From 5d5a5ffc7b6e6f9743b0cb0527f4a34081853156 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:50:04 +0630 Subject: [PATCH 26/49] chore: lint --- lib/structures/ModalSubmitInteraction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/structures/ModalSubmitInteraction.js b/lib/structures/ModalSubmitInteraction.js index 88e5f9e8f..781af908d 100644 --- a/lib/structures/ModalSubmitInteraction.js +++ b/lib/structures/ModalSubmitInteraction.js @@ -2,7 +2,7 @@ const Interaction = require("./Interaction"); const {InteractionResponseTypes} = require("../Constants"); -const Guild = require("./Guild") +const Guild = require("./Guild"); /** * Represents a modal submit interaction. See Interaction for more properties @@ -37,7 +37,7 @@ class ModalSubmitInteraction extends Interaction { if(this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client);; + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } From adfa5af87faa896ad0c5d4069cf59d0805d1c863 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 31 Aug 2024 13:36:18 +0100 Subject: [PATCH 27/49] lint --- examples/userCommand.js | 88 ++++++++++++++++++++--------------------- lib/Constants.js | 10 ++--- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index d75e9b935..3df076e21 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -3,59 +3,59 @@ const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot token", { - intents: [] + intents: [], }); bot.on("ready", () => { - console.log("connected!"); - bot.createCommand({ - type: Constants.ApplicationCommandTypes.CHAT_INPUT, - name: "ping", - description: "Reply with pong", - options: [], - /* The following 2 lines set the state of the application command as both user installable and guild installable */ - contexts: [ - Constants.ApplicationCommandContextType.GUILD, - Constants.ApplicationCommandContextType.BOT_DM, - Constants.ApplicationCommandContextType.PRIVATE - ], - integrationTypes: [ - Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, - Constants.ApplicationCommandIntegrationTypes.USER_INSTALL - ] - }); + console.log("connected!"); + bot.createCommand({ + type: Constants.ApplicationCommandTypes.CHAT_INPUT, + name: "ping", + description: "Reply with pong", + options: [], + /* The following 2 lines set the state of the application command as both user installable and guild installable */ + contexts: [ + Constants.ApplicationCommandContextType.GUILD, + Constants.ApplicationCommandContextType.BOT_DM, + Constants.ApplicationCommandContextType.PRIVATE, + ], + integrationTypes: [ + Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, + Constants.ApplicationCommandIntegrationTypes.USER_INSTALL, + ], + }); }); bot.on("interactionCreate", (interaction) => { - if(interaction instanceof Eris.CommandInteraction) { - if(interaction.data.name === "ping") { - let where = ""; - /** - * .context includes information of where the command was executed. - * if .context matches ... - * Constants.ApplicationCommandContextType.GUILD it means it is executed from a server - * Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM - * Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable - * - * Incase of BOT_DM and PRIVATE, the CommandInteraction will lose all its guild related properties such as the guild information and member data - */ - const context = interaction.context; + if (interaction instanceof Eris.CommandInteraction) { + if (interaction.data.name === "ping") { + let where = ""; + /** + * .context includes information of where the command was executed. + * if .context matches ... + * Constants.ApplicationCommandContextType.GUILD it means it is executed from a server + * Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM + * Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable + * + * Incase of BOT_DM and PRIVATE, the CommandInteraction will lose all its guild related properties such as the guild information and member data + */ + const context = interaction.context; - // Check where the command is sent from. - // Keep in mind, context will be the same for commands that are ran as user-installables and guild-invited bots unless user-installables are ran in DMs or are sent in the bot's DMs - if(context === Constants.ApplicationCommandContextType.GUILD) { - where = "as a server interaction."; - } else if(context === Constants.ApplicationCommandContextType.BOT_DM) { - where = "as a bot DM interaction."; - } else if(context === Constants.ApplicationCommandContextType.PRIVATE) { - where = "as a private interaction (user installable)."; - } else { - where = "as a server interaction."; - } + // Check where the command is sent from. + // Keep in mind, context will be the same for commands that are ran as user-installables and guild-invited bots unless user-installables are ran in DMs or are sent in the bot's DMs + if (context === Constants.ApplicationCommandContextType.GUILD) { + where = "as a server interaction."; + } else if (context === Constants.ApplicationCommandContextType.BOT_DM) { + where = "as a bot DM interaction."; + } else if (context === Constants.ApplicationCommandContextType.PRIVATE) { + where = "as a private interaction (user installable)."; + } else { + where = "as a server interaction."; + } - interaction.createMessage(`🏓 pong ${where}`); - } + interaction.createMessage(`🏓 pong ${where}`); } + } }); bot.connect(); diff --git a/lib/Constants.js b/lib/Constants.js index d68e88e26..4eac3961e 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -25,14 +25,14 @@ module.exports.ActivityTypes = { }; module.exports.ApplicationCommandContextType = { - GUILD: 0, - BOT_DM: 1, - PRIVATE: 2 + GUILD: 0, + BOT_DM: 1, + PRIVATE: 2, }; module.exports.ApplicationCommandIntegrationTypes = { - GUILD_INSTALL: 0, - USER_INSTALL: 1 + GUILD_INSTALL: 0, + USER_INSTALL: 1, }; module.exports.ApplicationCommandOptionTypes = { From 03badc8ee9882100fcacc3b3f0f3d18a030433e8 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:46:11 +0630 Subject: [PATCH 28/49] fix(typings): Type mismatch between discord and lib --- index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 508d55014..78f55812d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -225,8 +225,9 @@ declare namespace Eris { interface ApplicationCommandCreateOptions extends ApplicationCommandEditOptions { contexts?: ApplicationCommandContextTypes[]; description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void; - integrationTypes: ApplicationCommandIntegrationTypes[]; + integrationTypes?: ApplicationCommandIntegrationTypes[]; name: string; + type?: U; } /** Generic T is `true` if editing Guild scoped commands, and `false` if not */ interface ApplicationCommandBulkEditOptions extends ApplicationCommandCreateOptions { @@ -2635,7 +2636,7 @@ declare namespace Eris { /** Generic T is `true` if a Guild scoped command, and `false` if not */ export class ApplicationCommand extends Base { applicationID: string; - contexts: ApplicationCommandContextTypes[]; + contexts?: ApplicationCommandContextTypes[]; defaultMemberPermissions: Permission; /** @deprecated */ defaultPermission?: boolean | null; @@ -2643,6 +2644,7 @@ declare namespace Eris { descriptionLocalizations?: U extends "CHAT_INPUT" ? Record | null : null; dmPermission?: boolean; guild: T extends true ? PossiblyUncachedGuild : never; + integrationTypes?: ApplicationCommandIntegrationTypes[]; name: string; nameLocalizations?: Record | null; nsfw?: boolean; From f212f2f35d7b3c3d113c0114cad2b75801347496 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:08:38 +0630 Subject: [PATCH 29/49] chore(add types) --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index c1279d5b9..eb33fbf5c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1899,6 +1899,8 @@ declare namespace Eris { [key: string]: unknown; } interface OAuthApplicationInfo { + approximate_guild_count?: number; + approximate_user_install_count?: number; bot?: PartialUser; bot_public: boolean; bot_require_code_grant: boolean; From fd9abb18171f6ba5def3deb3147ee75aada71113 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:14:02 +0630 Subject: [PATCH 30/49] chore(format) --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index eb33fbf5c..ceaf12063 100644 --- a/index.d.ts +++ b/index.d.ts @@ -878,7 +878,7 @@ declare namespace Eris { channelDelete: [channel: Exclude]; channelPinUpdate: [channel: TextableChannel, timestamp: number, oldTimestamp: number]; channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldForumChannel | OldGuildTextChannel | OldVoiceChannel] - | [channel: GroupChannel, oldChannel: OldGroupChannel]; + | [channel: GroupChannel, oldChannel: OldGroupChannel]; connect: [id: number]; debug: [message: string, id?: number]; disconnect: []; @@ -935,7 +935,7 @@ declare namespace Eris { threadMemberUpdate: [channel: AnyThreadChannel, member: ThreadMember, oldMember: OldThreadMember]; threadUpdate: [channel: AnyThreadChannel, oldChannel: OldThread | null]; typingStart: [channel: AnyGuildTextableChannel | Uncached, user: User | Uncached, member: Member] - | [channel: DMChannel | Uncached, user: User | Uncached, member: null]; + | [channel: DMChannel | Uncached, user: User | Uncached, member: null]; unavailableGuildCreate: [guild: UnavailableGuild]; unknown: [packet: RawPacket, id?: number]; userUpdate: [user: User, oldUser: PartialUser | null]; From ed04a2828e0567f496ff640edc9550eb9a4a447c Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:24:39 +0630 Subject: [PATCH 31/49] no constructor for autocomplete --- index.d.ts | 2 +- lib/structures/AutocompleteInteraction.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0dd032fa3..3e751791d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1956,7 +1956,7 @@ declare namespace Eris { /** Generic T is `true` if a Guild scoped command, and `false` if not */ export class ApplicationCommand extends Base { applicationID: string; - contexts?: ApplicationCommandContextTypes[]; + contexts?: ApplicationCommandContextTypes[] | null; defaultMemberPermissions: Permission; /** @deprecated */ defaultPermission?: boolean | null; diff --git a/lib/structures/AutocompleteInteraction.js b/lib/structures/AutocompleteInteraction.js index 88a8aad78..f9d8ee549 100644 --- a/lib/structures/AutocompleteInteraction.js +++ b/lib/structures/AutocompleteInteraction.js @@ -46,7 +46,7 @@ class AutocompleteInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); + const guild = this._client.guilds.get(data.guild_id) || data.guild; this.member = guild.members.update(data.member, guild); } } From 89ea9d1d8c8c1cfddce5f9dfc6ab656b439e688c Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:29:12 +0630 Subject: [PATCH 32/49] assign only data.guild --- lib/structures/CommandInteraction.js | 2 +- lib/structures/ComponentInteraction.js | 2 +- lib/structures/ModalSubmitInteraction.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index a97ed9e20..8bc60fe57 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -107,7 +107,7 @@ class CommandInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); + const guild = this._client.guilds.get(data.guild_id) || data.guild; this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ComponentInteraction.js b/lib/structures/ComponentInteraction.js index 54e76558a..6961a6887 100644 --- a/lib/structures/ComponentInteraction.js +++ b/lib/structures/ComponentInteraction.js @@ -41,7 +41,7 @@ class ComponentInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); + const guild = this._client.guilds.get(data.guild_id) || data.guild; this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ModalSubmitInteraction.js b/lib/structures/ModalSubmitInteraction.js index 999c4a49c..74b38657f 100644 --- a/lib/structures/ModalSubmitInteraction.js +++ b/lib/structures/ModalSubmitInteraction.js @@ -36,7 +36,7 @@ class ModalSubmitInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); + const guild = this._client.guilds.get(data.guild_id) || data.guild; this.member = guild.members.update(data.member, guild); } } From 7fd0d8098bf1768a8ad4d038af4f5439107e0ca6 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:20:39 +0630 Subject: [PATCH 33/49] revert --- lib/structures/AutocompleteInteraction.js | 2 +- lib/structures/CommandInteraction.js | 2 +- lib/structures/ComponentInteraction.js | 2 +- lib/structures/ModalSubmitInteraction.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/structures/AutocompleteInteraction.js b/lib/structures/AutocompleteInteraction.js index f9d8ee549..88a8aad78 100644 --- a/lib/structures/AutocompleteInteraction.js +++ b/lib/structures/AutocompleteInteraction.js @@ -46,7 +46,7 @@ class AutocompleteInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || data.guild; + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index 8bc60fe57..a97ed9e20 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -107,7 +107,7 @@ class CommandInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || data.guild; + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ComponentInteraction.js b/lib/structures/ComponentInteraction.js index 6961a6887..54e76558a 100644 --- a/lib/structures/ComponentInteraction.js +++ b/lib/structures/ComponentInteraction.js @@ -41,7 +41,7 @@ class ComponentInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || data.guild; + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } diff --git a/lib/structures/ModalSubmitInteraction.js b/lib/structures/ModalSubmitInteraction.js index 74b38657f..999c4a49c 100644 --- a/lib/structures/ModalSubmitInteraction.js +++ b/lib/structures/ModalSubmitInteraction.js @@ -36,7 +36,7 @@ class ModalSubmitInteraction extends Interaction { if (this.channel.guild) { this.member = this.channel.guild.members.update(data.member, this.channel.guild); } else { - const guild = this._client.guilds.get(data.guild_id) || data.guild; + const guild = this._client.guilds.get(data.guild_id) || new Guild(data.guild, this._client); this.member = guild.members.update(data.member, guild); } } From 0533eaf4a4acd4ab799af9acf3eb29400b7ab598 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:32:57 +0630 Subject: [PATCH 34/49] add authorizingIntegrationOwners --- index.d.ts | 5 +++++ lib/Constants.d.ts | 1 + lib/Constants.js | 1 + lib/structures/Interaction.js | 8 +++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 3e751791d..7dc5adeb7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1309,6 +1309,10 @@ declare namespace Eris { target_id?: string; options: InteractionDataOptions[]; } + interface AuthorizingIntegrationOwners { + guildInstall?: string; + userInstall: string; + } interface CommandInteractionData { id: string; name: string; @@ -2834,6 +2838,7 @@ declare namespace Eris { export class Interaction extends Base { acknowledged: boolean; applicationID: string; + authorizingIntegrationOwners: AuthorizingIntegrationOwners; id: string; token: string; type: number; diff --git a/lib/Constants.d.ts b/lib/Constants.d.ts index 1c0ed6f7e..2d4b51eaa 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -560,6 +560,7 @@ export default interface Constants { allText: 633854226857041n; allVoice: 954930478188305n; all: 985162418487295n; + useExternalApps: 1125899906842624n; }; PollLayoutTypes: { DEFAULT: 1; diff --git a/lib/Constants.js b/lib/Constants.js index 3bf19b365..3cd1560a9 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -646,6 +646,7 @@ const Permissions = { // Unknown 47 setVoiceChannelStatus: 1n << 48n, sendPolls: 1n << 49n, + useExternalApps: 1n << 50n }; Permissions.allGuild = Permissions.kickMembers | Permissions.banMembers diff --git a/lib/structures/Interaction.js b/lib/structures/Interaction.js index 04b54519f..c9cab7b73 100644 --- a/lib/structures/Interaction.js +++ b/lib/structures/Interaction.js @@ -1,12 +1,13 @@ "use strict"; const Base = require("./Base"); -const { InteractionTypes } = require("../Constants"); +const { InteractionTypes, ApplicationCommandIntegrationTypes } = require("../Constants"); /** * Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, AutocompleteInteraction, ModalSubmitInteraction, and UnknownInteraction. * @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged * @prop {String} applicationID The ID of the interaction's application + * @prop {object} authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID * @prop {Number} createdAt Timestamp of the interaction's creation * @prop {String} id The ID of the interaction * @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.) @@ -16,9 +17,14 @@ const { InteractionTypes } = require("../Constants"); class Interaction extends Base { constructor(data, client) { super(data.id); + console.log(data) // TODO: REMOVE CONSOLE LOG DEBUG this._client = client; this.applicationID = data.application_id; + this.authorizingIntegrationOwners = { + userInstall: data.authorizing_integration_owners[ApplicationCommandIntegrationTypes.USER_INSTALL], + guildInstall: data.authorizing_integration_owners[ApplicationCommandIntegrationTypes.GUILD_INSTALL] + }; this.token = data.token; this.type = data.type; this.version = data.version; From 1fa31d3987de72eaf9b7f62a8ecd3b5cc332ec83 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:59:58 +0630 Subject: [PATCH 35/49] chore(lint) && integration_types_configuration --- examples/components.js | 4 ++-- examples/userCommand.js | 5 +++-- index.d.ts | 10 ++++++++++ lib/Constants.js | 2 +- lib/structures/Interaction.js | 5 ++--- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/components.js b/examples/components.js index 529d37ae4..3d36188a7 100644 --- a/examples/components.js +++ b/examples/components.js @@ -75,8 +75,8 @@ bot.on("messageCreate", (msg) => { // When a message is created default_values: [ // List of default values for auto-populated select menus https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure { id: "[Insert default channel id here]", - type: "channel" - } + type: "channel", + }, ], min_values: 1, max_values: 1, diff --git a/examples/userCommand.js b/examples/userCommand.js index 3df076e21..48322448c 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -2,12 +2,13 @@ const Eris = require("eris"); const Constants = Eris.Constants; -const bot = new Eris("Bot token", { +const bot = new Eris.Client("Bot token", { intents: [], }); -bot.on("ready", () => { +bot.on("ready", async () => { console.log("connected!"); + console.log((await bot.getOAuthApplication()).integration_types_config); bot.createCommand({ type: Constants.ApplicationCommandTypes.CHAT_INPUT, name: "ping", diff --git a/index.d.ts b/index.d.ts index 88835bc55..4a3137504 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2006,6 +2006,10 @@ declare namespace Eris { description: string; icon: string | null; id: string; + integration_types_config: { + 0?: OAuthApplicationIntegrationTypeConfiguration; + 1?: OAuthApplicationIntegrationTypeConfiguration; + }; // TODO: Configure types for this properly name: string; owner: PartialUser; privacy_policy_url?: string; @@ -2017,6 +2021,12 @@ declare namespace Eris { terms_of_service_url?: string; verify_key: string; } + interface OAuthApplicationIntegrationTypeConfiguration { + oauth2_install_params?: { + scopes: string[]; + permissions: string; + }; + } interface OAuthTeamInfo { icon: string | null; id: string; diff --git a/lib/Constants.js b/lib/Constants.js index b652e3af3..82338591c 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -655,7 +655,7 @@ const Permissions = { // Unknown 47 setVoiceChannelStatus: 1n << 48n, sendPolls: 1n << 49n, - useExternalApps: 1n << 50n + useExternalApps: 1n << 50n, }; Permissions.allGuild = Permissions.kickMembers | Permissions.banMembers diff --git a/lib/structures/Interaction.js b/lib/structures/Interaction.js index c9cab7b73..55ed0ab9a 100644 --- a/lib/structures/Interaction.js +++ b/lib/structures/Interaction.js @@ -7,7 +7,7 @@ const { InteractionTypes, ApplicationCommandIntegrationTypes } = require("../Con * Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, AutocompleteInteraction, ModalSubmitInteraction, and UnknownInteraction. * @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged * @prop {String} applicationID The ID of the interaction's application - * @prop {object} authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID + * @prop {Object} authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID * @prop {Number} createdAt Timestamp of the interaction's creation * @prop {String} id The ID of the interaction * @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.) @@ -17,13 +17,12 @@ const { InteractionTypes, ApplicationCommandIntegrationTypes } = require("../Con class Interaction extends Base { constructor(data, client) { super(data.id); - console.log(data) // TODO: REMOVE CONSOLE LOG DEBUG this._client = client; this.applicationID = data.application_id; this.authorizingIntegrationOwners = { userInstall: data.authorizing_integration_owners[ApplicationCommandIntegrationTypes.USER_INSTALL], - guildInstall: data.authorizing_integration_owners[ApplicationCommandIntegrationTypes.GUILD_INSTALL] + guildInstall: data.authorizing_integration_owners[ApplicationCommandIntegrationTypes.GUILD_INSTALL], }; this.token = data.token; this.type = data.type; From f22ad929600344ead771e61414195274fb8454a4 Mon Sep 17 00:00:00 2001 From: Retro <70205403+retrouser955@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:27:10 +0630 Subject: [PATCH 36/49] add install params and custom install url --- examples/userCommand.js | 1 - index.d.ts | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/userCommand.js b/examples/userCommand.js index 48322448c..e60469304 100644 --- a/examples/userCommand.js +++ b/examples/userCommand.js @@ -8,7 +8,6 @@ const bot = new Eris.Client("Bot token", { bot.on("ready", async () => { console.log("connected!"); - console.log((await bot.getOAuthApplication()).integration_types_config); bot.createCommand({ type: Constants.ApplicationCommandTypes.CHAT_INPUT, name: "ping", diff --git a/index.d.ts b/index.d.ts index 4a3137504..229a3be5f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2003,6 +2003,7 @@ declare namespace Eris { bot?: PartialUser; bot_public: boolean; bot_require_code_grant: boolean; + custom_install_url?: string; description: string; icon: string | null; id: string; @@ -2010,6 +2011,10 @@ declare namespace Eris { 0?: OAuthApplicationIntegrationTypeConfiguration; 1?: OAuthApplicationIntegrationTypeConfiguration; }; // TODO: Configure types for this properly + install_params?: { + scopes: string[], + permissions: string + } name: string; owner: PartialUser; privacy_policy_url?: string; From 391188af427ebcc0153c78ca319c6eee70093ebe Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Fri, 13 Dec 2024 21:27:58 +0630 Subject: [PATCH 37/49] chore(lint): dts --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index d1546ef4d..3804a94ce 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2024,9 +2024,9 @@ declare namespace Eris { 1?: OAuthApplicationIntegrationTypeConfiguration; }; // TODO: Configure types for this properly install_params?: { - scopes: string[], - permissions: string - } + scopes: string[]; + permissions: string; + }; name: string; owner: PartialUser; privacy_policy_url?: string; From 3cb938f733124cdd8754e7036057763444d33428 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Fri, 13 Dec 2024 21:40:11 +0630 Subject: [PATCH 38/49] deprecate `.interaction` --- index.d.ts | 1 + lib/structures/Message.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 3804a94ce..f17fa6ea6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3151,6 +3151,7 @@ declare namespace Eris { flags: number; guildID: T extends GuildTextableWithThreads ? string : undefined; id: string; + /** @deprecated */ interaction: MessageInteraction | null; jumpLink: string; member: T extends GuildTextableWithThreads ? Member : null; diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 0f3d8aed3..bff99a1d1 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -27,7 +27,7 @@ const User = require("./User"); * @prop {Number} flags Message flags (see constants) * @prop {String?} guildID The ID of the guild this message is in (undefined if in DMs) * @prop {String} id The ID of the message - * @prop {Object?} interaction An object containing info about the interaction the message is responding to, if applicable + * @prop {Object?} interaction [DEPRECATED] An object containing info about the interaction the message is responding to, if applicable * @prop {String} interaction.id The ID of the interaction * @prop {Member?} interaction.member The member who invoked the interaction * @prop {String} interaction.name The name of the command From 545fb504eabbf1a321f0bb315cb1d3e9b82a7f7f Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:23:13 +0630 Subject: [PATCH 39/49] feat(interaction metadata): Init types --- index.d.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.d.ts b/index.d.ts index f17fa6ea6..e6bfeaaf6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1613,6 +1613,26 @@ declare namespace Eris { type: InteractionTypes; user: User; } + interface BaseMessageMetadata { + authorizingIntegrationOwners: AuthorizingIntegrationOwners; + id: string; + originalResponseMessageID?: string; + type: InteractionTypes; + user: User; + } + interface ApplicationCommandInteractionMetadata extends BaseMessageMetadata { + targetUser?: User; + targetMessageID?: string; + type: Constants['InteractionTypes']['APPLICATION_COMMAND']; + } + interface MessageComponentInteractionMetadata extends BaseMessageMetadata { + interactionMessageID: string; + type: Constants['InteractionTypes']['MESSAGE_COMPONENT']; + } + interface ModelSubmitInteractionMetadata extends BaseMessageMetadata { + triggeringInteractionMetadata: MessageComponentInteractionMetadata | ApplicationCommandInteractionMetadata; + type: Constants['InteractionTypes']['MODAL_SUBMIT']; + } interface MessageReference extends MessageReferenceBase { channelID: string; } From dce393c91f91dd0a470dd95e173bb6ddb7383a56 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:23:47 +0630 Subject: [PATCH 40/49] chore(lint) --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index e6bfeaaf6..799ac72f7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1623,15 +1623,15 @@ declare namespace Eris { interface ApplicationCommandInteractionMetadata extends BaseMessageMetadata { targetUser?: User; targetMessageID?: string; - type: Constants['InteractionTypes']['APPLICATION_COMMAND']; + type: Constants["InteractionTypes"]["APPLICATION_COMMAND"]; } interface MessageComponentInteractionMetadata extends BaseMessageMetadata { interactionMessageID: string; - type: Constants['InteractionTypes']['MESSAGE_COMPONENT']; + type: Constants["InteractionTypes"]["MESSAGE_COMPONENT"]; } interface ModelSubmitInteractionMetadata extends BaseMessageMetadata { triggeringInteractionMetadata: MessageComponentInteractionMetadata | ApplicationCommandInteractionMetadata; - type: Constants['InteractionTypes']['MODAL_SUBMIT']; + type: Constants["InteractionTypes"]["MODAL_SUBMIT"]; } interface MessageReference extends MessageReferenceBase { channelID: string; From 3bb0f7ca7f0984370286279335dfa87c1ef111de Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:44:58 +0630 Subject: [PATCH 41/49] update types --- index.d.ts | 2 ++ lib/structures/Message.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/index.d.ts b/index.d.ts index 799ac72f7..496a341da 100644 --- a/index.d.ts +++ b/index.d.ts @@ -170,6 +170,7 @@ declare namespace Eris { type SelectMenuNonResolvedTypes = Constants["ComponentTypes"][keyof Pick]; type SelectMenuResolvedTypes = Constants["ComponentTypes"][keyof Pick]; type SelectMenuTypes = SelectMenuNonResolvedTypes | SelectMenuResolvedTypes; + type MessageInteractionMetadata = MessageComponentInteractionMetadata | ApplicationCommandInteractionMetadata | ModelSubmitInteractionMetadata; // Permission type PermissionType = Constants["PermissionOverwriteTypes"][keyof Constants["PermissionOverwriteTypes"]]; @@ -3173,6 +3174,7 @@ declare namespace Eris { id: string; /** @deprecated */ interaction: MessageInteraction | null; + interactionMetadata: MessageInteractionMetadata | null; jumpLink: string; member: T extends GuildTextableWithThreads ? Member : null; mentionEveryone: boolean; diff --git a/lib/structures/Message.js b/lib/structures/Message.js index bff99a1d1..57639372d 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -149,6 +149,8 @@ class Message extends Base { this.interaction = null; } + // TODO: Implement .interactionMetadata from data.interaction_metadata + if (this.channel.guild) { if (data.member) { data.member.id = this.author.id; From 155f66985bdd2ea9a6c629f9f40bdbc16e314864 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Tue, 17 Dec 2024 20:37:09 +0630 Subject: [PATCH 42/49] updated message interaction metadata --- lib/structures/Message.js | 68 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 57639372d..be83972e0 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -2,9 +2,67 @@ const Base = require("./Base"); const Endpoints = require("../rest/Endpoints"); -const { MessageFlags } = require("../Constants"); +const { MessageFlags, InteractionTypes } = require("../Constants"); const User = require("./User"); +function parseInteractionMetadata(client, data) { + switch (data.type) { + case InteractionTypes.APPLICATION_COMMAND: { + return parseMetadataApplicationCommand(client, data); + } + case InteractionTypes.MESSAGE_COMPONENT: { + return parseMetadataMessageComponent(client, data); + } + default: { // model submit + return parseMetadataModelSubmit(client, data); + } + } +} + +function parseBaseMetadata(client, data) { + const baseMetadata = { + authorizingIntegrationOwners: data.authorizing_integration_owners, + id: data.id, + originalResponseMessageID: data.original_response_message_id, + type: data.type, + user: client.users.update(data.user, client), + }; + + return baseMetadata; +} + +function parseMetadataApplicationCommand(client, data) { + const baseData = parseBaseMetadata(client, data); + if (data.target_user) { + baseData.targetUser = client.users.update(data.target_user, client); + } + baseData.targetMessageID = data.target_message_id; + return baseData; +} + +function parseMetadataMessageComponent(client, data) { + const baseData = parseBaseMetadata(client, data); + return { + ...baseData, + interactionMessageID: data.interaction_message_id, + }; +} + +function parseMetadataModelSubmit(client, data) { + const baseData = parseBaseMetadata(client, data); + + switch (data.triggering_interaction_metadata.type) { + case InteractionTypes.APPLICATION_COMMAND: + baseData.triggeringInteractionMetadata = parseMetadataApplicationCommand(client, data.triggering_interaction_metadata); + break; + default: // type message component + baseData.triggeringInteractionMetadata = parseMetadataApplicationCommand(client, data.triggering_interaction_metadata); + break; + } + + return baseData; +} + /** * Represents a message * @prop {Object?} activity The activity specified in the message @@ -13,7 +71,7 @@ const User = require("./User"); * @prop {Array} attachments Array of attachments * @prop {User} author The message author * @prop {Object} call The call associated with the message - * @prop {Number?} call.endedTimestamp The time when the call ended + * @prop {Number?} call.endedTimestamp The time when the call end * @prop {Array} call.participants An array of user IDs that participated in the call * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the id if the channel is not cached. * @prop {Array} channelMentions Array of mentions channels' ids @@ -149,7 +207,11 @@ class Message extends Base { this.interaction = null; } - // TODO: Implement .interactionMetadata from data.interaction_metadata + if (data.interaction_metadata) { + this.interactionMetadata = parseInteractionMetadata(this._client, data.interaction_metadata); + } else { + this.interactionMetadata = null; + } if (this.channel.guild) { if (data.member) { From 9f4719108dbf5724349d978117f73d2b246595c1 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:27:21 +0630 Subject: [PATCH 43/49] docs: add jsdoc --- index.d.ts | 4 ++-- lib/structures/Message.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 496a341da..9bac2e921 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1622,12 +1622,12 @@ declare namespace Eris { user: User; } interface ApplicationCommandInteractionMetadata extends BaseMessageMetadata { - targetUser?: User; targetMessageID?: string; + targetUser?: User; type: Constants["InteractionTypes"]["APPLICATION_COMMAND"]; } interface MessageComponentInteractionMetadata extends BaseMessageMetadata { - interactionMessageID: string; + interactedMessageID: string; type: Constants["InteractionTypes"]["MESSAGE_COMPONENT"]; } interface ModelSubmitInteractionMetadata extends BaseMessageMetadata { diff --git a/lib/structures/Message.js b/lib/structures/Message.js index be83972e0..a9d9a5731 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -44,7 +44,7 @@ function parseMetadataMessageComponent(client, data) { const baseData = parseBaseMetadata(client, data); return { ...baseData, - interactionMessageID: data.interaction_message_id, + interactedMessageID: data.interacted_message_id, }; } @@ -91,6 +91,16 @@ function parseMetadataModelSubmit(client, data) { * @prop {String} interaction.name The name of the command * @prop {Number} interaction.type The type of interaction * @prop {User} interaction.user The user who invoked the interaction + * @prop {Object?} interactionMetadata An object containing info about the interaction the message is responding to, if applicable + * @prop {string} interactionMetadata.authorizingIntegrationOwners authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID + * @prop {string} interactionMetadata.id The ID of the interaction that the message is replying to + * @prop {string?} interactionMetadata.interactedMessageID ID of the message that contained the interactive component + * @prop {string} interactionMetadata.originalResponseMessageID The ID of the original message, if applicable + * @prop {number} interactionMetadata.type The type of the interaction + * @prop {Object?} interactionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. + * @prop {Object?} interactionMetadata.targetUser The user the command was run on, present only on user command interaction + * @prop {Object?} interactionMetadata.triggeringInteractionMetadata Metadata for the interaction that was used to open the modal, of type `MessageComponentInteractionMetadata` or `ApplicationCommandInteractionMetadata`; + * @prop {Object} interactionMetadata.user The user who originally used the interaction * @prop {String} jumpLink The url used by Discord clients to jump to this message * @prop {Member?} member The message author with server-specific data * @prop {Boolean} mentionEveryone Whether the message mentions everyone/here or not From aefd65461e9ed77fd63977a271224c3b3b19ccae Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:29:33 +0630 Subject: [PATCH 44/49] docs(jsdoc): Complete types --- lib/structures/Message.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index a9d9a5731..a65322ccb 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -100,7 +100,12 @@ function parseMetadataModelSubmit(client, data) { * @prop {Object?} interactionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. * @prop {Object?} interactionMetadata.targetUser The user the command was run on, present only on user command interaction * @prop {Object?} interactionMetadata.triggeringInteractionMetadata Metadata for the interaction that was used to open the modal, of type `MessageComponentInteractionMetadata` or `ApplicationCommandInteractionMetadata`; - * @prop {Object} interactionMetadata.user The user who originally used the interaction + * @prop {string} interactionMetadata.triggeringInteractionMetadata.id The ID of the interaction that the message is replying to + * @prop {string?} interactionMetadata.triggeringInteractionMetadata.interactedMessageID ID of the message that contained the interactive component + * @prop {Object} interactionMetadata.triggeringInteractionMetadata.user The user who originally used the interaction + * @prop {number} interactionMetadata.triggeringInteractionMetadata.type The type of the interaction + * @prop {Object?} interactionMetadata.triggeringInteractionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. + * @prop {Object?} interactionMetadata.triggeringInteractionMetadata.targetUser The user the command was run on, present only on user command interaction * @prop {String} jumpLink The url used by Discord clients to jump to this message * @prop {Member?} member The message author with server-specific data * @prop {Boolean} mentionEveryone Whether the message mentions everyone/here or not From 8fd9f8a4a119351030aef1e26d63eddeeef64dff Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:30:17 +0630 Subject: [PATCH 45/49] chore: lint --- lib/structures/Message.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index a65322ccb..92d757bc0 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -92,18 +92,18 @@ function parseMetadataModelSubmit(client, data) { * @prop {Number} interaction.type The type of interaction * @prop {User} interaction.user The user who invoked the interaction * @prop {Object?} interactionMetadata An object containing info about the interaction the message is responding to, if applicable - * @prop {string} interactionMetadata.authorizingIntegrationOwners authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID - * @prop {string} interactionMetadata.id The ID of the interaction that the message is replying to + * @prop {String} interactionMetadata.authorizingIntegrationOwners authorizingIntegrationOwners An object containing the values IDs of the user and/or guild that authorized the app. guildInstall for GuildID and userInstall for UserID + * @prop {String} interactionMetadata.id The ID of the interaction that the message is replying to * @prop {string?} interactionMetadata.interactedMessageID ID of the message that contained the interactive component - * @prop {string} interactionMetadata.originalResponseMessageID The ID of the original message, if applicable - * @prop {number} interactionMetadata.type The type of the interaction + * @prop {String} interactionMetadata.originalResponseMessageID The ID of the original message, if applicable + * @prop {Number} interactionMetadata.type The type of the interaction * @prop {Object?} interactionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. * @prop {Object?} interactionMetadata.targetUser The user the command was run on, present only on user command interaction * @prop {Object?} interactionMetadata.triggeringInteractionMetadata Metadata for the interaction that was used to open the modal, of type `MessageComponentInteractionMetadata` or `ApplicationCommandInteractionMetadata`; - * @prop {string} interactionMetadata.triggeringInteractionMetadata.id The ID of the interaction that the message is replying to + * @prop {String} interactionMetadata.triggeringInteractionMetadata.id The ID of the interaction that the message is replying to * @prop {string?} interactionMetadata.triggeringInteractionMetadata.interactedMessageID ID of the message that contained the interactive component * @prop {Object} interactionMetadata.triggeringInteractionMetadata.user The user who originally used the interaction - * @prop {number} interactionMetadata.triggeringInteractionMetadata.type The type of the interaction + * @prop {Number} interactionMetadata.triggeringInteractionMetadata.type The type of the interaction * @prop {Object?} interactionMetadata.triggeringInteractionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. * @prop {Object?} interactionMetadata.triggeringInteractionMetadata.targetUser The user the command was run on, present only on user command interaction * @prop {String} jumpLink The url used by Discord clients to jump to this message From 498393dd069b8f13af241f4dffc8e8547c3d6492 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:32:51 +0630 Subject: [PATCH 46/49] fix(docs): readd user to interactionMetadata --- lib/structures/Message.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 92d757bc0..d3f6a35f7 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -100,6 +100,7 @@ function parseMetadataModelSubmit(client, data) { * @prop {Object?} interactionMetadata.targetMessageID The ID of the message the command was run on, present only on message command interactions. * @prop {Object?} interactionMetadata.targetUser The user the command was run on, present only on user command interaction * @prop {Object?} interactionMetadata.triggeringInteractionMetadata Metadata for the interaction that was used to open the modal, of type `MessageComponentInteractionMetadata` or `ApplicationCommandInteractionMetadata`; + * @prop {Object} interactionMetadata.user The user who originally used the interaction * @prop {String} interactionMetadata.triggeringInteractionMetadata.id The ID of the interaction that the message is replying to * @prop {string?} interactionMetadata.triggeringInteractionMetadata.interactedMessageID ID of the message that contained the interactive component * @prop {Object} interactionMetadata.triggeringInteractionMetadata.user The user who originally used the interaction From 239bf73fcdea099b4288c254c99e8f2f2520bd06 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:47:24 +0630 Subject: [PATCH 47/49] fix(interactionMetadata): parse model submit correctly --- lib/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index d3f6a35f7..655fb6c2f 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -56,7 +56,7 @@ function parseMetadataModelSubmit(client, data) { baseData.triggeringInteractionMetadata = parseMetadataApplicationCommand(client, data.triggering_interaction_metadata); break; default: // type message component - baseData.triggeringInteractionMetadata = parseMetadataApplicationCommand(client, data.triggering_interaction_metadata); + baseData.triggeringInteractionMetadata = parseMetadataModelSubmit(client, data.triggering_interaction_metadata); break; } From a7c1777a07a4da4849116b6e17c08a81d4fe7300 Mon Sep 17 00:00:00 2001 From: retrouser955 <70205403+retrouser955@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:03:13 +0630 Subject: [PATCH 48/49] fix(interactionMetadata): Parse modelsubmit correct --- lib/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 655fb6c2f..f806ee8b7 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -56,7 +56,7 @@ function parseMetadataModelSubmit(client, data) { baseData.triggeringInteractionMetadata = parseMetadataApplicationCommand(client, data.triggering_interaction_metadata); break; default: // type message component - baseData.triggeringInteractionMetadata = parseMetadataModelSubmit(client, data.triggering_interaction_metadata); + baseData.triggeringInteractionMetadata = parseMetadataMessageComponent(client, data.triggering_interaction_metadata); break; } From 092107e0da693367f9e9ca643ab525044ae644ef Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 27 Sep 2025 23:00:36 +0100 Subject: [PATCH 49/49] copilot fixes --- lib/structures/Message.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/structures/Message.js b/lib/structures/Message.js index f806ee8b7..9a2dc7ef0 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -13,8 +13,8 @@ function parseInteractionMetadata(client, data) { case InteractionTypes.MESSAGE_COMPONENT: { return parseMetadataMessageComponent(client, data); } - default: { // model submit - return parseMetadataModelSubmit(client, data); + default: { // modal submit + return parseMetadataModalSubmit(client, data); } } } @@ -48,7 +48,7 @@ function parseMetadataMessageComponent(client, data) { }; } -function parseMetadataModelSubmit(client, data) { +function parseMetadataModalSubmit(client, data) { const baseData = parseBaseMetadata(client, data); switch (data.triggering_interaction_metadata.type) { @@ -71,7 +71,7 @@ function parseMetadataModelSubmit(client, data) { * @prop {Array} attachments Array of attachments * @prop {User} author The message author * @prop {Object} call The call associated with the message - * @prop {Number?} call.endedTimestamp The time when the call end + * @prop {Number?} call.endedTimestamp The time when the call ended * @prop {Array} call.participants An array of user IDs that participated in the call * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the id if the channel is not cached. * @prop {Array} channelMentions Array of mentions channels' ids