mirror of
https://github.com/SrIzan10/handler.git
synced 2026-05-01 10:45:17 +00:00
Compare commits
55 Commits
v1.0.0
...
global_ser
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13cdb8b8cb | ||
|
|
a8f218ff00 | ||
|
|
fe1b7e4e84 | ||
|
|
a0f4184c2e | ||
|
|
1b830d492d | ||
|
|
2189a065c7 | ||
|
|
59a956fd0d | ||
|
|
8183e95a96 | ||
|
|
355865968a | ||
|
|
aca8ae2b13 | ||
|
|
3f6ce51548 | ||
|
|
8c12576f0e | ||
|
|
a40c7efa19 | ||
|
|
e2471d32cf | ||
|
|
f993e3fd66 | ||
|
|
9b51fc0c56 | ||
|
|
651f4aa35c | ||
|
|
2f10b0e6d2 | ||
|
|
a0ab4152d1 | ||
|
|
3b0b94b35a | ||
|
|
23edd5b193 | ||
|
|
b0e5512686 | ||
|
|
fd9dc35ff0 | ||
|
|
813ba0922e | ||
|
|
20bc135a7d | ||
|
|
8a373de880 | ||
|
|
395549c173 | ||
|
|
dbc180fa78 | ||
|
|
ff5c161469 | ||
|
|
82637245f3 | ||
|
|
bc3ed918da | ||
|
|
0c2f1b513b | ||
|
|
62bfcb1eb7 | ||
|
|
fbf54c9d36 | ||
|
|
b999918b71 | ||
|
|
224ce97fe8 | ||
|
|
e85eb81f8b | ||
|
|
a4301dc283 | ||
|
|
3c0da263b2 | ||
|
|
8c6fb27989 | ||
|
|
2830370025 | ||
|
|
4092b9be52 | ||
|
|
c98425da14 | ||
|
|
6565697b0c | ||
|
|
b94a9e932d | ||
|
|
f52dd01ca5 | ||
|
|
7162ccb928 | ||
|
|
2b6335fba1 | ||
|
|
b8841e926d | ||
|
|
f0f54cb7f2 | ||
|
|
8626add53e | ||
|
|
74e004d9c1 | ||
|
|
4323be47d7 | ||
|
|
ebe759f5e0 | ||
|
|
58d97e08a5 |
12
.eslintrc
12
.eslintrc
@@ -3,9 +3,11 @@
|
||||
"extends": ["plugin:@typescript-eslint/recommended"],
|
||||
"parserOptions": { "ecmaVersion": "latest", "sourceType": "script" },
|
||||
"rules": {
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals" : true }],
|
||||
"semi": ["error", "always"],
|
||||
"@typescript-eslint/no-empty-interface": 0
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
|
||||
"semi": ["error", "always"],
|
||||
"@typescript-eslint/no-empty-interface": 0,
|
||||
"@typescript-eslint/ban-types" : 0
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
.github/workflows/continuous-integration.yml
vendored
Normal file
44
.github/workflows/continuous-integration.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Continuous Integration
|
||||
|
||||
on:
|
||||
# Trigger the workflow on push or pull request or custom
|
||||
push:
|
||||
branches:
|
||||
main
|
||||
pull_request_target:
|
||||
branches:
|
||||
main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
Prettier:
|
||||
name: Run Prettier
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
|
||||
with:
|
||||
node-version: 17
|
||||
|
||||
# Prettier must be in `package.json`
|
||||
- name: Install Node.js dependencies
|
||||
run: npm i -g prettier && npm i
|
||||
|
||||
- name: Run Prettier
|
||||
run: prettier --write .
|
||||
|
||||
- name: Create Pull Request
|
||||
id: cpr
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
commit-message: "style: pretty please"
|
||||
branch: prettier
|
||||
delete-branch: true
|
||||
branch-suffix: short-commit-hash
|
||||
title: "style: pretty please"
|
||||
body: "pretty pretty prettier"
|
||||
reviewers: EvolutionX-10
|
||||
12
.prettierrc
12
.prettierrc
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"semi": true,
|
||||
"trailingComma": "all",
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"tabWidth": 4,
|
||||
"arrowParens": "avoid"
|
||||
"semi": true,
|
||||
"trailingComma": "all",
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"tabWidth": 4,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
|
||||
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## [1.1.0](https://github.com/sern-handler/handler/compare/v1.0.0...v1.1.0) (2022-08-29)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add proper error handling ([#115](https://github.com/sern-handler/handler/issues/115)) ([395549c](https://github.com/sern-handler/handler/commit/395549c173cb62a18205e451bf2cb5579ba9a6e0))
|
||||
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* release 1.1.0 ([8a373de](https://github.com/sern-handler/handler/commit/8a373de880ff18df85af812adf9f6f6a4f45028d))
|
||||
|
||||
## 1.0.0 (2022-08-15)
|
||||
|
||||
|
||||
|
||||
8992
package-lock.json
generated
8992
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
106
package.json
106
package.json
@@ -1,54 +1,56 @@
|
||||
{
|
||||
"name": "@sern/handler",
|
||||
"version": "1.0.0",
|
||||
"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",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/cjs/index.cjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsup --watch --dts",
|
||||
"clean-modules": "rimraf node_modules/ && npm install",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "eslint src/**/*.ts --fix",
|
||||
"build": "tsup && node scripts/mkjson.mjs dist/cjs dist/esm && tsup --dts-only --outDir dist",
|
||||
"publish": "npm run build && npm publish"
|
||||
},
|
||||
"keywords": [
|
||||
"sern-handler",
|
||||
"sern",
|
||||
"handler",
|
||||
"sern handler",
|
||||
"wrapper",
|
||||
"discord.js",
|
||||
"framework"
|
||||
],
|
||||
"author": "SernDevs",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"rxjs": "^7.5.6",
|
||||
"ts-pattern": "^4.0.2",
|
||||
"ts-results-es": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.32.0",
|
||||
"@typescript-eslint/parser": "5.32.0",
|
||||
"eslint": "8.21.0",
|
||||
"prettier": "2.7.1",
|
||||
"tsup": "^6.1.3",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"discord.js": "^14.2.x"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sern-handler/handler.git"
|
||||
},
|
||||
"homepage": "https://sern-handler.js.org"
|
||||
"name": "@sern/handler",
|
||||
"version": "1.1.0",
|
||||
"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",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/cjs/index.cjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsup --watch --dts",
|
||||
"clean-modules": "rimraf node_modules/ && npm install",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "eslint src/**/*.ts --fix",
|
||||
"build": "tsup && node scripts/mkjson.mjs dist/cjs dist/esm && tsup --dts-only --outDir dist",
|
||||
"publish": "npm run build && npm publish",
|
||||
"pretty": "prettier --write ."
|
||||
},
|
||||
"keywords": [
|
||||
"sern-handler",
|
||||
"sern",
|
||||
"handler",
|
||||
"sern handler",
|
||||
"wrapper",
|
||||
"discord.js",
|
||||
"framework"
|
||||
],
|
||||
"author": "SernDevs",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"iti": "^0.4.2",
|
||||
"rxjs": "^7.5.6",
|
||||
"ts-pattern": "^4.0.2",
|
||||
"ts-results-es": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.35.1",
|
||||
"@typescript-eslint/parser": "5.35.1",
|
||||
"eslint": "8.22.0",
|
||||
"prettier": "2.7.1",
|
||||
"tsup": "^6.1.3",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"discord.js": "^14.2.x"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sern-handler/handler.git"
|
||||
},
|
||||
"homepage": "https://sern-handler.js.org"
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"major": {
|
||||
"dependencyDashboardApproval": true,
|
||||
"reviewers": ["EvolutionX-10", "jacoobes", "Murtatrxx"]
|
||||
},
|
||||
"minor": {
|
||||
"reviewers": ["jacoobes", "Murtatrxx"]
|
||||
},
|
||||
"schedule": ["every weekend"],
|
||||
"lockFileMaintenance": {
|
||||
"enabled": true,
|
||||
"automerge": false
|
||||
}
|
||||
"major": {
|
||||
"dependencyDashboardApproval": true,
|
||||
"reviewers": ["EvolutionX-10", "jacoobes", "Murtatrxx"]
|
||||
},
|
||||
"minor": {
|
||||
"reviewers": ["jacoobes", "Murtatrxx"]
|
||||
},
|
||||
"schedule": ["every weekend"],
|
||||
"lockFileMaintenance": {
|
||||
"enabled": true,
|
||||
"automerge": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
// A quick script to regenerate package.jsons for each cjs and esm after tsup cleans distributions
|
||||
const locations = process.argv;
|
||||
locations.shift();
|
||||
locations.shift();
|
||||
for(const loc of locations) {
|
||||
if(loc.endsWith('cjs')) {
|
||||
await writeFile(join(loc, 'package.json'), JSON.stringify({ type : 'commonjs' }))
|
||||
for (const loc of locations) {
|
||||
if (loc.endsWith('cjs')) {
|
||||
await writeFile(join(loc, 'package.json'), JSON.stringify({ type: 'commonjs' }));
|
||||
} else {
|
||||
await writeFile(join(loc, 'package.json'), JSON.stringify({ type : 'module' }))
|
||||
await writeFile(join(loc, 'package.json'), JSON.stringify({ type: 'module' }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
13
src/handler/contracts/logging.ts
Normal file
13
src/handler/contracts/logging.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { SernEventsMapping } from '../../types/handler';
|
||||
import type { ScopedPlugin } from '../../types/handler';
|
||||
|
||||
export interface Logging extends ScopedPlugin {
|
||||
error(...payload: SernEventsMapping['error']): void;
|
||||
warning(...payload: SernEventsMapping['warning']): void;
|
||||
moduleActivate(...warning: SernEventsMapping['module.activate']): void;
|
||||
moduleRegister(...register: SernEventsMapping['module.register']): void;
|
||||
}
|
||||
|
||||
export interface LoggingConstructor {
|
||||
new (): Logging;
|
||||
}
|
||||
15
src/handler/contracts/moduleManager.ts
Normal file
15
src/handler/contracts/moduleManager.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type {
|
||||
CommandModuleDefs,
|
||||
} from '../../types/module';
|
||||
import type { CommandType } from '../structures/enums';
|
||||
import type { CommandModule } from '../../types/module';
|
||||
import type { ModuleStore } from '../structures/moduleStore';
|
||||
import type { ScopedPlugin } from '../../types/handler';
|
||||
|
||||
|
||||
export interface ModuleManager extends ScopedPlugin {
|
||||
readonly moduleStore : ModuleStore;
|
||||
getModule<T extends CommandType>(type: T, name: string) : CommandModuleDefs[T] | undefined
|
||||
setModule<T extends CommandType>(type : T, value: Required<CommandModule>) : void
|
||||
}
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
import type {
|
||||
BothCommand,
|
||||
ButtonCommand,
|
||||
ContextMenuMsg,
|
||||
ContextMenuUser,
|
||||
ModalSubmitCommand,
|
||||
SelectMenuCommand,
|
||||
SlashCommand,
|
||||
} from '../structures/module';
|
||||
import Context from '../structures/context';
|
||||
import type { SlashOptions } from '../../types/handler';
|
||||
import { asyncResolveArray } from '../utilities/asyncResolveArray';
|
||||
@@ -21,12 +12,20 @@ import type {
|
||||
UserContextMenuCommandInteraction,
|
||||
MessageContextMenuCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import { isAutocomplete } from '../utilities/predicates';
|
||||
import { SernError } from '../structures/errors';
|
||||
import treeSearch from '../utilities/treeSearch';
|
||||
import type {
|
||||
BothCommand,
|
||||
ButtonCommand,
|
||||
ContextMenuMsg,
|
||||
ContextMenuUser,
|
||||
ModalSubmitCommand,
|
||||
SelectMenuCommand,
|
||||
SlashCommand,
|
||||
} from '../../types/module';
|
||||
|
||||
export function applicationCommandDispatcher(interaction: Interaction) {
|
||||
if (isAutocomplete(interaction)) {
|
||||
if (interaction.isAutocomplete()) {
|
||||
return dispatchAutocomplete(interaction);
|
||||
} else {
|
||||
const ctx = Context.wrap(interaction as ChatInputCommandInteraction);
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import type { Interaction } from 'discord.js';
|
||||
import { concatMap, from, fromEvent, map, Observable } from 'rxjs';
|
||||
import { catchError, concatMap, from, fromEvent, map, Observable } from 'rxjs';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import { EventsHandler } from './eventsHandler';
|
||||
import {
|
||||
isApplicationCommand,
|
||||
isAutocomplete,
|
||||
isMessageComponent,
|
||||
isModalSubmit,
|
||||
} from '../utilities/predicates';
|
||||
import * as Files from '../utilities/readFile';
|
||||
import type { CommandModule } from '../structures/module';
|
||||
import { SernError } from '../structures/errors';
|
||||
import { CommandType } from '../structures/enums';
|
||||
import { CommandType, PayloadType } from '../structures/enums';
|
||||
import { match, P } from 'ts-pattern';
|
||||
import {
|
||||
applicationCommandDispatcher,
|
||||
@@ -29,6 +22,7 @@ import type {
|
||||
MessageContextMenuCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import { executeModule } from './observableHandling';
|
||||
import type { CommandModule } from '../../types/module';
|
||||
|
||||
export default class InteractionHandler extends EventsHandler<{
|
||||
event: Interaction;
|
||||
@@ -49,29 +43,26 @@ export default class InteractionHandler extends EventsHandler<{
|
||||
return from(eventPluginRes).pipe(map(res => ({ mod, res, execute })));
|
||||
}),
|
||||
concatMap(payload => executeModule(wrapper, payload)),
|
||||
)
|
||||
.subscribe({
|
||||
error: err => {
|
||||
catchError((err, caught) => {
|
||||
wrapper.sernEmitter?.emit('error', err);
|
||||
},
|
||||
});
|
||||
return caught;
|
||||
}),
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
override init() {
|
||||
this.discordEvent.subscribe({
|
||||
next: event => {
|
||||
if (isMessageComponent(event)) {
|
||||
const mod = Files.MessageCompCommands[event.componentType].get(
|
||||
event.customId,
|
||||
);
|
||||
if (event.isMessageComponent()) {
|
||||
const mod = Files.MessageCompCommands[event.componentType].get(event.customId);
|
||||
this.setState({ event, mod });
|
||||
} else if (isApplicationCommand(event) || isAutocomplete(event)) {
|
||||
} else if (event.isCommand() || event.isAutocomplete()) {
|
||||
const mod =
|
||||
Files.ApplicationCommands[event.commandType].get(
|
||||
event.commandName,
|
||||
) ?? Files.BothCommands.get(event.commandName);
|
||||
Files.ApplicationCommands[event.commandType].get(event.commandName) ??
|
||||
Files.BothCommands.get(event.commandName);
|
||||
this.setState({ event, mod });
|
||||
} else if (isModalSubmit(event)) {
|
||||
} else if (event.isModalSubmit()) {
|
||||
/**
|
||||
* maybe move modal submits into message component object maps?
|
||||
*/
|
||||
@@ -81,8 +72,8 @@ export default class InteractionHandler extends EventsHandler<{
|
||||
throw Error('This interaction is not supported yet');
|
||||
}
|
||||
},
|
||||
error: e => {
|
||||
this.wrapper.sernEmitter?.emit('error', e);
|
||||
error: reason => {
|
||||
this.wrapper.sernEmitter?.emit('error', { type: PayloadType.Failure, reason });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -106,10 +97,7 @@ export default class InteractionHandler extends EventsHandler<{
|
||||
{ type: CommandType.Modal },
|
||||
modalCommandDispatcher(event as ModalSubmitInteraction),
|
||||
)
|
||||
.with(
|
||||
{ type: CommandType.Button },
|
||||
buttonCommandDispatcher(event as ButtonInteraction),
|
||||
)
|
||||
.with({ type: CommandType.Button }, buttonCommandDispatcher(event as ButtonInteraction))
|
||||
.with(
|
||||
{ type: CommandType.MenuSelect },
|
||||
selectMenuCommandDispatcher(event as SelectMenuInteraction),
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { EventsHandler } from './eventsHandler';
|
||||
import { concatMap, from, fromEvent, map, Observable, of, switchMap } from 'rxjs';
|
||||
import { catchError, concatMap, from, fromEvent, map, Observable, of, switchMap } from 'rxjs';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import type { Message } from 'discord.js';
|
||||
import { executeModule, ignoreNonBot, isOneOfCorrectModules } from './observableHandling';
|
||||
import { fmt } from '../utilities/messageHelpers';
|
||||
import Context from '../structures/context';
|
||||
import * as Files from '../utilities/readFile';
|
||||
import type { TextCommand } from '../structures/module';
|
||||
import { CommandType } from '../structures/enums';
|
||||
import { CommandType, PayloadType } from '../structures/enums';
|
||||
import { asyncResolveArray } from '../utilities/asyncResolveArray';
|
||||
import { controller } from '../sern';
|
||||
import type { TextCommand } from '../../types/module';
|
||||
|
||||
export default class MessageHandler extends EventsHandler<{
|
||||
ctx: Context;
|
||||
@@ -36,12 +36,12 @@ export default class MessageHandler extends EventsHandler<{
|
||||
return from(res).pipe(map(res => ({ mod, execute, res })));
|
||||
}),
|
||||
concatMap(payload => executeModule(wrapper, payload)),
|
||||
)
|
||||
.subscribe({
|
||||
error: err => {
|
||||
catchError((err, caught) => {
|
||||
wrapper.sernEmitter?.emit('error', err);
|
||||
},
|
||||
});
|
||||
return caught;
|
||||
}),
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
protected init(): void {
|
||||
@@ -61,16 +61,17 @@ export default class MessageHandler extends EventsHandler<{
|
||||
Files.TextCommands.aliases.get(prefix),
|
||||
};
|
||||
}),
|
||||
concatMap(element => {
|
||||
return of(element.mod).pipe(
|
||||
concatMap(element =>
|
||||
of(element.mod).pipe(
|
||||
isOneOfCorrectModules(CommandType.Text),
|
||||
map(mod => ({ ...element, mod })),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
.subscribe({
|
||||
next: value => this.setState(value),
|
||||
error: err => this.wrapper.sernEmitter?.emit('error', err),
|
||||
error: reason =>
|
||||
this.wrapper.sernEmitter?.emit('error', { type: PayloadType.Failure, reason }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type { Message } from 'discord.js';
|
||||
import { from, Observable, of, tap, throwError } from 'rxjs';
|
||||
import { concatMap, from, Observable, of, tap, throwError } from 'rxjs';
|
||||
import { SernError } from '../structures/errors';
|
||||
import type { Module, CommandModuleDefs, CommandModule } from '../structures/module';
|
||||
import type { Result } from 'ts-results-es';
|
||||
import { Result } from 'ts-results-es';
|
||||
import type { CommandType } from '../structures/enums';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import { PayloadType } from '../structures/enums';
|
||||
|
||||
import type { CommandModule, CommandModuleDefs, Module } from '../../types/module';
|
||||
|
||||
export function ignoreNonBot(prefix: string) {
|
||||
return (src: Observable<Message>) =>
|
||||
@@ -80,12 +79,26 @@ export function executeModule(
|
||||
},
|
||||
) {
|
||||
if (payload.res.every(el => el.ok)) {
|
||||
return from(Promise.resolve(payload.execute())).pipe(
|
||||
tap(() => {
|
||||
wrapper.sernEmitter?.emit('module.activate', {
|
||||
type: PayloadType.Success,
|
||||
module: payload.mod,
|
||||
});
|
||||
const executeFn = Result.wrapAsync<unknown, Error | string>(() =>
|
||||
Promise.resolve(payload.execute()),
|
||||
);
|
||||
return from(executeFn).pipe(
|
||||
concatMap(res => {
|
||||
if (res.err) {
|
||||
return throwError(() => ({
|
||||
type: PayloadType.Failure,
|
||||
reason: res.val,
|
||||
module: payload.mod,
|
||||
}));
|
||||
}
|
||||
return of(res.val).pipe(
|
||||
tap(() =>
|
||||
wrapper.sernEmitter?.emit('module.activate', {
|
||||
type: PayloadType.Success,
|
||||
module: payload.mod,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
@@ -94,6 +107,6 @@ export function executeModule(
|
||||
module: payload.mod,
|
||||
reason: SernError.PluginFailure,
|
||||
});
|
||||
return of(null);
|
||||
return of(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { EventsHandler } from './eventsHandler';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import { concatMap, fromEvent, Observable, map, take, of, from, toArray, switchMap } from 'rxjs';
|
||||
import type { CommandModule } from '../structures/module';
|
||||
import * as Files from '../utilities/readFile';
|
||||
import { errTap } from './observableHandling';
|
||||
import type { DefinedCommandModule } from '../../types/handler';
|
||||
import { basename } from 'path';
|
||||
import { CommandType, PayloadType, PluginType } from '../structures/enums';
|
||||
import { processCommandPlugins } from './userDefinedEventsHandling';
|
||||
@@ -13,6 +11,8 @@ import { SernError } from '../structures/errors';
|
||||
import { match } from 'ts-pattern';
|
||||
import { type Result, Err, Ok } from 'ts-results-es';
|
||||
import { ApplicationCommandType, ComponentType } from 'discord.js';
|
||||
import type { CommandModule } from '../../types/module';
|
||||
import type { DefinedCommandModule } from '../../types/handler';
|
||||
|
||||
export default class ReadyHandler extends EventsHandler<{
|
||||
mod: DefinedCommandModule;
|
||||
|
||||
@@ -8,13 +8,13 @@ import type {
|
||||
EventInput,
|
||||
SpreadParams,
|
||||
} from '../../types/handler';
|
||||
import type { EventModule } from '../structures/module';
|
||||
import { PayloadType } from '../structures/enums';
|
||||
import type Wrapper from '../structures/wrapper';
|
||||
import { basename } from 'path';
|
||||
import { match } from 'ts-pattern';
|
||||
import { isDiscordEvent, isSernEvent } from '../utilities/predicates';
|
||||
import { errTap } from './observableHandling';
|
||||
import type { EventModule } from '../../types/module';
|
||||
|
||||
/**
|
||||
* Utility function to process command plugins for all Modules
|
||||
|
||||
@@ -15,7 +15,7 @@ import type { AutocompleteInteraction, Awaitable, Client, ClientEvents } from 'd
|
||||
import type { Result, Ok, Err } from 'ts-results-es';
|
||||
import type { CommandType, DefinitelyDefined, Override, SernEventsMapping } from '../../index';
|
||||
import { EventType, PluginType } from '../../index';
|
||||
import type { BaseModule, CommandModuleDefs, EventModuleDefs } from '../structures/module';
|
||||
import type { BaseModule, CommandModuleDefs, EventModuleDefs } from '../../types/module';
|
||||
import type { EventEmitter } from 'events';
|
||||
import type {
|
||||
DiscordEventCommand,
|
||||
|
||||
@@ -3,8 +3,7 @@ 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 { CommandType, EventType, PluginType } from './structures/enums';
|
||||
import type {
|
||||
CommandPlugin,
|
||||
EventModuleCommandPluginDefs,
|
||||
@@ -17,6 +16,10 @@ import { SernError } from './structures/errors';
|
||||
import InteractionHandler from './events/interactionHandler';
|
||||
import ReadyHandler from './events/readyHandler';
|
||||
import MessageHandler from './events/messageHandler';
|
||||
import type { CommandModule, EventModule } from '../types/module';
|
||||
import type { ModuleStore } from './structures/moduleStore';
|
||||
import type { Client } from 'discord.js';
|
||||
import type { ModuleConfig, ModuleManagerConstructor } from './contracts/moduleManager';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -119,3 +122,10 @@ export function eventModule(mod: InputEventModule): EventModule {
|
||||
plugins,
|
||||
} as EventModule;
|
||||
}
|
||||
|
||||
export function ModuleConfiguration<T extends ModuleStore>(
|
||||
moduleManager : ModuleManagerConstructor<T>,
|
||||
moduleStore: T,
|
||||
) : ModuleConfig<T> {
|
||||
return ( client: Client ) => new moduleManager(client, moduleStore);
|
||||
}
|
||||
5
src/handler/structures/defaultModuleManager.ts
Normal file
5
src/handler/structures/defaultModuleManager.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import ModuleManager from '../contracts/moduleManager';
|
||||
import type { CommandModule, CommandModuleDefs } from '../../types/module';
|
||||
import type { CommandType } from './enums';
|
||||
import { ModuleStore } from './moduleStore';
|
||||
import { Logging, LoggingConstructor } from '../contracts/logging';
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Override, SernEventsMapping } from '../../types/handler';
|
||||
import type { BaseModule } from './module';
|
||||
import type {
|
||||
DiscordEmitterPlugin,
|
||||
DiscordEventPlugin,
|
||||
@@ -10,6 +9,7 @@ import type {
|
||||
} from '../plugins/plugin';
|
||||
import type { Awaitable, ClientEvents } from 'discord.js';
|
||||
import type { EventType } from './enums';
|
||||
import type { BaseModule } from '../../types/module';
|
||||
|
||||
/*
|
||||
* Mapped type to generate all sern event modules
|
||||
|
||||
72
src/handler/structures/moduleStore.ts
Normal file
72
src/handler/structures/moduleStore.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type { CommandModule } from '../../types/module';
|
||||
import { ApplicationCommandOptionType, ApplicationCommandType, ComponentType, InteractionType } from 'discord.js';
|
||||
import type { EventEmitter } from 'events';
|
||||
import { CommandType } from './enums.js';
|
||||
import { match } from 'ts-pattern';
|
||||
import constFn from '../utilities/constantFunction.js';
|
||||
|
||||
/**
|
||||
* Would be a little overkill for a class just for the event emitters?
|
||||
*/
|
||||
export const ExternalEventEmitters = new Map<string, EventEmitter>();
|
||||
/**
|
||||
* Storing all command modules
|
||||
*/
|
||||
export class ModuleStore {
|
||||
protected readonly BothCommands = new Map<string, CommandModule>();
|
||||
protected readonly ApplicationCommands = {
|
||||
[ApplicationCommandType.User]: new Map<string, CommandModule>(),
|
||||
[ApplicationCommandType.Message]: new Map<string, CommandModule>(),
|
||||
[ApplicationCommandType.ChatInput]: new Map<string, CommandModule>(),
|
||||
};
|
||||
|
||||
protected readonly InteractionHandlers = {
|
||||
[ComponentType.Button]: new Map<string, CommandModule>(),
|
||||
[ComponentType.SelectMenu]: new Map<string, CommandModule>(),
|
||||
[InteractionType.ModalSubmit] : new Map<string, CommandModule>()
|
||||
};
|
||||
protected readonly TextCommands = {
|
||||
text: new Map<string, CommandModule>(),
|
||||
aliases: new Map<string, CommandModule>(),
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appType
|
||||
* Resolves the current map with an ApplicationCommandType
|
||||
*/
|
||||
resolveApplicationCommandMap(appType: ApplicationCommandType) {
|
||||
return this.ApplicationCommands[appType];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mapping
|
||||
* Resolves the handler by given component type, or if the type of interaction is a modal submit
|
||||
*/
|
||||
resolveInteractionHandlersMap(mapping: ComponentType.Button | ComponentType.SelectMenu | InteractionType.ModalSubmit) {
|
||||
return this.InteractionHandlers[mapping];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* Resolves the map with a CommandType
|
||||
*/
|
||||
resolveMap<T extends CommandType>(type: T) {
|
||||
return match(type as CommandType)
|
||||
.with(CommandType.Text, constFn(this.TextCommands.text))
|
||||
.with(CommandType.Modal, constFn(this.InteractionHandlers[InteractionType.ModalSubmit]))
|
||||
.with(CommandType.Button, constFn(this.InteractionHandlers[ComponentType.Button]))
|
||||
.with(CommandType.MenuSelect, constFn(this.InteractionHandlers[ComponentType.SelectMenu]))
|
||||
.with(CommandType.Both, constFn(this.BothCommands))
|
||||
.with(CommandType.MenuMsg, constFn(this.ApplicationCommands[ApplicationCommandType.Message]))
|
||||
.with(CommandType.MenuUser, constFn(this.ApplicationCommands[ApplicationCommandType.User]))
|
||||
.with(CommandType.Slash, constFn(this.ApplicationCommands[ApplicationCommandType.ChatInput]))
|
||||
.otherwise(() => {
|
||||
throw Error('Cannot find a map under this type');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,8 @@
|
||||
import Context from './context';
|
||||
import type {
|
||||
BothCommand,
|
||||
Module,
|
||||
SlashCommand,
|
||||
TextCommand,
|
||||
SernOptionsData,
|
||||
BaseOptions,
|
||||
SernAutocompleteData,
|
||||
SernSubCommandData,
|
||||
SernSubCommandGroupData,
|
||||
} from './module';
|
||||
import type Wrapper from './wrapper';
|
||||
|
||||
export * from './enums';
|
||||
export {
|
||||
Context,
|
||||
SlashCommand,
|
||||
TextCommand,
|
||||
BothCommand,
|
||||
Module,
|
||||
Wrapper,
|
||||
SernOptionsData,
|
||||
BaseOptions,
|
||||
SernAutocompleteData,
|
||||
SernSubCommandData,
|
||||
SernSubCommandGroupData,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import type { Client } from 'discord.js';
|
||||
import type SernEmitter from '../sernEmitter';
|
||||
import type { EventModule } from './module';
|
||||
import type { EventModule } from '../../types/module';
|
||||
import type { NodeApi } from 'iti';
|
||||
|
||||
/**
|
||||
* An object to be passed into Sern#init() function.
|
||||
* @typedef {object} Wrapper
|
||||
*/
|
||||
interface Wrapper {
|
||||
//@deprecrated Use Wrapper#addDependencies instead.
|
||||
readonly client: Client;
|
||||
readonly sernEmitter?: SernEmitter;
|
||||
readonly defaultPrefix?: string;
|
||||
@@ -15,6 +17,7 @@ interface Wrapper {
|
||||
| string
|
||||
| { mod: EventModule; absPath: string }[]
|
||||
| (() => { mod: EventModule; absPath: string }[]);
|
||||
readonly addDependencies: (rootBuilder: NodeApi<{}>) => void
|
||||
}
|
||||
|
||||
export default Wrapper;
|
||||
|
||||
3
src/handler/utilities/constantFunction.ts
Normal file
3
src/handler/utilities/constantFunction.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default <T>(value: T) =>
|
||||
() =>
|
||||
value;
|
||||
@@ -1,21 +1,9 @@
|
||||
import type { CommandModuleDefs, EventModule, Module } from '../structures/module';
|
||||
import {
|
||||
AutocompleteInteraction,
|
||||
Interaction,
|
||||
InteractionType,
|
||||
type ModalSubmitInteraction,
|
||||
type ButtonInteraction,
|
||||
type SelectMenuInteraction,
|
||||
type ChatInputCommandInteraction,
|
||||
type UserContextMenuCommandInteraction,
|
||||
type MessageContextMenuCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import type {
|
||||
DiscordEventCommand,
|
||||
ExternalEventCommand,
|
||||
SernEventCommand,
|
||||
} from '../structures/events';
|
||||
import { EventType } from '../..';
|
||||
import type { CommandModuleDefs, EventModule, Module } from '../../types/module';
|
||||
|
||||
export function correctModuleType<T extends keyof CommandModuleDefs>(
|
||||
plug: Module | undefined,
|
||||
@@ -26,26 +14,6 @@ export function correctModuleType<T extends keyof CommandModuleDefs>(
|
||||
return plug !== undefined && (plug.type & type) !== 0;
|
||||
}
|
||||
|
||||
export function isApplicationCommand(
|
||||
interaction: Interaction,
|
||||
): interaction is
|
||||
| ChatInputCommandInteraction
|
||||
| UserContextMenuCommandInteraction
|
||||
| MessageContextMenuCommandInteraction {
|
||||
return interaction.type === InteractionType.ApplicationCommand;
|
||||
}
|
||||
|
||||
export function isModalSubmit(interaction: Interaction): interaction is ModalSubmitInteraction {
|
||||
return interaction.type === InteractionType.ModalSubmit;
|
||||
}
|
||||
export function isAutocomplete(interaction: Interaction): interaction is AutocompleteInteraction {
|
||||
return interaction.type === InteractionType.ApplicationCommandAutocomplete;
|
||||
}
|
||||
export function isMessageComponent(
|
||||
interaction: Interaction,
|
||||
): interaction is ButtonInteraction | SelectMenuInteraction {
|
||||
return interaction.type === InteractionType.MessageComponent;
|
||||
}
|
||||
|
||||
export function isDiscordEvent(el: EventModule): el is DiscordEventCommand {
|
||||
return el.type === EventType.Discord;
|
||||
@@ -54,17 +22,3 @@ export function isSernEvent(el: EventModule): el is SernEventCommand {
|
||||
return el.type === EventType.Sern;
|
||||
}
|
||||
|
||||
export function isExternalEvent(el: EventModule): el is ExternalEventCommand {
|
||||
return el.type === EventType.External && 'emitter' in el;
|
||||
}
|
||||
|
||||
// export function isEventPlugin<T extends CommandType>(
|
||||
// e: CommandModulePlugin<T>,
|
||||
// ): e is EventPlugin<T> {
|
||||
// return e.type === PluginType.Event;
|
||||
// }
|
||||
// export function isCommandPlugin<T extends CommandType>(
|
||||
// e: CommandModulePlugin<T>,
|
||||
// ): e is CommandPlugin<T> {
|
||||
// return !isEventPlugin(e);
|
||||
// }
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ApplicationCommandType, ComponentType } from 'discord.js';
|
||||
import { readdirSync, statSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { type Observable, from, concatAll } from 'rxjs';
|
||||
import type { CommandModule } from '../structures/module';
|
||||
import { type Observable, from, concatAll } from 'rxjs';
|
||||
import { SernError } from '../structures/errors';
|
||||
import { type Result, Err, Ok } from 'ts-results-es';
|
||||
import type { EventEmitter } from 'events';
|
||||
import type { CommandModule } from '../../types/module';
|
||||
|
||||
//Maybe move this? this probably doesnt belong in utlities/
|
||||
export const BothCommands = new Map<string, CommandModule>();
|
||||
@@ -63,19 +63,22 @@ export function buildData<T>(commandDir: string): Observable<
|
||||
>
|
||||
> {
|
||||
const commands = getCommands(commandDir);
|
||||
return from(Promise.all(commands.map(async absPath => {
|
||||
let mod : T | undefined;
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
mod = require(absPath).default;
|
||||
} catch {
|
||||
mod = (await import(`file:///` +absPath)).default;
|
||||
}
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule);
|
||||
})
|
||||
)).pipe(concatAll());
|
||||
return from(
|
||||
Promise.all(
|
||||
commands.map(async absPath => {
|
||||
let mod: T | undefined;
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
mod = require(absPath).default;
|
||||
} catch {
|
||||
mod = (await import(`file:///` + absPath)).default;
|
||||
}
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule);
|
||||
}),
|
||||
),
|
||||
).pipe(concatAll());
|
||||
}
|
||||
|
||||
export function getCommands(dir: string): string[] {
|
||||
|
||||
@@ -1,31 +1,40 @@
|
||||
import type { SernOptionsData } from '../structures/module';
|
||||
import type { SernOptionsData } from '../../types/module';
|
||||
import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js';
|
||||
|
||||
export default function treeSearch(iAutocomplete: AutocompleteInteraction, options: SernOptionsData[] | undefined) {
|
||||
if(options === undefined) return undefined;
|
||||
export default function treeSearch(
|
||||
iAutocomplete: AutocompleteInteraction,
|
||||
options: SernOptionsData[] | undefined,
|
||||
) {
|
||||
if (options === undefined) return undefined;
|
||||
const _options = options.slice(); // required to prevent direct mutation of options
|
||||
while ( _options.length > 0 ) {
|
||||
while (_options.length > 0) {
|
||||
const cur = _options.pop()!;
|
||||
switch ( cur.type ) {
|
||||
case ApplicationCommandOptionType.Subcommand : {
|
||||
for ( const option of cur.options ?? [] ) {
|
||||
_options.push(option);
|
||||
}
|
||||
} break;
|
||||
case ApplicationCommandOptionType.SubcommandGroup : {
|
||||
for (const command of cur.options ?? []) {
|
||||
_options.push(command);
|
||||
}
|
||||
} break;
|
||||
default : {
|
||||
if(cur.autocomplete) {
|
||||
const choice = iAutocomplete.options.getFocused(true);
|
||||
if(cur.name === choice.name && cur.autocomplete) {
|
||||
return cur;
|
||||
switch (cur.type) {
|
||||
case ApplicationCommandOptionType.Subcommand:
|
||||
{
|
||||
for (const option of cur.options ?? []) {
|
||||
_options.push(option);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
case ApplicationCommandOptionType.SubcommandGroup:
|
||||
{
|
||||
for (const command of cur.options ?? []) {
|
||||
_options.push(command);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (cur.autocomplete) {
|
||||
const choice = iAutocomplete.options.getFocused(true);
|
||||
if (cur.name === choice.name && cur.autocomplete) {
|
||||
return cur;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import SernEmitter from './handler/sernEmitter';
|
||||
export { eventModule, commandModule } from './handler/sern';
|
||||
export * as Sern from './handler/sern';
|
||||
export * from './types/handler';
|
||||
export * from './types/module';
|
||||
export * from './handler/structures/structxports';
|
||||
export * from './handler/plugins/plugin';
|
||||
export { SernEmitter };
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { CommandInteractionOptionResolver } from 'discord.js';
|
||||
import type { CommandModule, EventModule, Module } from '../handler/structures/module';
|
||||
import type { PayloadType } from '../handler/structures/enums';
|
||||
import type { CommandModule, EventModule, Module } from './module';
|
||||
import type { Logging } from '../handler/contracts/logging';
|
||||
import type { Database } from '../handler/contracts/database';
|
||||
import type { ModuleManager } from '../handler/contracts/moduleManager';
|
||||
export type Nullish<T> = T | undefined | null;
|
||||
|
||||
// Thanks to @kelsny
|
||||
@@ -26,11 +29,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
|
||||
@@ -44,15 +42,26 @@ export type SpreadParams<T extends (...args: never) => unknown> = (
|
||||
* After modules are transformed, name and description are given default values if none
|
||||
* are provided to Module. This type represents that transformation
|
||||
*/
|
||||
export type DefinedModule = DefinitelyDefined<Module, 'name' | 'description'>;
|
||||
export type DefinedCommandModule = DefinitelyDefined<CommandModule, 'name' | 'description'>;
|
||||
export type DefinedEventModule = DefinitelyDefined<EventModule, 'name' | 'description'>;
|
||||
export type Payload =
|
||||
| { type: PayloadType.Success; module: Module }
|
||||
| { type: PayloadType.Failure; module: Module | undefined; reason: string | Error };
|
||||
| { type: PayloadType.Failure; module?: Module; reason: string | Error };
|
||||
export type SernEventsMapping = {
|
||||
['module.register']: [Payload];
|
||||
['module.activate']: [Payload];
|
||||
['error']: [Error | string];
|
||||
['error']: [Payload];
|
||||
['warning']: [string];
|
||||
};
|
||||
|
||||
|
||||
export interface ScopedPlugin {
|
||||
init (dependencies: Map<string, ScopedPlugin>) : void
|
||||
}
|
||||
|
||||
type DependencyMap = {
|
||||
logger : Logging;
|
||||
db : Database;
|
||||
//errorHandling: '';
|
||||
moduleManager : ModuleManager;
|
||||
}
|
||||
@@ -17,17 +17,21 @@ import type {
|
||||
SelectMenuInteraction,
|
||||
UserContextMenuCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import type { Args, Override, SlashOptions } from '../../types/handler';
|
||||
import type { AutocompletePlugin, CommandPlugin, EventPlugin } from '../plugins/plugin';
|
||||
import type Context from './context';
|
||||
import { CommandType, EventType, PluginType } from './enums';
|
||||
import type { DiscordEventCommand, ExternalEventCommand, SernEventCommand } from './events';
|
||||
import type {
|
||||
DiscordEventCommand,
|
||||
ExternalEventCommand,
|
||||
SernEventCommand,
|
||||
} from '../handler/structures/events';
|
||||
import { CommandType } from '../handler/structures/enums';
|
||||
import type { Args, Override, SlashOptions } from './handler';
|
||||
import type Context from '../handler/structures/context';
|
||||
import type { AutocompletePlugin, CommandPlugin, EventPlugin } from '../handler/plugins/plugin';
|
||||
import { EventType } from '../handler/structures/enums';
|
||||
|
||||
export interface BaseModule {
|
||||
type: CommandType | PluginType;
|
||||
type: CommandType;
|
||||
name?: string;
|
||||
description?: string;
|
||||
execute: (ctx: Context, args: Args) => Awaitable<void | unknown>;
|
||||
}
|
||||
|
||||
export type TextCommand = Override<
|
||||
@@ -159,9 +163,6 @@ export type EventModuleDefs = {
|
||||
[EventType.External]: ExternalEventCommand;
|
||||
};
|
||||
|
||||
//TODO: support deeply nested Autocomplete
|
||||
// objective: construct union of ApplicationCommandOptionData change any Autocomplete data
|
||||
// into Sern autocomplete data.
|
||||
|
||||
export type SernAutocompleteData = Override<
|
||||
BaseApplicationCommandOptionsData,
|
||||
@@ -207,4 +208,4 @@ export type SernOptionsData<U extends ApplicationCommandOptionData = Application
|
||||
? SernSubCommandData
|
||||
: U extends ApplicationCommandSubGroupData
|
||||
? SernSubCommandGroupData
|
||||
: BaseOptions;
|
||||
: BaseOptions;
|
||||
@@ -1,17 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"importsNotUsedAsValues": "error",
|
||||
"moduleResolution": "node",
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
},
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"include": ["src"],
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"experimentalDecorators": true,
|
||||
"strictNullChecks": true,
|
||||
"importsNotUsedAsValues": "error",
|
||||
"moduleResolution": "node",
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"outDir": "dist/cjs",
|
||||
"target": "esnext"
|
||||
}
|
||||
}
|
||||
"extends": "./tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"outDir": "dist/cjs",
|
||||
"target": "esnext"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm",
|
||||
"target": "esnext"
|
||||
}
|
||||
}
|
||||
"extends": "./tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm",
|
||||
"target": "esnext"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,36 +3,36 @@ import { defineConfig } from 'tsup';
|
||||
export default defineConfig([
|
||||
{
|
||||
entry: ['src/index.ts'],
|
||||
format : 'esm',
|
||||
format: 'esm',
|
||||
sourcemap: false,
|
||||
target: 'node16',
|
||||
tsconfig : './tsconfig-esm.json',
|
||||
outDir : './dist/esm',
|
||||
tsconfig: './tsconfig-esm.json',
|
||||
outDir: './dist/esm',
|
||||
platform: 'node',
|
||||
external: ['discord.js'],
|
||||
clean: true,
|
||||
treeshake: true,
|
||||
outExtension() {
|
||||
return {
|
||||
js : '.mjs'
|
||||
js: '.mjs',
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
entry: ['src/index.ts'],
|
||||
format : 'cjs',
|
||||
format: 'cjs',
|
||||
splitting: false,
|
||||
sourcemap: false,
|
||||
external: ['discord.js'],
|
||||
clean: true,
|
||||
target: 'node16',
|
||||
tsconfig : './tsconfig-cjs.json',
|
||||
outDir : './dist/cjs',
|
||||
tsconfig: './tsconfig-cjs.json',
|
||||
outDir: './dist/cjs',
|
||||
platform: 'node',
|
||||
outExtension() {
|
||||
return {
|
||||
js : '.cjs'
|
||||
js: '.cjs',
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user