Archived
0
0
Fork 0

feat(commands): added some default options

This commit is contained in:
Daryl Ronningen 2021-06-20 05:58:46 -07:00
parent 1f3e427523
commit 15e55c1349
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
2 changed files with 17 additions and 8 deletions

View file

@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>. * along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/ */
import path from 'path';
import config from 'config';
import type { Client, Message } from 'discord.js'; import type { Client, Message } from 'discord.js';
import type { ICommandOptions } from '@utils/types'; import type { ICommandOptions } from '@utils/types';
@ -21,9 +24,15 @@ export default abstract class Command {
public readonly client: Client; public readonly client: Client;
public readonly options: ICommandOptions; public readonly options: ICommandOptions;
protected constructor(client: Client, options: ICommandOptions) { protected constructor(client: Client, options?: ICommandOptions) {
this.client = client; this.client = client;
this.options = options;
const defaultOptions: ICommandOptions = {
name: path.basename(__filename, path.extname(__filename)),
group: path.basename(path.dirname(__filename)) === 'commands' ? '' : path.basename(path.dirname(__filename)),
};
this.options = config.util.extendDeep(defaultOptions, options);
} }
public abstract run(message: Message, ...args: string[]): void; public abstract run(message: Message, ...args: string[]): void;

View file

@ -31,12 +31,12 @@ export enum ECommandRunIn {
// Interfaces // Interfaces
export interface ICommandOptions { export interface ICommandOptions {
name: string; name?: string;
shortDescription: string; shortDescription?: string;
extendedDescription: string; extendedDescription?: string;
group: string; group?: string;
ownerOnly: boolean; ownerOnly?: boolean;
runIn: ECommandRunIn; runIn?: ECommandRunIn;
} }
// Type Aliases // Type Aliases