mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
style: pretty please (#260)
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2fd7697300
commit
cee740ea3f
4672
pnpm-lock.yaml
generated
4672
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -95,21 +95,23 @@ function createDispatcher({
|
||||
event: Interaction;
|
||||
module: Processed<CommandModule>;
|
||||
}) {
|
||||
switch(module.type) {
|
||||
case CommandType.Text:
|
||||
switch (module.type) {
|
||||
case CommandType.Text:
|
||||
throw Error(SernError.MismatchEvent);
|
||||
case CommandType.Slash: case CommandType.Both : {
|
||||
if(event.isAutocomplete()) {
|
||||
case CommandType.Slash:
|
||||
case CommandType.Both: {
|
||||
if (event.isAutocomplete()) {
|
||||
/**
|
||||
* Autocomplete is a special case that
|
||||
* must be handled separately, since it's
|
||||
* too different from regular command modules
|
||||
*/
|
||||
* Autocomplete is a special case that
|
||||
* must be handled separately, since it's
|
||||
* too different from regular command modules
|
||||
*/
|
||||
return dispatchAutocomplete(module, event);
|
||||
} else {
|
||||
return dispatchCommand(module, contextArgs(event));
|
||||
}
|
||||
}
|
||||
default : return dispatchCommand(module, interactionArg(event));
|
||||
default:
|
||||
return dispatchCommand(module, interactionArg(event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,17 +68,20 @@ export function defineAllFields<T extends AnyModule>() {
|
||||
* @returns Observable<{ module: T; absPath: string }>
|
||||
*/
|
||||
export function errTap<T extends AnyModule>(
|
||||
cb: (err: SernError) => void
|
||||
): OperatorFunction<Result<{ module: T; absPath: string}, SernError>, { module: T; absPath: string }> {
|
||||
return pipe(
|
||||
concatMap(result => {
|
||||
if(result.ok) {
|
||||
return of(result.val);
|
||||
} else {
|
||||
cb(result.val);
|
||||
return EMPTY;
|
||||
}
|
||||
})
|
||||
cb: (err: SernError) => void,
|
||||
): OperatorFunction<
|
||||
Result<{ module: T; absPath: string }, SernError>,
|
||||
{ module: T; absPath: string }
|
||||
> {
|
||||
return pipe(
|
||||
concatMap(result => {
|
||||
if (result.ok) {
|
||||
return of(result.val);
|
||||
} else {
|
||||
cb(result.val);
|
||||
return EMPTY;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,7 @@ import { defineAllFields, errTap } from './operators';
|
||||
import SernEmitter from '../sernEmitter';
|
||||
import type { EventEmitter } from 'node:events';
|
||||
|
||||
|
||||
function buildCommandModules(
|
||||
commandDir: string,
|
||||
sernEmitter: SernEmitter
|
||||
) {
|
||||
function buildCommandModules(commandDir: string, sernEmitter: SernEmitter) {
|
||||
return pipe(
|
||||
switchMap(() => Files.buildData<CommandModule>(commandDir)),
|
||||
errTap(error => {
|
||||
@@ -46,7 +42,7 @@ export function makeReadyEvent(
|
||||
SernEmitter.failure(module, SernError.PluginFailure),
|
||||
);
|
||||
},
|
||||
onSuccess: ({ module }) => {
|
||||
onSuccess: ({ module }) => {
|
||||
sEmitter.emit('module.register', SernEmitter.success(module));
|
||||
return module;
|
||||
},
|
||||
@@ -69,28 +65,34 @@ function registerModule<T extends Processed<CommandModule>>(
|
||||
const set = Result.wrap(() => manager.set(cb));
|
||||
return set.ok ? ok() : err();
|
||||
};
|
||||
switch(mod.type) {
|
||||
switch (mod.type) {
|
||||
case CommandType.Text: {
|
||||
mod.alias?.forEach(a => insert(ms => ms.TextCommands.set(a, mod)));
|
||||
return insert(ms => ms.TextCommands.set(name, mod));
|
||||
mod.alias?.forEach(a => insert(ms => ms.TextCommands.set(a, mod)));
|
||||
return insert(ms => ms.TextCommands.set(name, mod));
|
||||
}
|
||||
case CommandType.Slash:
|
||||
return insert(ms => ms.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod));
|
||||
case CommandType.Slash:
|
||||
return insert(ms =>
|
||||
ms.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod),
|
||||
);
|
||||
case CommandType.Both: {
|
||||
mod.alias?.forEach(a => insert(ms => ms.TextCommands.set(a, mod)));
|
||||
return insert(ms => ms.BothCommands.set(name, mod));
|
||||
}
|
||||
case CommandType.CtxUser:
|
||||
return insert(ms => ms.ApplicationCommands[ApplicationCommandType.User].set(name, mod));
|
||||
case CommandType.CtxUser:
|
||||
return insert(ms => ms.ApplicationCommands[ApplicationCommandType.User].set(name, mod));
|
||||
case CommandType.CtxMsg:
|
||||
return insert(ms => ms.ApplicationCommands[ApplicationCommandType.Message].set(name, mod));
|
||||
return insert(ms =>
|
||||
ms.ApplicationCommands[ApplicationCommandType.Message].set(name, mod),
|
||||
);
|
||||
case CommandType.Button:
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.Button].set(name, mod));
|
||||
case CommandType.StringSelect:
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.StringSelect].set(name, mod));
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.StringSelect].set(name, mod));
|
||||
case CommandType.MentionableSelect:
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.MentionableSelect].set(name, mod));
|
||||
case CommandType.UserSelect:
|
||||
return insert(ms =>
|
||||
ms.InteractionHandlers[ComponentType.MentionableSelect].set(name, mod),
|
||||
);
|
||||
case CommandType.UserSelect:
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.UserSelect].set(name, mod));
|
||||
case CommandType.ChannelSelect:
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.ChannelSelect].set(name, mod));
|
||||
@@ -98,6 +100,7 @@ function registerModule<T extends Processed<CommandModule>>(
|
||||
return insert(ms => ms.InteractionHandlers[ComponentType.RoleSelect].set(name, mod));
|
||||
case CommandType.Modal:
|
||||
return insert(ms => ms.ModalSubmit.set(name, mod));
|
||||
default: return err();
|
||||
default:
|
||||
return err();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ export function makeEventsHandler(
|
||||
const eventCreation$ = eventStream$.pipe(
|
||||
defineAllFields(),
|
||||
callInitPlugins({
|
||||
onFailure: module => s.emit('module.register', SernEmitter.failure(module, SernError.PluginFailure)),
|
||||
onFailure: module =>
|
||||
s.emit('module.register', SernEmitter.failure(module, SernError.PluginFailure)),
|
||||
onSuccess: ({ module }) => {
|
||||
s.emit('module.register', SernEmitter.success(module));
|
||||
return module;
|
||||
@@ -31,11 +32,15 @@ export function makeEventsHandler(
|
||||
}),
|
||||
);
|
||||
const intoDispatcher = (e: Processed<EventModule | CommandModule>) => {
|
||||
switch(e.type) {
|
||||
case EventType.Sern: return eventDispatcher(e, s);
|
||||
case EventType.Discord: return eventDispatcher(e, client);
|
||||
case EventType.External: return eventDispatcher(e, lazy(e.emitter));
|
||||
default: err.crash(Error(SernError.InvalidModuleType + ' while creating event handler'));
|
||||
switch (e.type) {
|
||||
case EventType.Sern:
|
||||
return eventDispatcher(e, s);
|
||||
case EventType.Discord:
|
||||
return eventDispatcher(e, client);
|
||||
case EventType.External:
|
||||
return eventDispatcher(e, lazy(e.emitter));
|
||||
default:
|
||||
err.crash(Error(SernError.InvalidModuleType + ' while creating event handler'));
|
||||
}
|
||||
};
|
||||
eventCreation$
|
||||
|
||||
@@ -19,7 +19,7 @@ import type {
|
||||
MentionableSelectMenuInteraction,
|
||||
RoleSelectMenuInteraction,
|
||||
StringSelectMenuInteraction,
|
||||
UserSelectMenuInteraction
|
||||
UserSelectMenuInteraction,
|
||||
} from 'discord.js';
|
||||
import { CommandType } from '../handler/structures/enums';
|
||||
import type { Args, SlashOptions } from './handler';
|
||||
|
||||
Reference in New Issue
Block a user