From d63423cfc458cb9ab07b9900a7c4d2f7ea8d71b9 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 25 May 2022 15:29:28 -0500 Subject: [PATCH] feat: finishing autocomplete!! --- src/handler/events/interactionCreate.ts | 2 +- src/handler/events/readyEvent.ts | 24 +++++++++++++++++++---- src/handler/structures/module.ts | 4 ++-- src/handler/structures/structxports.ts | 26 +++++++++++++++++++++++-- src/handler/utilities/optionsBuilder.ts | 8 -------- src/types/handler.ts | 26 +++++++++++++++---------- 6 files changed, 63 insertions(+), 27 deletions(-) delete mode 100644 src/handler/utilities/optionsBuilder.ts diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index a5a07e7..e4cf8ac 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -201,7 +201,7 @@ export function onInteractionCreate(wrapper: Wrapper) { return modalHandler(modul, interaction); } if (interaction.isAutocomplete()) { - const modul = Files.ApplicationCommands[1].get(interaction.commandName); + const modul = Files.ApplicationCommands['1'].get(interaction.commandName); return autoCmpHandler(modul, interaction); } return of(); diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index cfc1882..d1eeb29 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -1,4 +1,15 @@ -import { concat, concatMap, from, fromEvent, map, Observable, of, skip, take, throwError } from 'rxjs'; +import { + concat, + concatMap, + from, + fromEvent, + map, + Observable, + of, + skip, + take, + throwError, +} from 'rxjs'; import { basename } from 'path'; import * as Files from '../utilities/readFile'; import type Wrapper from '../structures/wrapper'; @@ -27,8 +38,12 @@ export const onReady = (wrapper: Wrapper) => { ); const processPlugins$ = processCommandFiles$.pipe( concatMap(mod => { - if(mod.type === CommandType.Autocomplete) { - return throwError(() => SernError.NonValidModuleType + `. You cannot use command plugins and Autocomplete.`); + if (mod.type === CommandType.Autocomplete) { + return throwError( + () => + SernError.NonValidModuleType + + `. You cannot use command plugins and Autocomplete.`, + ); } const cmdPluginsRes = mod.plugins?.map(plug => { @@ -89,6 +104,7 @@ function registerModule(mod: DefinitelyDefined): Resul return Ok.EMPTY; }) .with({ type: CommandType.Slash }, mod => { + console.log(mod); Files.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod); return Ok.EMPTY; }) @@ -113,7 +129,7 @@ function registerModule(mod: DefinitelyDefined): Resul Files.MessageCompCommands[ComponentType.SelectMenu].set(name, mod); return Ok.EMPTY; }) - .with({ type : CommandType.Modal }, mod => { + .with({ type: CommandType.Modal }, mod => { Files.ModalSubmitCommands.set(name, mod); return Ok.EMPTY; }) diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index 2c7d707..20ded25 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -1,5 +1,5 @@ import type { - ApplicationCommandAutocompleteOption, + ApplicationCommandAttachmentOption, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, ApplicationCommandNonOptionsData, @@ -173,8 +173,8 @@ export type BaseOptions = | ApplicationCommandChoicesData | ApplicationCommandNonOptionsData | ApplicationCommandChannelOptionData - | ApplicationCommandAutocompleteOption | ApplicationCommandNumericOptionData + | ApplicationCommandAttachmentOption | SernAutocompleteData; export type SernSubCommandData = Override< diff --git a/src/handler/structures/structxports.ts b/src/handler/structures/structxports.ts index 9e544ec..5396cad 100644 --- a/src/handler/structures/structxports.ts +++ b/src/handler/structures/structxports.ts @@ -1,6 +1,28 @@ import Context from './context'; -import type { BothCommand, Module, SlashCommand, TextCommand, OptionsData } from './module'; +import type { + BothCommand, + Module, + SlashCommand, + TextCommand, + SernOptionsData, + BaseOptions, + SernAutocompleteData, + SernSubCommandData, + SernSubCommandGroupData, +} from './module'; import type Wrapper from './wrapper'; export * from './enums'; -export { Context, SlashCommand, TextCommand, BothCommand, Module, Wrapper, OptionsData }; +export { + Context, + SlashCommand, + TextCommand, + BothCommand, + Module, + Wrapper, + SernOptionsData, + BaseOptions, + SernAutocompleteData, + SernSubCommandData, + SernSubCommandGroupData, +}; diff --git a/src/handler/utilities/optionsBuilder.ts b/src/handler/utilities/optionsBuilder.ts deleted file mode 100644 index a99453a..0000000 --- a/src/handler/utilities/optionsBuilder.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { SernOptionsData } from '../structures/module'; -import type { ApplicationCommandOptionData } from 'discord.js'; - -class OptionsBuilder { - public constructor(private options: ApplicationCommandOptionData[] = []) { - this.options = options; - } -} diff --git a/src/types/handler.ts b/src/types/handler.ts index e9e393b..dd6eb50 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -1,13 +1,6 @@ -import type { - Awaitable, - ClientEvents, - CommandInteractionOptionResolver, - MessageOptions, - MessagePayload, -} from 'discord.js'; +import type { Awaitable, ClientEvents, CommandInteractionOptionResolver } from 'discord.js'; import type { EventEmitter } from 'events'; // Anything that can be sent in a `#send` or `#reply` -export type possibleOutput = T | (MessagePayload & MessageOptions); export type Nullish = T | undefined | null; // Thanks @cursorsdottsx export type ParseType = { @@ -16,8 +9,14 @@ export type ParseType = { export type Args = ParseType<{ text: string[]; slash: SlashOptions }>; -export type DiscordEvent = ParseType<{ [K in keyof ClientEvents]: (...args: ClientEvents[K]) => Awaitable }>; -export type EventEmitterRegister = [emitter: EventEmitter, k: string, cb: (...args: unknown[]) => Awaitable]; +export type DiscordEvent = ParseType<{ + [K in keyof ClientEvents]: (...args: ClientEvents[K]) => Awaitable; +}>; +export type EventEmitterRegister = [ + emitter: EventEmitter, + k: string, + cb: (...args: unknown[]) => Awaitable, +]; export type SlashOptions = Omit; @@ -25,3 +24,10 @@ export type SlashOptions = Omit = Omit & T2; export type DefinitelyDefined = T & Override; +export type Expand = T extends object ? { [K in keyof T]: Expand } : T; + +type Reconstruct = T extends Omit ? O & Reconstruct : T; + +type IsOptional = { + [K in keyof T]-?: T[K] extends Required[K] ? false : true; +};