Skip to content

Commit

Permalink
feat: add remaining options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyameliaaaa committed Mar 23, 2023
1 parent b889421 commit 7d7d132
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/mixins/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ import {
} from '@discordjs/builders';
import { getAllStrings, getDefaultString, joinKeys } from 'lib';
import { AutocompletableMixin, BaseKeyMixin, BuilderMixin, NameAndDescriptionMixin, OptionMixin } from 'mixins';
import { IntegerOption, MentionableOption, NumberOption, RoleOption, StringOption, UserOption } from 'options';
import {
IntegerOption,
MentionableOption,
NumberOption,
RoleOption,
StringOption,
UserOption,
AttachmentOption,
BooleanOption,
ChannelOption
} from 'options';
import { hasMixin, mix } from 'ts-mixer';
import { OptionInput, OptionResolvable } from 'types';

Expand Down Expand Up @@ -128,20 +138,38 @@ export class SharedOptionsMixin<T extends SlashCommandBuilder | SlashCommandSubc
return this;
}

// addAttachmentOption(key: string, input: (option: AttachmentOption) => AttachmentOption = option => option) {
// this.addOption(input(new AttachmentOption(key)));
// return this;
// }
addAttachmentOption(key: string, input?: OptionInput<AttachmentOption>): this;
addAttachmentOption(option: OptionInput<AttachmentOption>): this;
addAttachmentOption(option: AttachmentOption): this;
addAttachmentOption(
keyOrOption: string | OptionInput<AttachmentOption> | AttachmentOption,
input: OptionInput<AttachmentOption> = option => option
) {
this.handleCall(keyOrOption, input, AttachmentOption);
return this;
}

// addBooleanOption(key: string, input: (option: BooleanOption) => BooleanOption = option => option) {
// this.addOption(input(new BooleanOption(key)));
// return this;
// }
addBooleanOption(key: string, input?: OptionInput<BooleanOption>): this;
addBooleanOption(option: OptionInput<BooleanOption>): this;
addBooleanOption(option: BooleanOption): this;
addBooleanOption(
keyOrOption: string | OptionInput<BooleanOption> | BooleanOption,
input: OptionInput<BooleanOption> = option => option
) {
this.handleCall(keyOrOption, input, BooleanOption);
return this;
}

// addChannelOption(key: string, input: (option: ChannelOption) => ChannelOption = option => option) {
// this.addOption(input(new ChannelOption(key)));
// return this;
// }
addChannelOption(key: string, input?: OptionInput<ChannelOption>): this;
addChannelOption(option: OptionInput<ChannelOption>): this;
addChannelOption(option: ChannelOption): this;
addChannelOption(
keyOrOption: string | OptionInput<ChannelOption> | ChannelOption,
input: OptionInput<ChannelOption> = option => option
) {
this.handleCall(keyOrOption, input, ChannelOption);
return this;
}

addIntegerOption(key: string, input?: OptionInput<IntegerOption>): this;
addIntegerOption(option: OptionInput<IntegerOption>): this;
Expand Down
1 change: 1 addition & 0 deletions src/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './autocompletables';
export * from './mentionables';
export * from './misc';
43 changes: 43 additions & 0 deletions src/options/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
ApplicationCommandOptionAllowedChannelTypes,
normalizeArray,
RestOrArray,
SlashCommandAttachmentOption,
SlashCommandBooleanOption,
SlashCommandChannelOption
} from '@discordjs/builders';
import { BaseKeyMixin } from 'mixins/base';
import { OptionMixin } from 'mixins/options';
import { mix } from 'ts-mixer';

export interface AttachmentOption extends OptionMixin<SlashCommandAttachmentOption>, BaseKeyMixin {}
@mix(OptionMixin, BaseKeyMixin)
export class AttachmentOption {
constructor(baseKey?: string) {
this.builder = new SlashCommandAttachmentOption();
}
}

export interface BooleanOption extends OptionMixin<SlashCommandBooleanOption>, BaseKeyMixin {}
@mix(OptionMixin, BaseKeyMixin)
export class BooleanOption {
constructor(baseKey?: string) {
this.builder = new SlashCommandBooleanOption();
}
}

export interface ChannelOption extends OptionMixin<SlashCommandChannelOption>, BaseKeyMixin {}
@mix(OptionMixin, BaseKeyMixin)
export class ChannelOption {
constructor(baseKey?: string) {
this.builder = new SlashCommandChannelOption();
}

addChannelTypes(...channelTypes: RestOrArray<ApplicationCommandOptionAllowedChannelTypes>) {
this.builder.addChannelTypes(...normalizeArray(channelTypes));
}

get channelTypes() {
return this.builder.channel_types;
}
}

0 comments on commit 7d7d132

Please sign in to comment.