Skip to content

Commit 1d5ccd0

Browse files
authored
docs: improve jsdocs (#413)
docs: improve jsdocs
2 parents 0a4a9d1 + 4dad82c commit 1d5ccd0

File tree

6 files changed

+273
-75
lines changed

6 files changed

+273
-75
lines changed

.eslintrc.json

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,44 @@
11
{
2-
"extends": [
3-
"eslint:recommended",
4-
"prettier",
5-
"plugin:@typescript-eslint/recommended"
6-
],
7-
"parser": "@typescript-eslint/parser",
8-
"parserOptions": {
9-
"ecmaVersion": 12
10-
},
11-
"plugins": [
12-
"@typescript-eslint",
13-
"prettier"
14-
],
15-
"rules": {
16-
"strict": ["error", "global"],
17-
"linebreak-style": [
18-
"error",
19-
"unix"
20-
],
21-
"quotes": [
22-
"error",
23-
"single"
24-
],
25-
"semi": [
26-
"error",
27-
"always"
28-
],
29-
"prefer-const": "error",
30-
"@typescript-eslint/no-explicit-any": "off",
31-
"no-restricted-globals": [
32-
"error",
33-
{
34-
"name": "Buffer",
35-
"message": "Import Buffer from `node:buffer` instead"
36-
},
37-
{
38-
"name": "process",
39-
"message": "Import process from `node:process` instead"
40-
},
41-
{
42-
"name": "setTimeout",
43-
"message": "Import setTimeout from `node:timers` instead"
44-
},
45-
{
46-
"name": "setInterval",
47-
"message": "Import setInterval from `node:timers` instead"
48-
},
49-
{
50-
"name": "setImmediate",
51-
"message": "Import setImmediate from `node:timers` instead"
52-
}
53-
]
54-
}
2+
"extends": [
3+
"eslint:recommended",
4+
"prettier",
5+
"plugin:@typescript-eslint/recommended"
6+
],
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"ecmaVersion": 12
10+
},
11+
"plugins": ["@typescript-eslint", "prettier"],
12+
"rules": {
13+
"strict": ["error", "global"],
14+
"max-len": ["error", 120, 2],
15+
"linebreak-style": ["error", "unix"],
16+
"quotes": ["error", "single"],
17+
"semi": ["error", "always"],
18+
"prefer-const": "error",
19+
"@typescript-eslint/no-explicit-any": "off",
20+
"no-restricted-globals": [
21+
"error",
22+
{
23+
"name": "Buffer",
24+
"message": "Import Buffer from `node:buffer` instead"
25+
},
26+
{
27+
"name": "process",
28+
"message": "Import process from `node:process` instead"
29+
},
30+
{
31+
"name": "setTimeout",
32+
"message": "Import setTimeout from `node:timers` instead"
33+
},
34+
{
35+
"name": "setInterval",
36+
"message": "Import setInterval from `node:timers` instead"
37+
},
38+
{
39+
"name": "setImmediate",
40+
"message": "Import setImmediate from `node:timers` instead"
41+
}
42+
]
43+
}
5544
}

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ export * from './lib/util/logger/Logger';
3333
// Inhibitors
3434
export * as Inhibitor from './inhibitors';
3535

36-
/* Providers
37-
* Providers will not be exported due to additional modules. To import, just use the path gcommands/dist/providers/{name}
36+
/**
37+
* Providers are not exported
38+
* To import, just use the path gcommands/dist/providers/{name}
3839
*/
3940
export * from './lib/structures/Provider';
4041

src/lib/GClient.ts

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import { setImmediate } from 'node:timers';
2-
import { Awaitable, Client, ClientOptions, Message } from 'discord.js';
2+
import {
3+
Awaitable,
4+
Client,
5+
ClientOptions,
6+
Message,
7+
Snowflake,
8+
} from 'discord.js';
39
import { Commands } from './managers/CommandManager';
410
import { Components } from './managers/ComponentManager';
511
import { Listeners } from './managers/ListenerManager';
612
import { Plugins } from './managers/PluginManager';
713
import { registerDirectories } from './util/registerDirectories';
814
import Responses from '../responses.json';
915

16+
/**
17+
* A valid prefix for GCommands.
18+
* * `string`: for single prefix, like `'?'`.
19+
* * `string[]`: an array of prefixes, like `['?', '!']`.
20+
* * `null`: disabled prefix, only mention works.
21+
*/
1022
export type GClientMessagePrefix = string | string[] | null;
1123

