mirror of
https://github.com/sern-handler/handler
synced 2026-06-13 11:22:15 +00:00
refactor: Adding some type aliases
This commit is contained in:
@@ -21,7 +21,7 @@ import { ApplicationCommandType, ComponentType } from 'discord.js';
|
||||
import type { CommandModule, Module } from '../structures/module';
|
||||
import { match } from 'ts-pattern';
|
||||
import { SernError } from '../structures/errors';
|
||||
import type { DefinitelyDefined } from '../../types/handler';
|
||||
import type { DefinedCommandModule, DefinedModule } from '../../types/handler';
|
||||
import { CommandType, PluginType } from '../structures/enums';
|
||||
import { errTap } from './observableHandling';
|
||||
|
||||
@@ -39,7 +39,7 @@ export function onReady(wrapper: Wrapper) {
|
||||
});
|
||||
}),
|
||||
map(({ mod, absPath }) => {
|
||||
return <DefinitelyDefined<CommandModule, 'name' | 'description'>>{
|
||||
return <DefinedCommandModule>{
|
||||
name: mod?.name ?? Files.fmtFileName(basename(absPath)),
|
||||
description: mod?.description ?? '...',
|
||||
...mod,
|
||||
@@ -70,7 +70,7 @@ export function onReady(wrapper: Wrapper) {
|
||||
|
||||
(
|
||||
concat(ready$, processPlugins$) as Observable<{
|
||||
mod: DefinitelyDefined<CommandModule, 'name' | 'description'>;
|
||||
mod: DefinedCommandModule;
|
||||
cmdPluginsRes: {
|
||||
execute: Awaitable<Result<void, void>>;
|
||||
type: PluginType.Command;
|
||||
@@ -106,9 +106,7 @@ export function onReady(wrapper: Wrapper) {
|
||||
});
|
||||
}
|
||||
|
||||
function registerModule(
|
||||
mod: DefinitelyDefined<Module, 'name' | 'description'>,
|
||||
): Result<void, void> {
|
||||
function registerModule(mod: DefinedModule): Result<void, void> {
|
||||
const name = mod.name;
|
||||
return match<Module>(mod)
|
||||
.with({ type: CommandType.Text }, mod => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { CommandType } from '../structures/enums';
|
||||
import { from, fromEvent, map, throwError } from 'rxjs';
|
||||
import { concatMap, from, fromEvent, map, of, throwError } from 'rxjs';
|
||||
import { SernError } from '../structures/errors';
|
||||
import { buildData, ExternalEventEmitters } from '../utilities/readFile';
|
||||
import { controller } from '../sern';
|
||||
import type { DefinitelyDefined } from '../../types/handler';
|
||||
import type { DefinedModule, DefinitelyDefined } from '../../types/handler';
|
||||
import type { Module } from '../structures/module';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import type { EventModule } from '../structures/module';
|
||||
@@ -14,7 +14,7 @@ import { isDiscordEvent, isExternalEvent, isSernEvent } from '../utilities/predi
|
||||
import type { SpreadParams } from '../../types/handler';
|
||||
import { errTap } from './observableHandling';
|
||||
|
||||
export function processCommandPlugins$<T extends DefinitelyDefined<Module, 'name' | 'description'>>(
|
||||
export function processCommandPlugins$<T extends DefinedModule>(
|
||||
{ client, sernEmitter }: Wrapper,
|
||||
{ mod, absPath }: { mod: T; absPath: string },
|
||||
) {
|
||||
@@ -58,8 +58,8 @@ export function processEvents(
|
||||
);
|
||||
const processPlugins$ = normalize$.pipe(map(mod => mod)); //for now, until i figure out what to do with how plugins are registered
|
||||
|
||||
const processAndLoadEvents$ = normalize$.pipe(
|
||||
map(mod => {
|
||||
const processAndLoadEvents$ = processPlugins$.pipe(
|
||||
concatMap(mod => {
|
||||
return match(mod as EventModule)
|
||||
.when(isSernEvent, m => {
|
||||
if (wrapper.sernEmitter === undefined) {
|
||||
@@ -71,13 +71,13 @@ export function processEvents(
|
||||
m.execute as SpreadParams<typeof m.execute>,
|
||||
);
|
||||
})
|
||||
.when(isDiscordEvent, m =>
|
||||
fromEvent(
|
||||
.when(isDiscordEvent, m => {
|
||||
return fromEvent(
|
||||
wrapper.client,
|
||||
mod.name!,
|
||||
m.name!,
|
||||
m.execute as SpreadParams<typeof m.execute>,
|
||||
),
|
||||
)
|
||||
);
|
||||
})
|
||||
.when(isExternalEvent, m => {
|
||||
if (!ExternalEventEmitters.has(m.emitter)) {
|
||||
throw Error(
|
||||
|
||||
@@ -9,7 +9,6 @@ import type {
|
||||
import type { CommandType } from './enums';
|
||||
import type { SernEventsMapping } from '../sernEmitter';
|
||||
import type { Awaitable, ClientEvents } from 'discord.js';
|
||||
import type { EventEmitter } from 'events';
|
||||
|
||||
export type SernEventCommand<T extends keyof SernEventsMapping = keyof SernEventsMapping> =
|
||||
Override<
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Client } from 'discord.js';
|
||||
import type { DiscordEvent, EventEmitterRegister, SernEvent } from '../../types/handler';
|
||||
import type SernEmitter from '../sernEmitter';
|
||||
import type { EventModule } from './module';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { CommandInteractionOptionResolver } from 'discord.js';
|
||||
import type { CommandModule, Module } from '../handler/structures/module';
|
||||
export type Nullish<T> = T | undefined | null;
|
||||
|
||||
// Thanks to @kelsny
|
||||
@@ -32,3 +33,10 @@ type IsOptional<T> = {
|
||||
export type SpreadParams<T extends (...args: any) => unknown> = (
|
||||
args: Parameters<T>[number],
|
||||
) => unknown;
|
||||
|
||||
/**
|
||||
* After modules are transformed, name and description are given default values if none
|
||||
* are provided to Module. This type represents that transformation
|
||||
*/
|
||||
export type DefinedModule = DefinitelyDefined<Module, 'name' | 'description'>;
|
||||
export type DefinedCommandModule = DefinitelyDefined<CommandModule, 'name' | 'description'>;
|
||||
|
||||
Reference in New Issue
Block a user