Improvements in Readme.md

This commit is contained in:
xxDeveloper
2022-02-13 22:13:27 +03:00
parent 911cf05d3f
commit c07d87566a
5 changed files with 65 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}

View File

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

View File

@@ -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<unknown>,
options: ApplicationCommandOptionData[],
}
export const Commands = new Map<string, CommandVal>();
export const Alias = new Map<string, CommandVal>();
@@ -25,7 +28,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise<strin
const files = readdirSync(dir);
for (const file of files) {
if (statSync(dir + '/' + file).isDirectory())
await readPath(dir + '/' + file, arrayOfFiles)
await readPath(dir + '/' + file, arrayOfFiles);
else
arrayOfFiles.push(join(dir, '/', file));
}
@@ -45,17 +48,17 @@ export const fmtFileName = (n: string) => n.substring(0, n.length - 3);
export async function buildData(handler: Sern.Handler)
: Promise<{
name: string;
mod: Sern.Module<unknown>;
absPath: string;
name: string;
mod: Sern.Module<unknown>;
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<unknown>, absPath }
}))
return Promise.all((await getCommands(commandDir))
.map(async absPath => {
return { name: basename(absPath), mod: (await import(absPath)).default as Sern.Module<unknown>, absPath }
}));
}
export async function getCommands(dir: string): Promise<string[]> {
return readPath(join(process.cwd(), dir))
return readPath(join(process.cwd(), dir));
}

View File

@@ -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<T extends sEvent>(e : T, message: string) {
console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`)
}
}
public log<T extends sEvent>(e : T, message: string) {
console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`);
}
}

View File

@@ -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<boolean> {
return this.wrapper.client
return this.wrapper.client;
}
/**