refactor: Cleaning up

This commit is contained in:
Jacob Nguyen
2022-05-15 19:26:38 -05:00
parent a76099cbcb
commit 269ab563ab
4 changed files with 11 additions and 38 deletions

View File

@@ -30,7 +30,6 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command
return throwError(() => SernError.UndefinedModule);
}
const eventPlugins = mod.onEvent;
return match(interaction)
.when(isChatInputCommand, i => {
const ctx = Context.wrap(i);

View File

@@ -23,7 +23,6 @@ export const onMessageCreate = (wrapper: Wrapper) => {
ctx: Context.wrap(message), //TODO : check for BothCommand
args: <Args>['text', rest],
mod:
Files.ApplicationCommands[1].get(prefix) ??
Files.BothCommands.get(prefix) ??
Files.TextCommands.aliases.get(prefix),
};

View File

@@ -31,34 +31,9 @@ export function filterCorrectModule<T extends keyof ModuleDefs>(cmdType: T) {
});
}
/** export function filterTap<T extends keyof ModuleDefs>(
cmdType : T,
tap: (mod : ModuleDefs[T], plugins : EventPlugin[]) => Awaitable<void>
) {
return (src : Observable<PluggedModule|undefined>) =>
new Observable<PluggedModule|undefined>( subscriber => {
return src.subscribe({
next(modul) {
if(match(modul, cmdType)) {
const asModT = <ModuleDefs[T]> modul!.mod;
tap(asModT, modul!.plugins as EventPlugin[]);
subscriber.next(modul);
} else {
if (modul === undefined) {
return throwError(() => SernError.UndefinedModule);
}
return throwError(() => SernError.MismatchModule);
}
},
error: (e) => subscriber.error(e),
complete: () => subscriber.complete()
});
});
}
**/
export function ignoreNonBot(prefix: string) {
return (src: Observable<Message>) =>
new Observable<Message>(subscriber => {
new Observable(subscriber => {
return src.subscribe({
next(m) {
const passAll = [

View File

@@ -7,7 +7,7 @@ import type { PluginType } from '../plugins/plugin';
import type { Result } from 'ts-results';
import type { Awaitable } from 'discord.js';
import type { Module } from '../structures/module';
import { match, P } from 'ts-pattern';
import { match } from 'ts-pattern';
import { ApplicationCommandType, ComponentType } from 'discord.js';
export const onReady = (wrapper: Wrapper) => {
@@ -64,30 +64,30 @@ export const onReady = (wrapper: Wrapper) => {
});
};
function registerModule(mod : Module) {
function registerModule(mod: Module) {
const name = mod.name!;
match<Module>(mod)
.with({type : CommandType.Text }, mod => {
.with({ type: CommandType.Text }, mod => {
mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod));
Files.TextCommands.text.set(name, mod);
})
.with({ type : CommandType.Slash }, mod => {
.with({ type: CommandType.Slash }, mod => {
Files.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod);
})
.with( { type : CommandType.Both }, mod => {
.with({ type: CommandType.Both }, mod => {
Files.BothCommands.set(name, mod);
mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod));
})
.with( { type : CommandType.MenuUser }, mod => {
.with({ type: CommandType.MenuUser }, mod => {
Files.ApplicationCommands[ApplicationCommandType.User].set(name, mod);
})
.with( { type : CommandType.MenuMsg }, mod => {
.with({ type: CommandType.MenuMsg }, mod => {
Files.ApplicationCommands[ApplicationCommandType.Message].set(name, mod);
})
.with( { type : CommandType.Button }, mod => {
.with({ type: CommandType.Button }, mod => {
Files.ApplicationCommands[ComponentType.Button].set(name, mod);
})
.with( { type: CommandType.MenuSelect }, mod => {
.with({ type: CommandType.MenuSelect }, mod => {
Files.MessageCompCommands[ComponentType.SelectMenu].set(name, mod);
})
});
}