mirror of
https://github.com/sern-handler/handler
synced 2026-06-13 03:12:15 +00:00
refactor: Cleaning up
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user