Compare commits

...

15 Commits

Author SHA1 Message Date
github-actions[bot]
790ce1681c chore(main): release 1.2.1 (#148)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-10-03 11:53:45 -05:00
Evo
cbad7380e1 fix(autocomplete): now support multiple autocomplete options (#147) 2022-10-03 11:50:49 -05:00
github-actions[bot]
ad36875be2 chore(main): release 1.2.0 (#145)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-09-28 11:57:10 -05:00
Jacob Nguyen
50288867a5 feat: classmodules@arcs (#143)
* feat: add class based commands

* docs: add deprecation warnings

* feat: add deprecation warnings

* feat: add more deprecation warnings

* feat: add prototype ClassModule abstract class

* feat: add EventModuleClass prototype, change names

* feat: more flexible contract

* feat: EventExecutable

* fix: typo

* feat: made abstract classes because of defaults

* fix: typings

* feat: update Context typings, update to djs v15

* chore: update typescript dependency

* chore: bump version

* chore: update ignore

* chore: prettier

* docs: change readme to be docusaurus compliant
2022-09-28 11:52:25 -05:00
Jacob Nguyen
6b8995d149 feat: update CODEOWNERS 2022-09-13 14:41:57 -05:00
xxDeveloper
82bbddac8d revert: feat of allow constructable modules (#138)
Revert "feat: allow constructable modules (#133)"

This reverts commit 03936eb2ea.
2022-09-13 14:36:15 -05:00
Arcs
03936eb2ea feat: allow constructable modules (#133)
* Update readFile.ts

* Update userDefinedEventsHandling.ts

* Update readyHandler.ts

* fix: ts error

Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
Co-authored-by: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com>
2022-09-13 21:46:06 +03:00
renovate[bot]
c4019f7a08 chore(deps): lock file maintenance (#136)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-09-12 20:57:34 +03:00
renovate[bot]
992619f8e5 chore(deps): update dependency @typescript-eslint/parser to v5.36.2 (#131)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com>
2022-09-11 14:24:50 +03:00
renovate[bot]
b995560ec6 chore(deps): update dependency @typescript-eslint/eslint-plugin to v5.36.2 (#130)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com>
2022-09-11 14:19:40 +03:00
renovate[bot]
f01ef9b86c chore(deps): lock file maintenance (#129)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-09-11 14:16:19 +03:00
xxDeveloper
702c5750fc docs: Fix the code example (#128) 2022-09-03 14:52:26 +03:00
renovate[bot]
d5d1b4129b chore(deps): update dependency @typescript-eslint/eslint-plugin to v5.36.1 (#126)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-09-03 11:26:55 +03:00
renovate[bot]
7658d3e3ab chore(deps): update dependency @typescript-eslint/parser to v5.36.1 (#127)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-09-03 11:24:09 +03:00
renovate[bot]
9c1abc6b2e chore(deps): lock file maintenance (#118) 2022-08-29 14:07:45 +03:00
13 changed files with 1262 additions and 354 deletions

2
.github/CODEOWNERS vendored
View File

@@ -1 +1 @@
src/* @jacoobes * @jacoobes

View File

@@ -1,2 +1,3 @@
.github/ .github/
*.md *.md
dist/

View File

@@ -1,5 +1,26 @@
# Changelog # 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) ## [1.1.0](https://github.com/sern-handler/handler/compare/v1.0.0...v1.1.0) (2022-08-29)

View File

@@ -1,17 +1,17 @@
<div align="center"> <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> </div>
<h1 align="center">Handlers. Redefined.</h1> <h1 align="center">Handlers. Redefined.</h1>
<h4 align="center">A customizable, batteries-included, powerful discord.js framework to streamline bot development.</h4> <h4 align="center">A customizable, batteries-included, powerful discord.js framework to streamline bot development.</h4>
<div align="center" style="margin-top: 10px"> <div align="center" styles="margin-top: 10px">
<img src="https://img.shields.io/badge/open-source-brightgreen"> <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/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://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://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> <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"> <img alt="Lines of code" src="https://img.shields.io/badge/total%20lines-2k-blue" />
</div> </div>
@@ -71,7 +71,7 @@ client.login(token);
#### ` ping.js (CommonJS)` #### ` ping.js (CommonJS)`
```js ```js
const { CommandType } = require('@sern/handler'); const { CommandType, commandModule } = require('@sern/handler');
exports.default = commandModule({ exports.default = commandModule({
name: 'ping', name: 'ping',

1493
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "@sern/handler", "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.", "description": "A customizable, batteries-included, powerful discord.js framework to automate and streamline bot development.",
"main": "dist/cjs/index.cjs", "main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs", "module": "dist/esm/index.mjs",
@@ -36,15 +36,15 @@
"ts-results-es": "^3.5.0" "ts-results-es": "^3.5.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "5.35.1", "@typescript-eslint/eslint-plugin": "5.36.1",
"@typescript-eslint/parser": "5.35.1", "@typescript-eslint/parser": "5.36.2",
"eslint": "8.22.0", "eslint": "8.22.0",
"prettier": "2.7.1", "prettier": "2.7.1",
"tsup": "^6.1.3", "tsup": "^6.1.3",
"typescript": "4.7.4" "typescript": "^4.8.3"
}, },
"peerDependencies": { "peerDependencies": {
"discord.js": "^14.2.x" "discord.js": "^14.5.x"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -3,8 +3,13 @@ import { Err, Ok } from 'ts-results-es';
import { ExternalEventEmitters } from './utilities/readFile'; import { ExternalEventEmitters } from './utilities/readFile';
import type { EventEmitter } from 'events'; import type { EventEmitter } from 'events';
import { processEvents } from './events/userDefinedEventsHandling'; import { processEvents } from './events/userDefinedEventsHandling';
import type { CommandModule, EventModule } from './structures/module'; import type {
import { EventType, PluginType } from './structures/enums'; CommandModule,
CommandModuleDefs,
EventModule,
EventModuleDefs,
} from './structures/module';
import { CommandType, EventType, PluginType } from './structures/enums';
import type { import type {
CommandPlugin, CommandPlugin,
EventModuleCommandPluginDefs, EventModuleCommandPluginDefs,
@@ -42,7 +47,7 @@ export function init(wrapper: Wrapper) {
} }
/** /**
* * @deprecated - use Sern#makeDependencies instead
* @param emitter Any external event emitter. * @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. * 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, * As there are infinite possibilities to adding external event emitters,
@@ -119,3 +124,17 @@ export function eventModule(mod: InputEventModule): EventModule {
plugins, plugins,
} as EventModule; } 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'];
}

View File

@@ -6,13 +6,13 @@ import type {
GuildMember, GuildMember,
InteractionReplyOptions, InteractionReplyOptions,
Message, Message,
ReplyMessageOptions,
Snowflake, Snowflake,
TextBasedChannel, TextBasedChannel,
MessageReplyOptions,
User, User,
} from 'discord.js'; } from 'discord.js';
import { type Option, None, Some } from 'ts-results-es'; 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'; import { SernError } from './errors';
function firstSome<T>(...args: Option<T>[]): Nullish<T> { function firstSome<T>(...args: Option<T>[]): Nullish<T> {
@@ -130,9 +130,7 @@ export default class Context {
return this.oMsg.none && this.oInterac.none; return this.oMsg.none && this.oInterac.none;
} }
//Make queueable //Make queueable
public reply( public reply(content: ReplyOptions) {
content: string | Omit<InteractionReplyOptions, 'fetchReply'> | ReplyMessageOptions,
) {
return firstSome( return firstSome(
this.oInterac.map(i => { this.oInterac.map(i => {
return i return i
@@ -140,7 +138,7 @@ export default class Context {
.then(() => i.fetchReply()); .then(() => i.fetchReply());
}), }),
this.oMsg.map(m => { this.oMsg.map(m => {
return m.reply(content as string | ReplyMessageOptions); return m.reply(content as string | MessageReplyOptions);
}), }),
)!; )!;
} }

View File

@@ -7,13 +7,17 @@ import type { EventModule } from './module';
* @typedef {object} Wrapper * @typedef {object} Wrapper
*/ */
interface Wrapper { interface Wrapper {
//@deprecated - Use Sern#makeDependencies instead
readonly client: Client; readonly client: Client;
//@deprecated - Use Sern#makeDependencies instead
readonly sernEmitter?: SernEmitter; readonly sernEmitter?: SernEmitter;
readonly defaultPrefix?: string; readonly defaultPrefix?: string;
readonly commands: string; readonly commands: string;
readonly events?: readonly events?:
| string | string
//@deprecated - array and function options will be removed
| { mod: EventModule; absPath: string }[] | { mod: EventModule; absPath: string }[]
//@deprecated - array and function options will be removed
| (() => { mod: EventModule; absPath: string }[]); | (() => { mod: EventModule; absPath: string }[]);
} }

View File

@@ -73,9 +73,13 @@ export function buildData<T>(commandDir: string): Observable<
} catch { } catch {
mod = (await import(`file:///` + absPath)).default; mod = (await import(`file:///` + absPath)).default;
} }
if (mod !== undefined) { if (mod === undefined) {
return Ok({ mod, absPath }); return Err(SernError.UndefinedModule);
} else return Err(SernError.UndefinedModule); }
try {
mod = new (mod as unknown as new () => T)();
} catch {}
return Ok({ mod, absPath });
}), }),
), ),
).pipe(concatAll()); ).pipe(concatAll());

View File

@@ -1,12 +1,14 @@
import type { SernOptionsData } from '../structures/module'; import type { SernAutocompleteData, SernOptionsData } from '../structures/module';
import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js'; import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js';
export default function treeSearch( export default function treeSearch(
iAutocomplete: AutocompleteInteraction, iAutocomplete: AutocompleteInteraction,
options: SernOptionsData[] | undefined, options: SernOptionsData[] | undefined,
) { ): SernAutocompleteData {
if (options === undefined) return undefined; if (options === undefined) return undefined;
const _options = options.slice(); // required to prevent direct mutation of options const _options = options.slice(); // required to prevent direct mutation of options
let autocompleteData: SernAutocompleteData;
while (_options.length > 0) { while (_options.length > 0) {
const cur = _options.pop()!; const cur = _options.pop()!;
switch (cur.type) { switch (cur.type) {
@@ -29,12 +31,12 @@ export default function treeSearch(
if (cur.autocomplete) { if (cur.autocomplete) {
const choice = iAutocomplete.options.getFocused(true); const choice = iAutocomplete.options.getFocused(true);
if (cur.name === choice.name && cur.autocomplete) { if (cur.name === choice.name && cur.autocomplete) {
return cur; autocompleteData = cur;
} }
return undefined;
} }
} }
break; break;
} }
} }
return autocompleteData;
} }

View File

@@ -1,5 +1,5 @@
import SernEmitter from './handler/sernEmitter'; 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 * as Sern from './handler/sern';
export * from './types/handler'; export * from './types/handler';
export * from './handler/structures/structxports'; export * from './handler/structures/structxports';

View File

@@ -1,6 +1,7 @@
import type { CommandInteractionOptionResolver } from 'discord.js'; import type { CommandInteractionOptionResolver } from 'discord.js';
import type { CommandModule, EventModule, Module } from '../handler/structures/module'; import type { CommandModule, EventModule, Module } from '../handler/structures/module';
import type { PayloadType } from '../handler/structures/enums'; import type { PayloadType } from '../handler/structures/enums';
import type { InteractionReplyOptions, MessageReplyOptions } from 'discord.js';
export type Nullish<T> = T | undefined | null; export type Nullish<T> = T | undefined | null;
// Thanks to @kelsny // Thanks to @kelsny
@@ -26,12 +27,6 @@ export type EventInput =
| { mod: EventModule; absPath: string }[] | { mod: EventModule; absPath: string }[]
| (() => { 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 * Turns a function with a union of array of args into a single union
* [ T , V , B ] | [ A ] => T | V | B | A * [ T , V , B ] | [ A ] => T | V | B | A
@@ -56,3 +51,8 @@ export type SernEventsMapping = {
['error']: [Payload]; ['error']: [Payload];
['warning']: [string]; ['warning']: [string];
}; };
export type ReplyOptions =
| string
| Omit<InteractionReplyOptions, 'fetchReply'>
| MessageReplyOptions;