diff --git a/README.md b/README.md index 96e3f19..922f65b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,24 @@ -# 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 +# Installation + +```sh +npm install sern-handler +``` + +```sh +yarn add sern-handler +``` + +# Documentation - 📑 [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! 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", diff --git a/src/handler/Utilities/readFile.ts b/src/handler/Utilities/readFile.ts index cb1fe86..f5b168b 100644 --- a/src/handler/Utilities/readFile.ts +++ b/src/handler/Utilities/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/handler/logger.ts b/src/handler/logger.ts new file mode 100644 index 0000000..9b1a959 --- /dev/null +++ b/src/handler/logger.ts @@ -0,0 +1,16 @@ + +enum sEvent { + GLOBAL_SLASH, + LOCAL_SLASH, + TEXT_CMD, + CRASH, + DM, + +} + +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/handler/sern.ts b/src/handler/sern.ts index 3bc7f01..706d97e 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -63,7 +63,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); }) @@ -115,7 +115,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; @@ -143,13 +143,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 @@ -171,7 +171,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: [] }) } } } @@ -269,6 +269,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/types/handler.ts b/src/types/handler.ts index bfd267d..b4e9e38 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -28,8 +28,13 @@ export type Context = { message: Option, interaction: Option } +<<<<<<< HEAD export type Arg = ParseType<{ text: string, slash: SlashOptions }>; +======= +// `string` | `SlashOptions`, narrow down your type by checking `text` | `slash` +export type Arg = ParseType<{text : string, slash : SlashOptions}> +>>>>>>> 6ce7649311f1d077f6437528cbad10da16e58435 // TypeAlias for interaction.options export type SlashOptions = Omit;