stlye: pretty please (#124)

Co-authored-by: EvolutionX-10 <EvolutionX-10@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2022-08-29 07:12:33 +05:30
committed by GitHub
parent 82637245f3
commit ff5c161469
14 changed files with 4926 additions and 4923 deletions

View File

@@ -3,9 +3,9 @@
"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
}
}
}

View File

@@ -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"
}

9508
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,54 +1,54 @@
{
"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.35.1",
"@typescript-eslint/parser": "5.35.1",
"eslint": "8.23.0",
"prettier": "2.7.1",
"tsup": "^6.1.3",
"typescript": "4.8.2"
},
"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.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.35.1",
"@typescript-eslint/parser": "5.35.1",
"eslint": "8.23.0",
"prettier": "2.7.1",
"tsup": "^6.1.3",
"typescript": "4.8.2"
},
"peerDependencies": {
"discord.js": "^14.2.x"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sern-handler/handler.git"
},
"homepage": "https://sern-handler.js.org"
}

View File

@@ -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
}
}

View File

@@ -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' }));
}
}

View File

@@ -61,15 +61,12 @@ export default class InteractionHandler extends EventsHandler<{
this.discordEvent.subscribe({
next: event => {
if (isMessageComponent(event)) {
const mod = Files.MessageCompCommands[event.componentType].get(
event.customId,
);
const mod = Files.MessageCompCommands[event.componentType].get(event.customId);
this.setState({ event, mod });
} else if (isApplicationCommand(event) || isAutocomplete(event)) {
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)) {
/**
@@ -106,10 +103,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),

View File

@@ -7,7 +7,6 @@ import type { CommandType } from '../structures/enums';
import type Wrapper from '../structures/wrapper';
import { PayloadType } from '../structures/enums';
export function ignoreNonBot(prefix: string) {
return (src: Observable<Message>) =>
new Observable<Message>(subscriber => {

View File

@@ -1,7 +1,7 @@
import { ApplicationCommandType, ComponentType } from 'discord.js';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
import { type Observable, from, concatAll } from 'rxjs';
import { type Observable, from, concatAll } from 'rxjs';
import type { CommandModule } from '../structures/module';
import { SernError } from '../structures/errors';
import { type Result, Err, Ok } from 'ts-results-es';
@@ -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[] {

View File

@@ -1,31 +1,40 @@
import type { SernOptionsData } from '../structures/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;
}
}
}
}

View File

@@ -1,17 +1,17 @@
{
"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,
"strictNullChecks": true,
"importsNotUsedAsValues": "error",
"moduleResolution": "node",
"skipLibCheck": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules", "dist"],
"include": ["src"]
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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',
};
}
}
},
},
]);