mirror of
https://github.com/sern-handler/handler
synced 2026-06-27 18:22:14 +00:00
feat : strict commandType checking transition for ergonomics
This commit is contained in:
@@ -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 : <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(
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { EventPlugin, SernPlugin } from '../plugins/plugin';
|
||||
export function match<T extends keyof ModuleDefs>(
|
||||
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<T extends keyof ModuleDefs>(cmdType : T) {
|
||||
|
||||
@@ -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} );
|
||||
|
||||
@@ -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<string, PluggedModule>();
|
||||
export const ApplicationCommandStore = {
|
||||
[ApplicationCommandType.User] : new Map<string, PluggedModule>(),
|
||||
[ApplicationCommandType.Message] : new Map<string, PluggedModule>(),
|
||||
@@ -18,9 +18,9 @@ export const MessageCompCommandStore = {
|
||||
[ComponentType.SelectMenu] : new Map<string, PluggedModule>()
|
||||
}
|
||||
export const TextCommandStore = {
|
||||
[CommandType.Text] : new Map<string, PluggedModule>() // Aliases
|
||||
text : new Map<string, PluggedModule>(),
|
||||
aliases : new Map<string, PluggedModule>()
|
||||
}
|
||||
export const Alias = new Map<string, PluggedModule>();
|
||||
|
||||
// Courtesy @Townsy45
|
||||
function readPath(dir: string, arrayOfFiles: string[] = []): string[] {
|
||||
|
||||
Reference in New Issue
Block a user