From d5ad51d0e9d193420626db032149f36d0ef2f9c3 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 22:37:38 -0600 Subject: [PATCH 1/7] eslint require semis! --- .eslintrc | 3 ++- src/handler/sern.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6598da8..3dac692 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,7 @@ "parserOptions": { "ecmaVersion": "esnext", "sourceType": "" }, "rules": { "@typescript-eslint/no-non-null-assertion": "off", - "quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals" : true }] + "quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals" : true }], + "semi" : ["error", "always"] } } \ No newline at end of file diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 028a8fa..b1f714c 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -16,7 +16,7 @@ import type { Message } from 'discord.js'; -import { Ok, Result, None, Some, Option } from 'ts-results'; +import { Ok, Result, None, Some } from 'ts-results'; import { isBot, hasPrefix, fmt } from './utilities/messageHelpers'; /** @@ -154,6 +154,7 @@ export class Handler { } case 'public': { // Creating global commands + // TODO : warn user they will be creating a public command await this.client.application!.commands .create({ name: cmdName, From 5c2701fba776c6836d1faacbf5f1bf0ce155b308 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 22:39:51 -0600 Subject: [PATCH 2/7] fix eslint-caught semis --- src/handler/Utilities/readFile.ts | 2 +- src/handler/logger.ts | 2 +- src/handler/sern.ts | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/handler/Utilities/readFile.ts b/src/handler/Utilities/readFile.ts index 9a6917f..9fc78ba 100644 --- a/src/handler/Utilities/readFile.ts +++ b/src/handler/Utilities/readFile.ts @@ -55,7 +55,7 @@ export async function buildData(handler: Sern.Handler) 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 { name: basename(absPath), mod: (await import(absPath)).default as Sern.Module, absPath }; })); } diff --git a/src/handler/logger.ts b/src/handler/logger.ts index b5343dd..d325452 100644 --- a/src/handler/logger.ts +++ b/src/handler/logger.ts @@ -12,7 +12,7 @@ enum sEvent { export default class Logger { - public clear() { console.clear() } + public clear() { console.clear(); } public log(e : T, message: string) { dayJS.extend(UTC); diff --git a/src/handler/sern.ts b/src/handler/sern.ts index b1f714c..2a01e30 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -44,7 +44,7 @@ export class Handler { .on('ready', async () => { Files.buildData(this) - .then(data => this.registerModules(data)) + .then(data => this.registerModules(data)); if (wrapper.init !== undefined) wrapper.init(this); }) @@ -55,10 +55,10 @@ export class Handler { const tryFmt = fmt(message, this.prefix); const module = this.findCommand(tryFmt.shift()!); if (module === undefined) { - message.channel.send('Unknown legacy command') + message.channel.send('Unknown legacy command'); return; } - const cmdResult = (await this.commandResult(module, message, tryFmt.join(' '))) + const cmdResult = (await this.commandResult(module, message, tryFmt.join(' '))); if (cmdResult === undefined) return; message.channel.send(cmdResult); @@ -90,7 +90,7 @@ export class Handler { if (name === undefined) `${interaction.commandName} is not a valid command!`; if (module.mod.type < CommandType.SLASH) return 'This is not a slash command'; - const context = { message: None, interaction: Some(interaction) } + const context = { message: None, interaction: Some(interaction) }; const parsedArgs = module.mod.parse?.(context, ['slash', interaction.options]) ?? Ok(''); if (parsedArgs.err) return parsedArgs.val; @@ -108,7 +108,7 @@ export class Handler { private async commandResult(module: Files.CommandVal | undefined, message: Message, args: string): Promise { if (module?.mod === undefined) return 'Unknown legacy command'; - if (module.mod.type === CommandType.SLASH) return `This may be a slash command and not a legacy command` + if (module.mod.type === CommandType.SLASH) return `This may be a slash command and not a legacy command`; 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'; @@ -121,7 +121,7 @@ export class Handler { const context = { message: Some(message), interaction: None - } + }; const parsedArgs = module.mod.parse?.(context, ['text', args]) ?? Ok(''); if (parsedArgs.err) return parsedArgs.val; return (await module.mod.delegate(context, parsedArgs))?.val; @@ -145,12 +145,12 @@ export class Handler { case 1: Files.Commands.set(cmdName, { mod, options: [] }); break; case 2: case (1 | 2): { - const options = ((await import(absPath)).options as ApplicationCommandOptionData[]) + const options = ((await import(absPath)).options as ApplicationCommandOptionData[]); Files.Commands.set(cmdName, { mod, options: options ?? [] }); switch (mod.visibility) { case 'private': { // Reloading guild slash commands - await this.reloadSlash(cmdName, mod.desc, options) + await this.reloadSlash(cmdName, mod.desc, options); } case 'public': { // Creating global commands @@ -169,7 +169,7 @@ export class Handler { if (mod.alias.length > 0) { for (const alias of mod.alias) { - Files.Alias.set(alias, { mod, options: [] }) + Files.Alias.set(alias, { mod, options: [] }); } } } From 4a1de83b4197417fd2ed5496c239221950256eea Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:43:08 +0300 Subject: [PATCH 3/7] Update README.md --- README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f4dd48f..c8b1e8e 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,11 @@ yarn add sern-handler # Basic Usage -[Typescript](https://www.typescriptlang.org/) -```ts -import { Client } from 'discord.js' -import { Intents } from 'discord.js' -import {prefix, token} from "../src/secrets.json" -import {Sern} from "sern-handler" +TypeScript or JavaScript +```js +import { Client, Intents } from 'discord.js'; +import { prefix, token } from '../src/secrets.json'; +import { Handler } from 'sern-handler'; const client = new Client({ intents: [ @@ -29,10 +28,9 @@ const client = new Client({ Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS ] +}); -}) - - new Sern.Handler( { + new Handler( { client, prefix, commands : "dist/commands", @@ -43,12 +41,12 @@ const client = new Client({ } ], init: async (handler : Sern.Handler) => { - /* an optional function to initialize anything else on bot startup */ + // Optional function to initialize anything else on bot startup }, }); -client.login(token) +client.login(token); ``` # Links From f30a373da63627638a05e3635f77c58087febfe6 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:45:44 +0300 Subject: [PATCH 4/7] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c8b1e8e..26652c9 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ yarn add sern-handler TypeScript or JavaScript ```js import { Client, Intents } from 'discord.js'; -import { prefix, token } from '../src/secrets.json'; import { Handler } from 'sern-handler'; +import { prefix, token } from '../src/secrets.json'; const client = new Client({ intents: [ @@ -30,14 +30,15 @@ const client = new Client({ ] }); - new Handler( { +// Access handler anywhere +client.handler = new Handler({ client, prefix, - commands : "dist/commands", + commands : 'dist/commands', privateServers : [ { test : true, - id: "server id" + id: 'server-id' } ], init: async (handler : Sern.Handler) => { From 5c928a1d0fdd6993b164592f7ad3b67ab5836284 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:46:59 +0300 Subject: [PATCH 5/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26652c9..3263ce7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ yarn add sern-handler # Basic Usage -TypeScript or JavaScript +JavaScript ```js import { Client, Intents } from 'discord.js'; import { Handler } from 'sern-handler'; @@ -41,7 +41,7 @@ client.handler = new Handler({ id: 'server-id' } ], - init: async (handler : Sern.Handler) => { + init: async (handler) => { // Optional function to initialize anything else on bot startup }, }); From 38963ffa19eace111ee2864c838ada00fc40f26b Mon Sep 17 00:00:00 2001 From: jacoobes Date: Mon, 14 Feb 2022 09:21:32 -0600 Subject: [PATCH 6/7] rf --- src/handler/utilities/readFile.ts | 54 +++++++++++++------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index 9fc78ba..f8d694b 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -1,23 +1,15 @@ -import type { - ApplicationCommandOptionData -} from 'discord.js'; +import type { ApplicationCommandOptionData } from 'discord.js'; -import { - readdirSync, - statSync -} from 'fs'; +import { readdirSync, statSync } from 'fs'; -import { - basename, - join -} from 'path'; +import { basename, join } from 'path'; import type * as Sern from '../sern'; export type CommandVal = { - mod: Sern.Module, - options: ApplicationCommandOptionData[], -} + mod: Sern.Module; + options: ApplicationCommandOptionData[]; +}; export const Commands = new Map(); export const Alias = new Map(); @@ -27,11 +19,9 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise n.substring(0, n.length - 3); /** - * @param {Sern.Handler} handler an instance of Sern.Handler + * @param {Sern.Handler} handler an instance of Sern.Handler * @returns {Promise<{ name: string; mod: Sern.Module; absPath: string; }[]>} data from command files -*/ + */ -export async function buildData(handler: Sern.Handler) - : Promise<{ - name: string; - mod: Sern.Module; - absPath: string; - }[]> { - const commandDir = handler.commandDir; - return Promise.all((await getCommands(commandDir)) - .map(async absPath => { +export async function buildData(handler: Sern.Handler): Promise< + { + 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 }; - })); + }), + ); } export async function getCommands(dir: string): Promise { From 499a996a6c0e0576415ef90237c6f9f6ef1cd22d Mon Sep 17 00:00:00 2001 From: jacoobes Date: Mon, 14 Feb 2022 09:59:28 -0600 Subject: [PATCH 7/7] readme changes --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 3263ce7..3cc05e5 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,38 @@ yarn add sern-handler # Basic Usage +Typescript +```ts +import { Client } from 'discord.js' +import { Intents } from 'discord.js' +import { prefix, token } from "../src/secrets.json" +import { Sern } from "sern-handler" + +const client = new Client({ + intents: [ + Intents.FLAGS.GUILDS, + Intents.FLAGS.GUILD_MESSAGES, + Intents.FLAGS.GUILD_MEMBERS + ] + +}) + + new Sern.Handler( { + client, + prefix, + commands : 'dist/commands', + privateServers : [ + { + test : true, + id: 'server-id' + } + ], + init: async (handler : Sern.Handler) => { + // Optional function to initialize anything else on bot startup + }, +}); +``` + JavaScript ```js import { Client, Intents } from 'discord.js';