Skip to content

Commit

Permalink
fix tests and undo breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Nov 14, 2024
1 parent a91e5cb commit f6e7a7e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 35 deletions.
46 changes: 23 additions & 23 deletions src/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Interaction {
#_channel_id;
#token;
#member;
#options;
/**
* Creates the structure for an interaction.
* @param {Client} client The client instance.
Expand Down Expand Up @@ -83,13 +82,6 @@ class Interaction {
* @private
*/
this.#token = data.token;

/**
* The options provided with the interaction.
* @type {Array<Object>}
* @private
*/
this.#options = data.data.options;
}

/**
Expand Down Expand Up @@ -172,16 +164,6 @@ class Interaction {
return this.#member;
}

/**
* The options provided with the interaction.
* @type {Array<Object>}
* @readonly
* @public
*/
get options() {
return this.#options;
}

/**
* Prompts a user to enter text using a modal.
* @param {Object} options Modal options.
Expand Down Expand Up @@ -316,6 +298,28 @@ class Interaction {
return this;
}

/**
* Edits a response to an interaction. Works up to 15 minutes after the response was sent.
* @param {Object?} options The new interaction response options.
* @param {String?} options.content The new content of the interaction response.
* @param {Array<FileUpload>?} options.files The new files to send with the interaction response.
* @param {Array<Embed>?} options.embeds The new embeds to send with the interaction response.
* @param {Array<ActionRow>?} options.components The new components to send with the interaction response.
* @returns {Promise<Interaction>}
* @public
* @async
* @method
* @throws {Error | TypeError}
*/
async edit({ content, files, embeds, components } = {}) {
return Interaction.edit(this.#_client, this.#token, {
content,
files,
embeds,
components,
});
}

/**
* Edits a response to an interaction. Works up to 15 minutes after the response was sent.
* @param {Client} client The client instance.
Expand All @@ -334,7 +338,7 @@ class Interaction {
static async edit(
client,
interactionToken,
{ content, files, embeds, components },
{ content, files, embeds, components } = {},
) {
if (!(client instanceof Client))
throw new TypeError("GLUON: Client must be an instance of Client");
Expand Down Expand Up @@ -393,10 +397,6 @@ class Interaction {
guild_id: this.guildId,
channel_id: this.channelId,
member: this.member.toJSON(format),
type: this.type,
data: {
options: this.options,
},
};
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/SlashCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import cacheChannel from "../util/gluon/cacheChannel.js";
*/
class SlashCommand extends Interaction {
#data;
#options;
/**
* Creates a slash command interaction structure.
* @param {Client} client The client instance.
Expand Down Expand Up @@ -49,6 +50,13 @@ class SlashCommand extends Interaction {
if (data.data.resolved?.channels)
for (const value of Object.values(data.data.resolved.channels))
cacheChannel(client, value, data.guild_id);

/**
* The options provided with the interaction.
* @type {Array<Object>}
* @private
*/
this.#options = data.data.options;
}

/**
Expand All @@ -61,6 +69,16 @@ class SlashCommand extends Interaction {
return this.#data;
}

/**
* The options provided with the slash command.
* @type {Array<Object>}
* @readonly
* @public
*/
get options() {
return this.#options;
}

/**
* @method
* @public
Expand Down
13 changes: 1 addition & 12 deletions test/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe("Interaction", function () {
expect(interaction).to.have.property("guildId");
expect(interaction).to.have.property("channelId");
expect(interaction).to.have.property("member");
expect(interaction).to.have.property("options");
expect(interaction).to.have.property("guild");
expect(interaction).to.have.property("channel");
expect(interaction).to.have.property("token");
Expand Down Expand Up @@ -114,16 +113,6 @@ describe("Interaction", function () {
});
});

context("check options", function () {
it("should have the correct options", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
TEST_GUILDS.ALL_CACHES_ENABLED(client);
TEST_CHANNELS.TEXT_CHANNEL_ALL_CACHES_ENABLED(client);
const interaction = new Interaction(client, TEST_DATA.INTERACTION);
expect(interaction.options).to.deep.equal([]);
});
});

context("check textPrompt", function () {
it("should be a function", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
Expand Down Expand Up @@ -368,7 +357,7 @@ describe("Interaction", function () {
expect(request).to.be.calledOnce;
expect(request).to.be.calledOnceWith("patchOriginalInteractionResponse", [
TEST_DATA.CLIENT_USER.id,
TEST_DATA.INTERACTION.token,
"vcsfdjhdfkjvhkdf",
]);
expect(request.firstCall.args[2]).to.be.an("object");
});
Expand Down
12 changes: 12 additions & 0 deletions test/structures/SlashCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("SlashCommand", function () {
const slashCommand = new SlashCommand(client, TEST_DATA.SLASH_COMMAND);
expect(slashCommand).to.have.property("id");
expect(slashCommand).to.have.property("data");
expect(slashCommand).to.have.property("options");
expect(slashCommand).to.have.property("toString");
});
});
Expand All @@ -29,6 +30,17 @@ describe("SlashCommand", function () {
});
});

context("check options", function () {
it("should have the correct options", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
TEST_GUILDS.ALL_CACHES_ENABLED(client);
const slashCommand = new SlashCommand(client, TEST_DATA.SLASH_COMMAND);
expect(slashCommand.options).to.equal(
TEST_DATA.SLASH_COMMAND.data.options,
);
});
});

context("check toString", function () {
it("should return the correct string", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
Expand Down

0 comments on commit f6e7a7e

Please sign in to comment.