mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: add generic to readFile.ts buildData, adding different event loading strategies
This commit is contained in:
@@ -28,7 +28,7 @@ import { errTap } from './observableHandling';
|
||||
export const onReady = (wrapper: Wrapper) => {
|
||||
const { client, commands } = wrapper;
|
||||
const ready$ = fromEvent(client, 'ready').pipe(take(1), skip(1));
|
||||
const processCommandFiles$ = Files.buildData(commands).pipe(
|
||||
const processCommandFiles$ = Files.buildData<Module>(commands).pipe(
|
||||
errTap(reason => {
|
||||
wrapper.sernEmitter?.emit('module.register', {
|
||||
type: 'failure',
|
||||
|
||||
@@ -16,7 +16,10 @@ interface Wrapper {
|
||||
readonly sernEmitter?: SernEmitter;
|
||||
readonly defaultPrefix?: string;
|
||||
readonly commands: string;
|
||||
readonly events?: (DiscordEvent | EventEmitterRegister | SernEvent)[];
|
||||
readonly events?:
|
||||
| (DiscordEvent | EventEmitterRegister | SernEvent)[]
|
||||
| string
|
||||
| (() => (DiscordEvent | EventEmitterRegister | SernEvent)[]);
|
||||
}
|
||||
|
||||
export default Wrapper;
|
||||
|
||||
@@ -48,10 +48,10 @@ export const fmtFileName = (n: string) => n.substring(0, n.length - 3);
|
||||
* @param commandDir
|
||||
*/
|
||||
|
||||
export function buildData(commandDir: string): Observable<
|
||||
export function buildData<T>(commandDir: string): Observable<
|
||||
Result<
|
||||
{
|
||||
mod: Module;
|
||||
mod: T;
|
||||
absPath: string;
|
||||
},
|
||||
SernError.UndefinedModule
|
||||
@@ -60,7 +60,7 @@ export function buildData(commandDir: string): Observable<
|
||||
return from(
|
||||
getCommands(commandDir).map(absPath => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const mod = <Module | undefined>require(absPath).default;
|
||||
const mod = <T | undefined>require(absPath).default;
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule as const);
|
||||
|
||||
Reference in New Issue
Block a user