Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes authored Nov 6, 2023
2 parents a96c8bc + 132b625 commit 99845ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 8 additions & 23 deletions src/handlers/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends CommandModule, V extends BaseInteraction | Message>(
payload: { module: Processed<T>; 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<CommandModule>, args: [Context, Args]) {
return {
module,
args,
};
}

function dispatchAutocomplete(payload: {
module: Processed<BothCommand>;
event: AutocompleteInteraction;
Expand All @@ -52,9 +35,6 @@ export function contextArgs(wrappable: Message | BaseInteraction, messageArgs?:
return [ctx, args] as [Context, Args];
}

function interactionArg<T extends BaseInteraction>(interaction: T) {
return [interaction] as [T];
}

function intoPayload(module: Processed<Module>) {
return pipe(
Expand Down Expand Up @@ -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],
};
}
}
13 changes: 7 additions & 6 deletions src/handlers/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -78,8 +78,7 @@ export function createInteractionHandler<T extends Interaction>(
return Files
.defaultModuleLoader<Processed<CommandModule>>(fullPath)
.then(payload =>
Ok(createDispatcher({ module: payload.module, event }))
);
Ok(createDispatcher({ module: payload.module, event })));
},
);
}
Expand All @@ -98,9 +97,9 @@ export function createMessageHandler(
}
return Files
.defaultModuleLoader<Processed<CommandModule>>(fullPath)
.then(payload => {
.then(({ module })=> {
const args = contextArgs(event, rest);
return Ok(dispatchMessage(payload.module, args));
return Ok({ module, args });
});
});
}
Expand All @@ -126,7 +125,9 @@ export function buildModules<T extends AnyModule>(
input: ObservableInput<string>,
moduleManager: ModuleManager,
) {
return Files.buildModuleStream<Processed<T>>(input).pipe(assignDefaults(moduleManager));
return Files
.buildModuleStream<Processed<T>>(input)
.pipe(assignDefaults(moduleManager));
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/handlers/user-defined-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ export function eventsHandler(
}
};
buildModules<EventModule>(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();
}

0 comments on commit 99845ad

Please sign in to comment.