From dfb34b99e325c98dbf0f701ba0fb51c39e175eaa Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 01:17:33 -0600 Subject: [PATCH 1/7] testing cmds now have module prop, not on filename --- src/handler/sern.ts | 13 +++++++------ src/handler/utils/readFile.ts | 8 +------- src/types/handler.ts | 1 + 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/handler/sern.ts b/src/handler/sern.ts index eda48a4..c1551dd 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -64,7 +64,7 @@ export class Handler { const cmdResult = (await this.commandResult(module, message, tryFmt.join(' '))) if (cmdResult === undefined) return; - message.channel.send(cmdResult) + message.channel.send(cmdResult); }) @@ -116,7 +116,7 @@ export class Handler { if (module.mod.visibility === 'private') { 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.testOnly) { + if (checkIsTestServer !== module.mod.test) { const msg = `This command is only available on test servers.`; // TODO: Customizable private message return msg; @@ -144,13 +144,13 @@ export class Handler { }[] ) { for await (const { name, mod, absPath } of modArr) { - const { cmdName, testOnly } = Files.fmtFileName(name); + const cmdName = Files.fmtFileName(name); switch (mod.type) { - case 1: Files.Commands.set(cmdName, { mod, options: [], testOnly }); break; + case 1: Files.Commands.set(cmdName, { mod, options: [] }); break; case 2: case (1 | 2): { const options = ((await import(absPath)).options as ApplicationCommandOptionData[]) - Files.Commands.set(cmdName, { mod, options: options ?? [], testOnly }); + Files.Commands.set(cmdName, { mod, options: options ?? [] }); switch (mod.visibility) { case 'private': { // Loading guild slash commands only @@ -172,7 +172,7 @@ export class Handler { if (mod.alias.length > 0) { for (const alias of mod.alias) { - Files.Alias.set(alias, { mod, options: [], testOnly }) + Files.Alias.set(alias, { mod, options: [] }) } } } @@ -270,6 +270,7 @@ export interface Module { desc: string, visibility: Visibility, type: CommandType, + test : boolean, delegate: (eventParams: Context, args: Ok) => Awaitable | void> parse?: (ctx: Context, args: Arg) => Utils.ArgType } diff --git a/src/handler/utils/readFile.ts b/src/handler/utils/readFile.ts index fb8e611..7a5a468 100644 --- a/src/handler/utils/readFile.ts +++ b/src/handler/utils/readFile.ts @@ -15,7 +15,6 @@ import type * as Sern from '../sern'; export type CommandVal = { mod: Sern.Module, options: ApplicationCommandOptionData[], - testOnly: boolean } export const Commands = new Map(); export const Alias = new Map(); @@ -37,12 +36,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise { - const endsW = n.toLowerCase().endsWith('-test.js') || n.toLowerCase().endsWith('-test.ts'); - return endsW - ? { cmdName: n.substring(0, n.length - 8), testOnly: true } - : { cmdName: n.substring(0, n.length - 3), testOnly: false }; -}; +export const fmtFileName = (n: string) => n.substring(0, n.length - 3); /** * @param {Sern.Handler} handler an instance of Sern.Handler diff --git a/src/types/handler.ts b/src/types/handler.ts index 9bfa72f..7193500 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -27,6 +27,7 @@ export type Context = { message: Option, interaction: Option } +// `string` | `SlashOptions`, narrow down your type by checking `text` | `slash` export type Arg = ParseType<{text : string, slash : SlashOptions}> // TypeAlias for interaction.options From 2810ecafcaadce855dd048c2e8488dc7ab1de339 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 01:36:07 -0600 Subject: [PATCH 2/7] starting logger --- src/handler/logger.ts | 16 ++++++++++++++++ src/index.ts | 5 +++++ 2 files changed, 21 insertions(+) create mode 100644 src/handler/logger.ts diff --git a/src/handler/logger.ts b/src/handler/logger.ts new file mode 100644 index 0000000..f90be9d --- /dev/null +++ b/src/handler/logger.ts @@ -0,0 +1,16 @@ + + + +enum sEvent { + GLOBAL_SLASH, + LOCAL_SLASH, + TEXT_CMD, + CRASH, +} + +class Logger { + + public log(e : T, message: string) { + console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`) + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 78e789f..3a77436 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,3 +4,8 @@ import * as Types from './types/handler'; module.exports = { Sern, Utils, Types }; export { Sern, Utils, Types }; + + +function t () { + +} \ No newline at end of file From e0a2bee00943fc5ab4552324dbc7fb511974b1e0 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 01:42:11 -0600 Subject: [PATCH 3/7] oops removed random function --- src/handler/logger.ts | 4 ++-- src/index.ts | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/handler/logger.ts b/src/handler/logger.ts index f90be9d..9b1a959 100644 --- a/src/handler/logger.ts +++ b/src/handler/logger.ts @@ -1,11 +1,11 @@ - - enum sEvent { GLOBAL_SLASH, LOCAL_SLASH, TEXT_CMD, CRASH, + DM, + } class Logger { diff --git a/src/index.ts b/src/index.ts index 3a77436..78e789f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,3 @@ import * as Types from './types/handler'; module.exports = { Sern, Utils, Types }; export { Sern, Utils, Types }; - - -function t () { - -} \ No newline at end of file From 86c6647ecf137c50a2aa9b3be19c48ba8258b13b Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:29:03 +0300 Subject: [PATCH 4/7] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96e3f19..be8a725 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ -# Sern Handler +# Sern + +Sern is making easier to create & automate your discord bot with new version compatibility and full customization. + - A reincarnation of [this old project](https://github.com/jacoobes/sern_handler) # Links - 📑 [Documentation](https://sernhandler.js.org) -# Contributions +# Contribute - Pull up on issues and tell me if there are bugs - Check issues - Any contributions are open to suggestion! From 2889e92b2d497f4781f8ab2fb524baf4d5c4ed7f Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:40:05 +0300 Subject: [PATCH 5/7] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index be8a725..54198f1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,17 @@ Sern is making easier to create & automate your discord bot with new version com - A reincarnation of [this old project](https://github.com/jacoobes/sern_handler) -# Links +# Installation + +```sh +npm install sern-handler +``` + +```sh +npm install sern-handler +``` + +# Documentation - 📑 [Documentation](https://sernhandler.js.org) From 9870275635d881e6bed0116c0286c7edc81bdb38 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:46:58 +0300 Subject: [PATCH 6/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c1f58cd..0bbcbbf 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "sernhandler2", + "name": "sern-handler", "version": "1.0.0", "description": "", "main": "dist/index.js", From 6ce7649311f1d077f6437528cbad10da16e58435 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Sun, 13 Feb 2022 21:30:06 +0300 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54198f1..922f65b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ npm install sern-handler ``` ```sh -npm install sern-handler +yarn add sern-handler ``` # Documentation