From c07d87566a9b834a8d39b5dc2c353a27b296fa26 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 22:13:27 +0300 Subject: [PATCH] Improvements in Readme.md --- .prettierrc | 10 +++++----- README.md | 25 +++++++++++++++++++++---- src/handler/Utilities/readFile.ts | 27 +++++++++++++++------------ src/handler/logger.ts | 21 +++++++++------------ src/handler/sern.ts | 30 +++++++++++++++--------------- 5 files changed, 65 insertions(+), 48 deletions(-) diff --git a/.prettierrc b/.prettierrc index ba93fc7..3203c2e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { - "semi": true, - "trailingComma": "all", - "singleQuote": true, - "printWidth": 120, - "tabWidth": 2 + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 120, + "tabWidth": 2 } \ No newline at end of file diff --git a/README.md b/README.md index 922f65b..9b339e0 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,28 @@ npm install sern-handler yarn add sern-handler ``` -# Documentation +# Basic Usage -- 📑 [Documentation](https://sernhandler.js.org) +```js + import { Sern, PayloadOptions } from 'sern-handler'; + + const payload = new PayloadOptions({ + commands: '/commands', // Folder where all commands are located (subfolders supported). + events: '/events' // Events folder directory (subfolders supported). + owners: ['182326315813306369'], // Array of Discord ID(s). + prefix: '/', // Prefix for your bot (if no provied then it will use /). + client // The instance of Discord#Client(). + }); + + const handler = new Sern(payload); // Create a new instance of Sern with payloads. +``` + +# Links + +- 📑 [Official Documentation](https://sernhandler.js.org) +- 🎧 [Discord Server](https://discord.gg/QWQWQWQ) # Contribute -- Pull up on issues and tell me if there are bugs -- Check issues +- Pull up on issues and tell me if there are bugs. +- Check issues. - Any contributions are open to suggestion! diff --git a/src/handler/Utilities/readFile.ts b/src/handler/Utilities/readFile.ts index f5b168b..9a6917f 100644 --- a/src/handler/Utilities/readFile.ts +++ b/src/handler/Utilities/readFile.ts @@ -1,4 +1,6 @@ -import type { ApplicationCommandOptionData } from 'discord.js'; +import type { + ApplicationCommandOptionData +} from 'discord.js'; import { readdirSync, @@ -6,8 +8,8 @@ import { } from 'fs'; import { - basename, - join + basename, + join } from 'path'; import type * as Sern from '../sern'; @@ -16,6 +18,7 @@ export type CommandVal = { mod: Sern.Module, options: ApplicationCommandOptionData[], } + export const Commands = new Map(); export const Alias = new Map(); @@ -25,7 +28,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise n.substring(0, n.length - 3); export async function buildData(handler: Sern.Handler) : Promise<{ - name: string; - mod: Sern.Module; - absPath: string; + name: string; + mod: Sern.Module; + absPath: string; }[]> { const commandDir = handler.commandDir; - return Promise.all((await getCommands(commandDir)) - .map(async absPath => { - return { name: basename(absPath), mod: (await import(absPath)).default as Sern.Module, absPath } - })) + return Promise.all((await getCommands(commandDir)) + .map(async absPath => { + return { name: basename(absPath), mod: (await import(absPath)).default as Sern.Module, absPath } + })); } export async function getCommands(dir: string): Promise { - return readPath(join(process.cwd(), dir)) + return readPath(join(process.cwd(), dir)); } diff --git a/src/handler/logger.ts b/src/handler/logger.ts index 9b1a959..7953264 100644 --- a/src/handler/logger.ts +++ b/src/handler/logger.ts @@ -1,16 +1,13 @@ - enum sEvent { - GLOBAL_SLASH, - LOCAL_SLASH, - TEXT_CMD, - CRASH, - DM, - + TEXT_CMD, + GLOBAL_SLASH, + LOCAL_SLASH, + DM, + CRASH, } class Logger { - - public log(e : T, message: string) { - console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`) - } -} \ No newline at end of file + public log(e : T, message: string) { + console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`); + } +} diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 706d97e..bc7a977 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -2,18 +2,18 @@ import * as Files from './Utilities/readFile'; import type * as Utils from './Utilities/Preprocessors/args'; import type { - Arg, - Context, - Visibility, - possibleOutput + Arg, + Context, + Visibility, + possibleOutput } from '../Types/Handler'; import type { - ApplicationCommandOptionData, - Awaitable, - Client, - CommandInteraction, - Message + ApplicationCommandOptionData, + Awaitable, + Client, + CommandInteraction, + Message } from 'discord.js'; import { Ok, Result, None, Some } from 'ts-results'; @@ -116,9 +116,9 @@ export class Handler { const checkIsTestServer = this.privateServers.find(({ id }) => id === message.guildId!)?.test; if (checkIsTestServer === undefined) return 'This command has the private modifier but is not registered under Handler#privateServers'; if (checkIsTestServer !== module.mod.test) { - const msg = `This command is only available on test servers.`; // TODO: Customizable private message - - return msg; + const msg = `This command is only available on test servers.`; // TODO: Customizable private message + + return msg; } } const context = { @@ -152,7 +152,7 @@ export class Handler { Files.Commands.set(cmdName, { mod, options: options ?? [] }); switch (mod.visibility) { case 'private': { - // Loading guild slash commands only + // Reloading guild slash commands await this.reloadSlash(cmdName, mod.desc, options) } case 'public': { @@ -196,7 +196,7 @@ export class Handler { name: cmdName, description, options - }) + }); } } @@ -224,7 +224,7 @@ export class Handler { */ get client(): Client { - return this.wrapper.client + return this.wrapper.client; } /**