mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 17:36:56 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ef4ee87e9 | ||
|
|
fd39858636 | ||
|
|
132b625070 | ||
|
|
03439fec43 | ||
|
|
fc87e99ed0 | ||
|
|
a08541a8e7 | ||
|
|
8bd5eb4949 |
2
.github/workflows/continuous-integration.yml
vendored
2
.github/workflows/continuous-integration.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
|
||||
2
.github/workflows/dependency-review.yml
vendored
2
.github/workflows/dependency-review.yml
vendored
@@ -15,6 +15,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2
|
||||
|
||||
2
.github/workflows/npm-publish.yml
vendored
2
.github/workflows/npm-publish.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
test-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
|
||||
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
|
||||
with:
|
||||
node-version: 17
|
||||
|
||||
2
.github/workflows/release-please.yml
vendored
2
.github/workflows/release-please.yml
vendored
@@ -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
|
||||
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
|
||||
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
|
||||
with:
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## [3.1.1](https://github.com/sern-handler/handler/compare/v3.1.0...v3.1.1) (2023-11-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* queuing events ([fd39858](https://github.com/sern-handler/handler/commit/fd39858636d3038abb6d91021b65c99c488a3d6e))
|
||||
* queuing events ([#332](https://github.com/sern-handler/handler/issues/332)) @Benzo-Fury ([#333](https://github.com/sern-handler/handler/issues/333)) ([fd39858](https://github.com/sern-handler/handler/commit/fd39858636d3038abb6d91021b65c99c488a3d6e))
|
||||
|
||||
## [3.1.0](https://github.com/sern-handler/handler/compare/v3.0.2...v3.1.0) (2023-09-04)
|
||||
|
||||
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
- For you. A framework that's tailored to your exact needs.
|
||||
- Lightweight. Does a lot while being small.
|
||||
- Latest features. Support for discord.js v14 and all of its interactions.
|
||||
- Hybrid, customizable and composable commands. Create them just how you like.
|
||||
- Start quickly. Plug and play or customize to your liking.
|
||||
- Embraces reactive programming. For consistent and reliable backend.
|
||||
- Switch and customize how errors are handled, logging, and more.
|
||||
- works with [bun](https://bun.sh/) and [node](https://nodejs.org/en) out the box!
|
||||
- Use it with TypeScript or JavaScript. CommonJS and ESM supported.
|
||||
- Active and growing community, always here to help. [Join us](https://sern.dev/discord)
|
||||
- Unleash its full potential with a powerful CLI and awesome plugins.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@sern/handler",
|
||||
"packageManager": "yarn@3.5.0",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
||||
@@ -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;
|
||||
@@ -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(
|
||||
@@ -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],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T extends Interaction>(
|
||||
return Files
|
||||
.defaultModuleLoader<Processed<CommandModule>>(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<Processed<CommandModule>>(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<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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Interaction } from 'discord.js';
|
||||
import { concatMap, merge } from 'rxjs';
|
||||
import { mergeMap, merge } from 'rxjs';
|
||||
import { SernEmitter } from '../core';
|
||||
import {
|
||||
isAutocomplete,
|
||||
@@ -28,6 +28,6 @@ export function interactionHandler([emitter, , , modules, client]: DependencyLis
|
||||
filterTap(e => emitter.emit('warning', SernEmitter.warning(e))),
|
||||
makeModuleExecutor(module =>
|
||||
emitter.emit('module.activate', SernEmitter.failure(module, SernError.PluginFailure))),
|
||||
concatMap(payload => executeModule(emitter, payload)),
|
||||
mergeMap(payload => executeModule(emitter, payload)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { concatMap, EMPTY } from 'rxjs';
|
||||
import { mergeMap, EMPTY } from 'rxjs';
|
||||
import type { Message } from 'discord.js';
|
||||
import { SernEmitter } from '../core';
|
||||
import { sharedEventStream, SernError, filterTap } from '../core/_internal';
|
||||
@@ -42,6 +42,6 @@ export function messageHandler(
|
||||
makeModuleExecutor(module => {
|
||||
emitter.emit('module.activate', SernEmitter.failure(module, SernError.PluginFailure));
|
||||
}),
|
||||
concatMap(payload => executeModule(emitter, payload)),
|
||||
mergeMap(payload => executeModule(emitter, payload)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user