feat: Add DefinetlyDefined type, more todo statements

This commit is contained in:
Jacob Nguyen
2022-05-17 12:11:00 -05:00
parent b26650818e
commit c8c0c841db
4 changed files with 10 additions and 8 deletions

View File

@@ -18,8 +18,6 @@ import {
} from '../utilities/predicates';
import { filterCorrectModule } from './observableHandling';
//TODO : atm, i have to cast for every interaction. is there a way to not cast?
// maybe pass it through an observable
function applicationCommandHandler(mod: Module | undefined, interaction: CommandInteraction) {
const mod$ = <T extends CommandType>(cmdTy : T) => of(mod).pipe(
filterCorrectModule(cmdTy)
@@ -28,9 +26,9 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command
return match(interaction)
.when(isChatInputCommand, i => {
const ctx = Context.wrap(i);
//SUPPORT COMMANDTYPE.BOTH
return mod$(CommandType.Slash).pipe(
concatMap(m => {
console.log(m);
return of(m.onEvent.map(e => e.execute(
[ctx, ['slash', i.options]],
controller

View File

@@ -31,7 +31,8 @@ export const onMessageCreate = (wrapper: Wrapper) => {
const ensureModuleType$ = processMessage$.pipe(
concatMap(payload =>
of(payload.mod).pipe(
filterCorrectModule(CommandType.Text), // fix for BothCommand
//SUPPORT COMMANDTYPE.BOTH
filterCorrectModule(CommandType.Text),
map(mod => ({ ...payload, mod })),
),
),

View File

@@ -11,6 +11,7 @@ import { match } from 'ts-pattern';
import { ApplicationCommandType, ComponentType } from 'discord.js';
import { Err, Ok } from 'ts-results';
import { SernError } from '../structures/errors';
import type { DefinetlyDefined, Override } from '../../types/handler';
export const onReady = (wrapper: Wrapper) => {
const { client, commands } = wrapper;
@@ -39,7 +40,7 @@ export const onReady = (wrapper: Wrapper) => {
(
concat(ready$, processPlugins$) as Observable<{
mod: Module;
mod: DefinetlyDefined<Module, { name : string }>;
cmdPluginsRes: {
execute: Awaitable<Result<void, void>>;
type: PluginType.Command;
@@ -69,8 +70,8 @@ export const onReady = (wrapper: Wrapper) => {
});
};
function registerModule(mod: Module) : Result<void, void> {
const name = mod.name!;
function registerModule(mod: DefinetlyDefined<Module, { name: string }>) : Result<void, void> {
const name = mod.name;
return match<Module>(mod)
.with({ type: CommandType.Text }, mod => {
mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod));

View File

@@ -29,4 +29,6 @@ export type UnionToTuple<T> = T extends readonly [infer V, infer S]
? [V, S]
: [V]
: never
: never;
: never;
export type DefinetlyDefined<T, K> = T & Override<T, K>