From 03439fec434db8456b32a66fc832dda48cf6c2fa Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 21 Oct 2023 22:30:40 -0500 Subject: [PATCH 1/2] chore(deps): update google-github-actions/release-please-action digest to 4c5670f (#336) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/release-please.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 4cbf3ec2..8af0d7ba 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -6,7 +6,7 @@ jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@ca6063f4ed81b55db15b8c42d1b6f7925866342d # v3 + - uses: google-github-actions/release-please-action@4c5670f886fe259db4d11222f7dff41c1382304d # v3 with: release-type: node package-name: release-please-action From 132b625070bd7d5ecdef3bd3746428cec1e02949 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 4 Nov 2023 16:57:13 -0500 Subject: [PATCH 2/2] refactor: rm redudant fns and formatting --- src/handlers/dispatchers.ts | 31 ++++++++--------------------- src/handlers/event-utils.ts | 13 ++++++------ src/handlers/user-defined-events.ts | 16 +++++++-------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/handlers/dispatchers.ts b/src/handlers/dispatchers.ts index 6826cf70..2b8cd296 100644 --- a/src/handlers/dispatchers.ts +++ b/src/handlers/dispatchers.ts @@ -14,23 +14,6 @@ import { CommandType, Context } from '../core'; import type { Args } from '../types/utility'; import type { BothCommand, CommandModule, Module, Processed } from '../types/core-modules'; -function dispatchInteraction( - payload: { module: Processed; event: V }, - createArgs: (m: typeof payload.event) => unknown[], -) { - return { - module: payload.module, - args: createArgs(payload.event), - }; -} -//TODO: refactor dispatchers so that it implements a strategy for each different type of payload? -export function dispatchMessage(module: Processed, args: [Context, Args]) { - return { - module, - args, - }; -} - function dispatchAutocomplete(payload: { module: Processed; event: AutocompleteInteraction; @@ -52,9 +35,6 @@ export function contextArgs(wrappable: Message | BaseInteraction, messageArgs?: return [ctx, args] as [Context, Args]; } -function interactionArg(interaction: T) { - return [interaction] as [T]; -} function intoPayload(module: Processed) { return pipe( @@ -109,9 +89,14 @@ export function createDispatcher(payload: { */ return dispatchAutocomplete(payload as never); } - return dispatchInteraction(payload, contextArgs); + return { + module: payload.module, + args: contextArgs(payload.event), + }; } - default: - return dispatchInteraction(payload, interactionArg); + default: return { + module: payload.module, + args: [payload.event], + }; } } diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index e61cc2ed..3329b1c7 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -24,7 +24,7 @@ import { useContainerRaw, } from '../core/_internal'; import { Emitter, ErrorHandling, Logging, ModuleManager } from '../core'; -import { contextArgs, createDispatcher, dispatchMessage } from './dispatchers'; +import { contextArgs, createDispatcher } from './dispatchers'; import { ObservableInput, pipe } from 'rxjs'; import { SernEmitter } from '../core'; import { Err, Ok, Result } from 'ts-results-es'; @@ -78,8 +78,7 @@ export function createInteractionHandler( return Files .defaultModuleLoader>(fullPath) .then(payload => - Ok(createDispatcher({ module: payload.module, event })) - ); + Ok(createDispatcher({ module: payload.module, event }))); }, ); } @@ -98,9 +97,9 @@ export function createMessageHandler( } return Files .defaultModuleLoader>(fullPath) - .then(payload => { + .then(({ module })=> { const args = contextArgs(event, rest); - return Ok(dispatchMessage(payload.module, args)); + return Ok({ module, args }); }); }); } @@ -126,7 +125,9 @@ export function buildModules( input: ObservableInput, moduleManager: ModuleManager, ) { - return Files.buildModuleStream>(input).pipe(assignDefaults(moduleManager)); + return Files + .buildModuleStream>(input) + .pipe(assignDefaults(moduleManager)); } /** diff --git a/src/handlers/user-defined-events.ts b/src/handlers/user-defined-events.ts index 822aa736..ff5d23af 100644 --- a/src/handlers/user-defined-events.ts +++ b/src/handlers/user-defined-events.ts @@ -24,14 +24,12 @@ export function eventsHandler( } }; buildModules(allPaths, moduleManager) - .pipe( - callInitPlugins(emitter), - map(intoDispatcher), - /** - * Where all events are turned on - */ - mergeAll(), - handleCrash(err, log), - ) + .pipe(callInitPlugins(emitter), + map(intoDispatcher), + /** + * Where all events are turned on + */ + mergeAll(), + handleCrash(err, log)) .subscribe(); }