mirror of
https://github.com/sern-handler/handler
synced 2026-06-18 05:42:15 +00:00
feat: rolling out more event loading support
This commit is contained in:
@@ -48,9 +48,9 @@ export function ignoreNonBot(prefix: string) {
|
||||
* If the current value in Result stream is an error, calls callback.
|
||||
* @param cb
|
||||
*/
|
||||
export function errTap(cb: (err: SernError) => void) {
|
||||
return (src: Observable<Result<{ mod: Module; absPath: string }, SernError>>) =>
|
||||
new Observable<{ mod: Module; absPath: string }>(subscriber => {
|
||||
export function errTap<T extends Module>(cb: (err: SernError) => void) {
|
||||
return (src: Observable<Result<{ mod: T; absPath: string }, SernError>>) =>
|
||||
new Observable<{ mod: T; absPath: string }>(subscriber => {
|
||||
return src.subscribe({
|
||||
next(value) {
|
||||
if (value.err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Client } from 'discord.js';
|
||||
import type { DiscordEvent, EventEmitterRegister, SernEvent } from '../../types/handler';
|
||||
import type SernEmitter from '../sernEmitter';
|
||||
import type { EventModule } from './module';
|
||||
|
||||
/**
|
||||
* An object to be passed into Sern.Handler constructor.
|
||||
@@ -16,10 +17,7 @@ interface Wrapper {
|
||||
readonly sernEmitter?: SernEmitter;
|
||||
readonly defaultPrefix?: string;
|
||||
readonly commands: string;
|
||||
readonly events?:
|
||||
| (DiscordEvent | EventEmitterRegister | SernEvent)[]
|
||||
| string
|
||||
| (() => (DiscordEvent | EventEmitterRegister | SernEvent)[]);
|
||||
readonly events?: EventModule[] | string | (() => EventModule[]);
|
||||
}
|
||||
|
||||
export default Wrapper;
|
||||
|
||||
@@ -9,7 +9,7 @@ import type {
|
||||
SelectMenuInteraction,
|
||||
UserContextMenuCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import type { DiscordEvent, EventEmitterRegister, SernEvent } from '../..';
|
||||
import type { DiscordEventCommand, SernEventCommand } from '../structures/events';
|
||||
import { CommandType } from '../..';
|
||||
|
||||
export function correctModuleType<T extends keyof ModuleDefs>(
|
||||
@@ -50,12 +50,10 @@ export function isPromise<T>(promiseLike: Awaitable<T>): promiseLike is Promise<
|
||||
return keys.has('then') && keys.has('catch');
|
||||
}
|
||||
|
||||
export function isDiscordEvent(
|
||||
el: DiscordEvent | EventEmitterRegister | SernEvent,
|
||||
): el is DiscordEvent {
|
||||
return el.length === 2 && !['module.register', 'module.activates'].includes(el[0]);
|
||||
export function isDiscordEvent(el: EventModule): el is DiscordEventCommand {
|
||||
return el.type === CommandType.Discord;
|
||||
}
|
||||
export function isSernEvent(el: DiscordEvent | EventEmitterRegister | SernEvent): el is SernEvent {
|
||||
export function isSernEvent(el: EventModule): el is SernEventCommand {
|
||||
return !isDiscordEvent(el);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export function buildData<T>(commandDir: string): Observable<
|
||||
mod: T;
|
||||
absPath: string;
|
||||
},
|
||||
SernError.UndefinedModule
|
||||
SernError
|
||||
>
|
||||
> {
|
||||
return from(
|
||||
@@ -63,7 +63,7 @@ export function buildData<T>(commandDir: string): Observable<
|
||||
const mod = <T | undefined>require(absPath).default;
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule as const);
|
||||
} else return Err(SernError.UndefinedModule);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user