24+
/**
25+
* Enum for the auto defer feature.
26+
*
27+
* Automatically defers interaction if application doesn't respond in 3s
28+
* * EPHEMERAL
29+
* * NORMAL
30+
* * UPDATE
31+
*/
1232
export enum AutoDeferType {
1333
/**
1434
* @example interaction.deferReply({ ephemeral: true })
@@ -24,19 +44,91 @@ export enum AutoDeferType {
2444
'UPDATE' = 3,
2545
}
2646

47+
/**
48+
* Options for the GClient.
49+
* @extends {ClientOptions}
50+
*/
2751
export interface GClientOptions extends ClientOptions {
52+
/**
53+
* Support for message commands.
54+
* @type {boolean}
55+
*/
2856
messageSupport?: boolean;
57+
/**
58+
* Prefix for message commands
59+
* @requires {@link GClientOptions.messageSupport} to be enabled
60+
*/
2961
messagePrefix?:
3062
| ((message: Message) => Awaitable<GClientMessagePrefix>)
3163
| GClientMessagePrefix;
64+
/**
65+
* Whether to send a message for an unknown message command.
66+
* @type {boolean}
67+
*/
3268
unknownCommandMessage?: boolean;
69+
/**
70+
* Array of all folders to be loaded by GCommands.
71+
*
72+
* GCommands will check all the files in each folder for these classes:
73+
* * Command
74+
* * Listener
75+
* * Component
76+
*
77+
* @type {string[]}
78+
* @example
79+
* ```typescript
80+
* new GClient({
81+
* dirs: [
82+
* join(__dirname, 'commands'),
83+
* join(__dirname, 'events'),
84+
* join(__dirname, 'components'),
85+
* ]
86+
* })
87+
* ```
88+
*/
3389
dirs?: Array<string>;
90+
/**
91+
* The database to be used in the project.
92+
*
93+
* This option is only for easier access and is not used by GCommands.
94+
*
95+
* @type {any}
96+
*/
3497
database?: any;
35-
devGuildId?: string;
98+
/**
99+
* The guild id that will serve as the development server for your application.
100+
*
101+
* If this option is present, all slash commands will be registered only for the specified guild id.
102+
* However, if the command contains the `guildId` option, it is used instead of this option.
103+
*
104+
* @type {Snowflake}
105+
*/
106+
devGuildId?: Snowflake;
36107
}
37108

109+
/**
110+
* The base {@link Client} that GCommands uses.
111+
*
112+
* @see {@link GClientOptions} for all available options for GClient.
113+
*
114+
* @extends {Client}
115+
*/
38116
export class GClient<Ready extends boolean = boolean> extends Client<Ready> {
117+
/**
118+
* Object of the default responses that GCommands uses for auto responding in the case of something happening.
119+
*
120+
* You can customize these messages using the
121+
* [@gcommands/plugin-language](https://github.com/Garlic-Team/gcommands-addons/tree/master/packages/plugin-language)
122+
* plugin.
123+
*
124+
* @see {@link Responses}
125+
*/
39126
public responses: Record<string, string> = Responses;
127+
128+
/**
129+
* Object of all provided options.
130+
* @see {@link GClientOptions}
131+
*/
40132
public declare options: GClientOptions;
41133

42134
constructor(options: GClientOptions) {
@@ -48,6 +140,7 @@ export class GClient<Ready extends boolean = boolean> extends Client<Ready> {
48140
this.options.database.init();
49141
}
50142

143+
// Load all managers before login.
51144
setImmediate(async (): Promise<void> => {
52145
await Promise.all([
53146
Plugins.initiate(this),
@@ -58,6 +151,35 @@ export class GClient<Ready extends boolean = boolean> extends Client<Ready> {
58151
});
59152
}
60153

154+
/**
155+
* The method that returns the database option provided in {@link GClientOptions}
156+
* @param {any} _ Used for typings
157+
* @returns {Database}
158+
* @example TypeScript example
159+
* ```typescript
160+
* import { MongoDBProvider } from 'gcommands/dist/providers/MongoDBProvider';
161+
*
162+
* const client = new GClient({
163+
* ..settings,
164+
* database: new MongoDBProvider('mongodb://localhost:27017/database')
165+
* })
166+
*
167+
* const db = client.getDatabase(MongoDBProvider.prototype);
168+
* // returns <MongoDBProvider>
169+
* ```
170+
* @example JavaScript example
171+
* ```javascript
172+
* const { MongoDBProvider } = require('gcommands/dist/providers/MongoDBProvider');
173+
*
174+
* const client = new GClient({
175+
* ..settings,
176+
* database: new MongoDBProvider('mongodb://localhost:27017/database')
177+
* })
178+
*
179+
* const db = client.getDatabase(MongoDBProvider.prototype);
180+
* // returns <MongoDBProvider>
181+
* ```
182+
*/
61183
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62184
public getDatabase<Database>(_?: Database): Database {
63185
return this.options.database;

src/lib/loaders/directoryLoader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import { Util } from '../util/Util';
44

5-
export async function directoryLoader(dir: string): Promise<Array<any>> {
5+
/**
6+
* The method that loads all files from a directory
7+
* @param {string} dir The directory to load
8+
* @returns {Promise<any[]>}
9+
*/
10+
export async function directoryLoader(dir: string): Promise<any[]> {
611
let files = [];
712
if (fs.existsSync(dir)) {
813
for await (const fsDirent of fs.readdirSync(dir, { withFileTypes: true })) {

src/lib/loaders/pluginFinder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
33

4+
/**
5+
* The method that loads plugin files from a directory
6+
* @param basedir The base plugin directory
7+
* @param folder The plugin folder
8+
*/
49
export async function loadPluginFolder(basedir: string, folder: fs.Dirent) {
510
if (folder.isDirectory()) {
611
if (fs.existsSync(path.join(basedir, folder.name, 'index.js'))) {
@@ -19,6 +24,10 @@ export async function loadPluginFolder(basedir: string, folder: fs.Dirent) {
1924
}
2025
}
2126

27+
/**
28+
* The method that find all plugins in a directory
29+
* @param {string} basedir The directory to find plugins in
30+
*/
2231
export async function pluginFinder(basedir: string) {
2332
if (fs.existsSync(basedir)) {
2433
if (fs.existsSync(path.join(basedir, 'plugins'))) {

0 commit comments

Comments
 (0)