mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: Make name and description defined when making plugins!
This commit is contained in:
@@ -50,6 +50,7 @@ export const onReady = (wrapper: Wrapper) => {
|
||||
return {
|
||||
...plug,
|
||||
name: plug?.name ?? 'Unnamed Plugin',
|
||||
description: plug?.description ?? '...',
|
||||
execute: plug.execute(client, mod, controller),
|
||||
};
|
||||
}) ?? [];
|
||||
@@ -59,7 +60,7 @@ export const onReady = (wrapper: Wrapper) => {
|
||||
|
||||
(
|
||||
concat(ready$, processPlugins$) as Observable<{
|
||||
mod: DefinitelyDefined<Module, { name: string; description: string }>;
|
||||
mod: DefinitelyDefined<Module, 'name' | 'description'>;
|
||||
cmdPluginsRes: {
|
||||
execute: Awaitable<Result<void, void>>;
|
||||
type: PluginType.Command;
|
||||
@@ -99,7 +100,9 @@ export const onReady = (wrapper: Wrapper) => {
|
||||
});
|
||||
};
|
||||
|
||||
function registerModule(mod: DefinitelyDefined<Module, { name: string }>): Result<void, void> {
|
||||
function registerModule(
|
||||
mod: DefinitelyDefined<Module, 'name' | 'description'>,
|
||||
): Result<void, void> {
|
||||
const name = mod.name;
|
||||
return match<Module>(mod)
|
||||
.with({ type: CommandType.Text }, mod => {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
import type { Awaitable, Client } from 'discord.js';
|
||||
import type { Err, Ok, Result } from 'ts-results';
|
||||
import type { Module, Override } from '../..';
|
||||
import type { DefinitelyDefined, Module, Override } from '../..';
|
||||
import { CommandType } from '../..';
|
||||
import type { AutocompleteCommand, BaseModule, ModuleDefs } from '../structures/module';
|
||||
import { PluginType } from '../structures/enums';
|
||||
@@ -37,7 +37,7 @@ export type CommandPlugin<T extends keyof ModuleDefs = keyof ModuleDefs> = {
|
||||
type: PluginType.Command;
|
||||
execute: (
|
||||
wrapper: Client,
|
||||
module: ModuleDefs[T],
|
||||
module: DefinitelyDefined<ModuleDefs[T], 'name' | 'description'>,
|
||||
controller: Controller,
|
||||
) => Awaitable<Result<void, void>>;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ export type EventPlugin<T extends keyof ModuleDefs = keyof ModuleDefs> = {
|
||||
// return plug;
|
||||
// }
|
||||
|
||||
type ModuleNoPlugins = {
|
||||
export type ModuleNoPlugins = {
|
||||
[T in keyof ModuleDefs]: Omit<ModuleDefs[T], 'plugins' | 'onEvent'>;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import type SernEmitter from '../sernEmitter';
|
||||
* An object to be passed into Sern.Handler constructor.
|
||||
* @typedef {object} Wrapper
|
||||
* @property {readonly Client} client
|
||||
* @prop { readonly SernEmitter } sernEmitter
|
||||
* @property {readonly string} defaultPrefix
|
||||
* @property {readonly string} commands
|
||||
* @prop { readonly DiscordEvent[] } events
|
||||
|
||||
@@ -28,7 +28,11 @@ export type SlashOptions = Omit<CommandInteractionOptionResolver, 'getMessage' |
|
||||
// Source: https://dev.to/vborodulin/ts-how-to-override-properties-with-type-intersection-554l
|
||||
export type Override<T1, T2> = Omit<T1, keyof T2> & T2;
|
||||
|
||||
export type DefinitelyDefined<T, K> = T & Override<T, K>;
|
||||
export type DefinitelyDefined<T, K extends keyof T> = {
|
||||
[L in K]-?: T[L] extends Record<string, unknown>
|
||||
? DefinitelyDefined<T[L], keyof T[L]>
|
||||
: Required<T>[L];
|
||||
} & T;
|
||||
|
||||
type Reconstruct<T> = T extends Omit<infer O, infer _> ? O & Reconstruct<O> : T;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user