diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index 1ce5bad..ff1c99c 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -1,5 +1,5 @@ import type { Message } from 'discord.js'; -import { fromEvent, Observable, of, concatMap, map, from, every, concatAll, tap } from 'rxjs'; +import { fromEvent, Observable, of, concatMap, map, from, filter, concatAll, tap } from 'rxjs'; import { Err, Ok } from 'ts-results'; import type { Args } from '../..'; import { CommandType } from '../sern'; @@ -7,7 +7,7 @@ import Context from '../structures/context'; import type Wrapper from '../structures/wrapper'; import { fmt } from '../utilities/messageHelpers'; import * as Files from '../utilities/readFile'; -import { filterCorrectModule, ignoreNonBot } from './observableHandling'; +import { filterCorrectModule, ignoreNonBot, match } from './observableHandling'; import { isEventPlugin } from './readyEvent'; export const onMessageCreate = (wrapper : Wrapper) => { @@ -23,10 +23,11 @@ export const onMessageCreate = (wrapper : Wrapper) => { return { ctx : Context.wrap(message), args : ['text', rest], - mod : Files.ApplicationCommandStore[1].get(prefix) ?? Files.Alias.get(prefix) + mod : Files.ApplicationCommandStore[1].get(prefix) + ?? Files.BothCommand.get(prefix) + ?? Files.TextCommandStore.aliases.get(prefix) } })); - const ensureModuleType$ = processMessage$.pipe( concatMap(payload => of(payload.mod) .pipe( diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index 9204fd3..dae0bc7 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -10,7 +10,7 @@ import type { EventPlugin, SernPlugin } from '../plugins/plugin'; export function match( plug: PluggedModule | undefined, type : T ) : plug is { mod: ModuleDefs[T], plugins : SernPlugin[] } { - return plug !== undefined && (plug.mod.type & type) != 0; + return plug !== undefined && plug.mod.type === type; } export function filterCorrectModule(cmdType : T) { diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index c987d2a..7511588 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -75,15 +75,15 @@ export const onReady = ( wrapper : Wrapper ) => { function handler( name : string ) : ModuleHandlers { return { [CommandType.Text] : (mod, plugins) => { - mod.alias.forEach ( a => Files.Alias.set(a,{ mod, plugins})); + mod.alias.forEach ( a => Files.TextCommandStore.aliases.set(a,{ mod, plugins})); Files.ApplicationCommandStore[1].set( name, { mod, plugins } ); }, [CommandType.Slash]: (mod, plugins) => { Files.ApplicationCommandStore[1].set( name , { mod, plugins }); }, [CommandType.Both] :( mod, plugins )=> { - Files.ApplicationCommandStore[1].set ( name,{ mod, plugins}); - mod.alias.forEach (a => Files.Alias.set(a, {mod,plugins})); + Files.BothCommand.set ( name,{ mod, plugins}); + mod.alias.forEach (a => Files.TextCommandStore.aliases.set(a, {mod,plugins})); }, [CommandType.MenuUser] : (mod, plugins) => { Files.ApplicationCommandStore[2].set ( name, {mod, plugins} ); diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index 305571a..1ba884e 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -6,7 +6,7 @@ import { CommandType } from '../sern'; import type { PluggedModule } from '../structures/modules/module'; -// A little ambigious, but ChatInput map stores text commands also. +export const BothCommand = new Map(); export const ApplicationCommandStore = { [ApplicationCommandType.User] : new Map(), [ApplicationCommandType.Message] : new Map(), @@ -18,9 +18,9 @@ export const MessageCompCommandStore = { [ComponentType.SelectMenu] : new Map() } export const TextCommandStore = { - [CommandType.Text] : new Map() // Aliases + text : new Map(), + aliases : new Map() } -export const Alias = new Map(); // Courtesy @Townsy45 function readPath(dir: string, arrayOfFiles: string[] = []): string[] {