11import { 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' ;
39import { Commands } from './managers/CommandManager' ;
410import { Components } from './managers/ComponentManager' ;
511import { Listeners } from './managers/ListenerManager' ;
612import { Plugins } from './managers/PluginManager' ;
713import { registerDirectories } from './util/registerDirectories' ;
814import 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+ */
1022export 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+ */
1232export 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+ */
2751export 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+ */
38116export 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 ;
0 commit comments