From 1725f759ba64e7a7ce7ae69d7a7db5f2a81741a8 Mon Sep 17 00:00:00 2001 From: Amitoj Singh Date: Sat, 18 Dec 2021 02:40:32 +0300 Subject: [PATCH 1/3] feat(SlashCommands): add attachment option --- __tests__/SlashCommands.test.ts | 4 ++++ src/index.ts | 1 + .../slashCommands/mixins/CommandOptions.ts | 10 ++++++++++ src/interactions/slashCommands/options/attachment.ts | 10 ++++++++++ 4 files changed, 25 insertions(+) create mode 100644 src/interactions/slashCommands/options/attachment.ts diff --git a/__tests__/SlashCommands.test.ts b/__tests__/SlashCommands.test.ts index 6d23b761..d3bee4fd 100644 --- a/__tests__/SlashCommands.test.ts +++ b/__tests__/SlashCommands.test.ts @@ -8,6 +8,7 @@ import { SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, + SlashCommandAttachmentOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, @@ -25,6 +26,7 @@ const getBooleanOption = () => new SlashCommandBooleanOption().setName('owo').se const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123'); const getChannelOption = () => new SlashCommandChannelOption().setName('owo').setDescription('Testing 123'); const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123'); +const getAttachmentOption = () => new SlashCommandAttachmentOption().setName('owo').setDescription('Testing 123'); const getMentionableOption = () => new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123'); const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setName('owo').setDescription('Testing 123'); const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123'); @@ -254,6 +256,8 @@ describe('Slash Commands', () => { expect(() => getBuilder().addRoleOption(getRoleOption())).not.toThrowError(); + expect(() => getBuilder().addRoleOption(getAttachmentOption())).not.toThrowError(); + expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError(); }); diff --git a/src/index.ts b/src/index.ts index fa51ade9..e0b9e8f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export * from './interactions/slashCommands/options/integer'; export * from './interactions/slashCommands/options/mentionable'; export * from './interactions/slashCommands/options/number'; export * from './interactions/slashCommands/options/role'; +export * from './interactions/slashCommands/options/attachment'; export * from './interactions/slashCommands/options/string'; export * from './interactions/slashCommands/options/user'; diff --git a/src/interactions/slashCommands/mixins/CommandOptions.ts b/src/interactions/slashCommands/mixins/CommandOptions.ts index 5b2c5d46..f2ef599b 100644 --- a/src/interactions/slashCommands/mixins/CommandOptions.ts +++ b/src/interactions/slashCommands/mixins/CommandOptions.ts @@ -6,6 +6,7 @@ import { SlashCommandIntegerOption } from '../options/integer'; import { SlashCommandMentionableOption } from '../options/mentionable'; import { SlashCommandNumberOption } from '../options/number'; import { SlashCommandRoleOption } from '../options/role'; +import { SlashCommandAttachmentOption } from '../options/attachment'; import { SlashCommandStringOption } from '../options/string'; import { SlashCommandUserOption } from '../options/user'; import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder'; @@ -53,6 +54,15 @@ export class SharedSlashCommandOptions { return this._sharedAddOptionMethod(input, SlashCommandRoleOption); } + /** + * Adds an attachment option + * + * @param input A function that returns an option builder, or an already built builder + */ + public addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)) { + return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption); + } + /** * Adds a mentionable option * diff --git a/src/interactions/slashCommands/options/attachment.ts b/src/interactions/slashCommands/options/attachment.ts new file mode 100644 index 00000000..cfad1a65 --- /dev/null +++ b/src/interactions/slashCommands/options/attachment.ts @@ -0,0 +1,10 @@ +import { ApplicationCommandOptionType } from 'discord-api-types/v9'; +import { SlashCommandOptionBase } from '../mixins/CommandOptionBase'; + +export class SlashCommandAttachmentOption extends SlashCommandOptionBase { + public override readonly type = ApplicationCommandOptionType.Attachment as const; + + public constructor() { + super(ApplicationCommandOptionType.Attachment); + } +} From ebfb69d02c1c3bcf8d1d5e2037c65e92a5e6bf28 Mon Sep 17 00:00:00 2001 From: Amitoj Singh Date: Sat, 18 Dec 2021 02:58:43 +0300 Subject: [PATCH 2/3] refactor(SlashCommandTest): addRoleOption -> addAttachmentOption --- __tests__/SlashCommands.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/SlashCommands.test.ts b/__tests__/SlashCommands.test.ts index d3bee4fd..f707f484 100644 --- a/__tests__/SlashCommands.test.ts +++ b/__tests__/SlashCommands.test.ts @@ -256,7 +256,7 @@ describe('Slash Commands', () => { expect(() => getBuilder().addRoleOption(getRoleOption())).not.toThrowError(); - expect(() => getBuilder().addRoleOption(getAttachmentOption())).not.toThrowError(); + expect(() => getBuilder().addAttachmentOption(getAttachmentOption())).not.toThrowError(); expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError(); }); From 3dff9ef184108b12a5e7ac2199ac79b29782d483 Mon Sep 17 00:00:00 2001 From: Amitoj Singh Date: Sun, 19 Dec 2021 10:49:49 +0300 Subject: [PATCH 3/3] refactor(SlashCommands): fix linting errors --- src/interactions/slashCommands/mixins/CommandOptions.ts | 4 +++- src/interactions/slashCommands/options/attachment.ts | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/interactions/slashCommands/mixins/CommandOptions.ts b/src/interactions/slashCommands/mixins/CommandOptions.ts index f2ef599b..dd792b04 100644 --- a/src/interactions/slashCommands/mixins/CommandOptions.ts +++ b/src/interactions/slashCommands/mixins/CommandOptions.ts @@ -59,7 +59,9 @@ export class SharedSlashCommandOptions { * * @param input A function that returns an option builder, or an already built builder */ - public addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)) { + public addAttachmentOption( + input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption), + ) { return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption); } diff --git a/src/interactions/slashCommands/options/attachment.ts b/src/interactions/slashCommands/options/attachment.ts index cfad1a65..9f28abb1 100644 --- a/src/interactions/slashCommands/options/attachment.ts +++ b/src/interactions/slashCommands/options/attachment.ts @@ -2,9 +2,9 @@ import { ApplicationCommandOptionType } from 'discord-api-types/v9'; import { SlashCommandOptionBase } from '../mixins/CommandOptionBase'; export class SlashCommandAttachmentOption extends SlashCommandOptionBase { - public override readonly type = ApplicationCommandOptionType.Attachment as const; + public override readonly type = ApplicationCommandOptionType.Attachment as const; - public constructor() { - super(ApplicationCommandOptionType.Attachment); - } + public constructor() { + super(ApplicationCommandOptionType.Attachment); + } }