mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
790ce1681c | ||
|
|
cbad7380e1 | ||
|
|
ad36875be2 | ||
|
|
50288867a5 | ||
|
|
6b8995d149 | ||
|
|
82bbddac8d | ||
|
|
03936eb2ea | ||
|
|
c4019f7a08 | ||
|
|
992619f8e5 | ||
|
|
b995560ec6 | ||
|
|
f01ef9b86c | ||
|
|
702c5750fc | ||
|
|
d5d1b4129b | ||
|
|
7658d3e3ab | ||
|
|
9c1abc6b2e |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -1 +1 @@
|
||||
src/* @jacoobes
|
||||
* @jacoobes
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
.github/
|
||||
*.md
|
||||
*.md
|
||||
dist/
|
||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,5 +1,26 @@
|
||||
# Changelog
|
||||
|
||||
## [1.2.1](https://github.com/sern-handler/handler/compare/v1.2.0...v1.2.1) (2022-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **autocomplete:** now support multiple autocomplete options ([#147](https://github.com/sern-handler/handler/issues/147)) ([cbad738](https://github.com/sern-handler/handler/commit/cbad7380e1993b96c643f365726457f63e4fbd5d))
|
||||
|
||||
## [1.2.0](https://github.com/sern-handler/handler/compare/v1.1.0...v1.2.0) (2022-09-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* allow constructable modules ([#133](https://github.com/sern-handler/handler/issues/133)) ([03936eb](https://github.com/sern-handler/handler/commit/03936eb2ea1d1af7cada04d77bb8345d63a5e20f))
|
||||
* classmodules@arcs ([#143](https://github.com/sern-handler/handler/issues/143)) ([5028886](https://github.com/sern-handler/handler/commit/50288867a5b171511941a1be3877d721694e9f77))
|
||||
* update CODEOWNERS ([6b8995d](https://github.com/sern-handler/handler/commit/6b8995d149c857558415a6c151a3f575ec373445))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* feat of allow constructable modules ([#138](https://github.com/sern-handler/handler/issues/138)) ([82bbdda](https://github.com/sern-handler/handler/commit/82bbddac8d656b60b3a1fb2471ea03ee5224f5c3))
|
||||
|
||||
## [1.1.0](https://github.com/sern-handler/handler/compare/v1.0.0...v1.1.0) (2022-08-29)
|
||||
|
||||
|
||||
|
||||
14
README.md
14
README.md
@@ -1,17 +1,17 @@
|
||||
<div align="center">
|
||||
<img src="https://raw.githubusercontent.com/sern-handler/.github/main/banner.png" width="900px">
|
||||
<img src="https://raw.githubusercontent.com/sern-handler/.github/main/banner.png" width="900px" />
|
||||
</div>
|
||||
|
||||
<h1 align="center">Handlers. Redefined.</h1>
|
||||
<h4 align="center">A customizable, batteries-included, powerful discord.js framework to streamline bot development.</h4>
|
||||
|
||||
<div align="center" style="margin-top: 10px">
|
||||
<img src="https://img.shields.io/badge/open-source-brightgreen">
|
||||
<div align="center" styles="margin-top: 10px">
|
||||
<img src="https://img.shields.io/badge/open-source-brightgreen" />
|
||||
<a href="https://www.npmjs.com/package/@sern/handler"><img src="https://img.shields.io/npm/v/@sern/handler?maxAge=3600" alt="NPM version" /></a>
|
||||
<a href="https://www.npmjs.com/package/@sern/handler"><img src="https://img.shields.io/npm/dt/@sern/handler?maxAge=3600" alt="NPM downloads" /></a>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-brightgreen" alt="License MIT"></a>
|
||||
<a href="https://sern-handler.js.org"><img alt="docs.rs" src="https://img.shields.io/docsrs/docs"></a>
|
||||
<img alt="Lines of code" src="https://img.shields.io/badge/total%20lines-2k-blue">
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-brightgreen" alt="License MIT" /></a>
|
||||
<a href="https://sern-handler.js.org"><img alt="docs.rs" src="https://img.shields.io/docsrs/docs" /></a>
|
||||
<img alt="Lines of code" src="https://img.shields.io/badge/total%20lines-2k-blue" />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ client.login(token);
|
||||
#### ` ping.js (CommonJS)`
|
||||
|
||||
```js
|
||||
const { CommandType } = require('@sern/handler');
|
||||
const { CommandType, commandModule } = require('@sern/handler');
|
||||
|
||||
exports.default = commandModule({
|
||||
name: 'ping',
|
||||
|
||||
1493
package-lock.json
generated
1493
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sern/handler",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.1",
|
||||
"description": "A customizable, batteries-included, powerful discord.js framework to automate and streamline bot development.",
|
||||
"main": "dist/cjs/index.cjs",
|
||||
"module": "dist/esm/index.mjs",
|
||||
@@ -36,15 +36,15 @@
|
||||
"ts-results-es": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.35.1",
|
||||
"@typescript-eslint/parser": "5.35.1",
|
||||
"@typescript-eslint/eslint-plugin": "5.36.1",
|
||||
"@typescript-eslint/parser": "5.36.2",
|
||||
"eslint": "8.22.0",
|
||||
"prettier": "2.7.1",
|
||||
"tsup": "^6.1.3",
|
||||
"typescript": "4.7.4"
|
||||
"typescript": "^4.8.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"discord.js": "^14.2.x"
|
||||
"discord.js": "^14.5.x"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -3,8 +3,13 @@ import { Err, Ok } from 'ts-results-es';
|
||||
import { ExternalEventEmitters } from './utilities/readFile';
|
||||
import type { EventEmitter } from 'events';
|
||||
import { processEvents } from './events/userDefinedEventsHandling';
|
||||
import type { CommandModule, EventModule } from './structures/module';
|
||||
import { EventType, PluginType } from './structures/enums';
|
||||
import type {
|
||||
CommandModule,
|
||||
CommandModuleDefs,
|
||||
EventModule,
|
||||
EventModuleDefs,
|
||||
} from './structures/module';
|
||||
import { CommandType, EventType, PluginType } from './structures/enums';
|
||||
import type {
|
||||
CommandPlugin,
|
||||
EventModuleCommandPluginDefs,
|
||||
@@ -42,7 +47,7 @@ export function init(wrapper: Wrapper) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated - use Sern#makeDependencies instead
|
||||
* @param emitter Any external event emitter.
|
||||
* The object will be stored in a map, and then fetched by the name of the instance's class.
|
||||
* As there are infinite possibilities to adding external event emitters,
|
||||
@@ -119,3 +124,17 @@ export function eventModule(mod: InputEventModule): EventModule {
|
||||
plugins,
|
||||
} as EventModule;
|
||||
}
|
||||
|
||||
export abstract class CommandExecutable<Type extends CommandType> {
|
||||
abstract type: Type;
|
||||
plugins: CommandPlugin<Type>[] = [];
|
||||
onEvent: EventPlugin<Type>[] = [];
|
||||
abstract execute: CommandModuleDefs[Type]['execute'];
|
||||
}
|
||||
|
||||
export abstract class EventExecutable<Type extends EventType> {
|
||||
abstract type: Type;
|
||||
plugins: EventModuleCommandPluginDefs[Type][] = [];
|
||||
onEvent: EventModuleEventPluginDefs[Type][] = [];
|
||||
abstract execute: EventModuleDefs[Type]['execute'];
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import type {
|
||||
GuildMember,
|
||||
InteractionReplyOptions,
|
||||
Message,
|
||||
ReplyMessageOptions,
|
||||
Snowflake,
|
||||
TextBasedChannel,
|
||||
MessageReplyOptions,
|
||||
User,
|
||||
} from 'discord.js';
|
||||
import { type Option, None, Some } from 'ts-results-es';
|
||||
import type { Nullish } from '../../types/handler';
|
||||
import type { Nullish, ReplyOptions } from '../../types/handler';
|
||||
import { SernError } from './errors';
|
||||
|
||||
function firstSome<T>(...args: Option<T>[]): Nullish<T> {
|
||||
@@ -130,9 +130,7 @@ export default class Context {
|
||||
return this.oMsg.none && this.oInterac.none;
|
||||
}
|
||||
//Make queueable
|
||||
public reply(
|
||||
content: string | Omit<InteractionReplyOptions, 'fetchReply'> | ReplyMessageOptions,
|
||||
) {
|
||||
public reply(content: ReplyOptions) {
|
||||
return firstSome(
|
||||
this.oInterac.map(i => {
|
||||
return i
|
||||
@@ -140,7 +138,7 @@ export default class Context {
|
||||
.then(() => i.fetchReply());
|
||||
}),
|
||||
this.oMsg.map(m => {
|
||||
return m.reply(content as string | ReplyMessageOptions);
|
||||
return m.reply(content as string | MessageReplyOptions);
|
||||
}),
|
||||
)!;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,17 @@ import type { EventModule } from './module';
|
||||
* @typedef {object} Wrapper
|
||||
*/
|
||||
interface Wrapper {
|
||||
//@deprecated - Use Sern#makeDependencies instead
|
||||
readonly client: Client;
|
||||
//@deprecated - Use Sern#makeDependencies instead
|
||||
readonly sernEmitter?: SernEmitter;
|
||||
readonly defaultPrefix?: string;
|
||||
readonly commands: string;
|
||||
readonly events?:
|
||||
| string
|
||||
//@deprecated - array and function options will be removed
|
||||
| { mod: EventModule; absPath: string }[]
|
||||
//@deprecated - array and function options will be removed
|
||||
| (() => { mod: EventModule; absPath: string }[]);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,13 @@ export function buildData<T>(commandDir: string): Observable<
|
||||
} catch {
|
||||
mod = (await import(`file:///` + absPath)).default;
|
||||
}
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule);
|
||||
if (mod === undefined) {
|
||||
return Err(SernError.UndefinedModule);
|
||||
}
|
||||
try {
|
||||
mod = new (mod as unknown as new () => T)();
|
||||
} catch {}
|
||||
return Ok({ mod, absPath });
|
||||
}),
|
||||
),
|
||||
).pipe(concatAll());
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import type { SernOptionsData } from '../structures/module';
|
||||
import type { SernAutocompleteData, SernOptionsData } from '../structures/module';
|
||||
import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js';
|
||||
|
||||
export default function treeSearch(
|
||||
iAutocomplete: AutocompleteInteraction,
|
||||
options: SernOptionsData[] | undefined,
|
||||
) {
|
||||
): SernAutocompleteData {
|
||||
if (options === undefined) return undefined;
|
||||
const _options = options.slice(); // required to prevent direct mutation of options
|
||||
let autocompleteData: SernAutocompleteData;
|
||||
|
||||
while (_options.length > 0) {
|
||||
const cur = _options.pop()!;
|
||||
switch (cur.type) {
|
||||
@@ -29,12 +31,12 @@ export default function treeSearch(
|
||||
if (cur.autocomplete) {
|
||||
const choice = iAutocomplete.options.getFocused(true);
|
||||
if (cur.name === choice.name && cur.autocomplete) {
|
||||
return cur;
|
||||
autocompleteData = cur;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return autocompleteData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import SernEmitter from './handler/sernEmitter';
|
||||
export { eventModule, commandModule } from './handler/sern';
|
||||
export { eventModule, commandModule, EventExecutable, CommandExecutable } from './handler/sern';
|
||||
export * as Sern from './handler/sern';
|
||||
export * from './types/handler';
|
||||
export * from './handler/structures/structxports';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { CommandInteractionOptionResolver } from 'discord.js';
|
||||
import type { CommandModule, EventModule, Module } from '../handler/structures/module';
|
||||
import type { PayloadType } from '../handler/structures/enums';
|
||||
import type { InteractionReplyOptions, MessageReplyOptions } from 'discord.js';
|
||||
export type Nullish<T> = T | undefined | null;
|
||||
|
||||
// Thanks to @kelsny
|
||||
@@ -26,12 +27,6 @@ export type EventInput =
|
||||
| { mod: EventModule; absPath: string }[]
|
||||
| (() => { mod: EventModule; absPath: string }[]);
|
||||
|
||||
export type Reconstruct<T> = T extends Omit<infer O, never> ? O & Reconstruct<O> : T;
|
||||
|
||||
export type IsOptional<T> = {
|
||||
[K in keyof T]-?: T[K] extends Required<T>[K] ? false : true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turns a function with a union of array of args into a single union
|
||||
* [ T , V , B ] | [ A ] => T | V | B | A
|
||||
@@ -56,3 +51,8 @@ export type SernEventsMapping = {
|
||||
['error']: [Payload];
|
||||
['warning']: [string];
|
||||
};
|
||||
|
||||
export type ReplyOptions =
|
||||
| string
|
||||
| Omit<InteractionReplyOptions, 'fetchReply'>
|
||||
| MessageReplyOptions;
|
||||
|
||||
Reference in New Issue
Block a user