refactor: cleaning up code, removing unuseds

This commit is contained in:
Jacob Nguyen
2022-05-27 15:06:24 -05:00
parent 0ae541daba
commit e69dae92cd
4 changed files with 27 additions and 6 deletions

View File

@@ -206,7 +206,7 @@ export function onInteractionCreate(wrapper: Wrapper) {
Files.BothCommands.get(interaction.commandName);
return autoCmpHandler(modul, interaction);
}
return of();
return throwError(() => SernError.NotSupportedInteraction);
}),
)
.subscribe({

View File

@@ -1,8 +1,9 @@
import type { Message } from 'discord.js';
import { Observable, throwError } from 'rxjs';
import { SernError } from '../structures/errors';
import type { Module, ModuleDefs } from '../structures/module';
import type { InteractionDefs, Module, ModuleDefs } from '../structures/module';
import { correctModuleType } from '../utilities/predicates';
import type { CommandType } from '../structures/enums';
export function filterCorrectModule<T extends keyof ModuleDefs>(cmdType: T) {
return (src: Observable<Module | undefined>) =>
@@ -43,3 +44,14 @@ export function ignoreNonBot(prefix: string) {
});
});
}
export function processOnEvents<T extends CommandType>(interaction: InteractionDefs[T]) {
return (src: Observable<ModuleDefs[CommandType]>) =>
new Observable<Message>(subscriber => {
return src.subscribe({
next(m) {},
error: e => subscriber.error(e),
complete: () => subscriber.complete(),
});
});
}

View File

@@ -1,11 +1,7 @@
export enum SernError {
ReservedEvent = 'Cannot register the reserved ready event. Please use the init property.',
NoAlias = 'You cannot provide an array with elements to a slash command.',
NonValidModuleType = 'Detected an unknown module type',
UndefinedModule = `A module could not be detected at`,
MismatchModule = `A module type mismatched with event emitted!`,
NotImplemented = 'This feature has not yet been implemented',
NotSupportedInteraction = `This interaction is not supported.`,
NotValidEventName = `Supplied a non valid event name`,
PluginFailure = `A plugin failed to call controller.next()`,
}

View File

@@ -21,6 +21,7 @@ import type Context from './context';
import { CommandType, PluginType } from './enums';
import type { AutocompleteInteraction } from 'discord.js';
import type { ApplicationCommandOptionType } from 'discord.js';
import { ChatInputCommandInteraction, Message } from 'discord.js';
export interface BaseModule {
type: CommandType | PluginType;
@@ -150,6 +151,18 @@ export type ModuleDefs = {
[CommandType.Autocomplete]: AutocompleteCommand;
};
export type InteractionDefs = {
[CommandType.Text]: Context;
[CommandType.Slash]: Context;
[CommandType.Both]: Context;
[CommandType.MenuMsg]: MessageContextMenuCommandInteraction;
[CommandType.MenuUser]: UserContextMenuCommandInteraction;
[CommandType.Button]: ButtonInteraction;
[CommandType.MenuSelect]: SelectMenuInteraction;
[CommandType.Modal]: ModalSubmitInteraction;
[CommandType.Autocomplete]: AutocompleteInteraction;
};
//TODO: support deeply nested Autocomplete
// objective: construct union of ApplicationCommandOptionData change any Autocomplete data
// into Sern autocomplete data.