Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
chore(structures): add more options to pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
alexthemaster committed Jul 22, 2020
1 parent 01e3016 commit 46c240c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/events/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class extends Event {

if (cmd.disabled) return message.channel.send(`This command was globally disabled by the bot owner.`);

if (!cmd.canRunInDM && message.channel.type === 'dm') return;

if (cmd.nsfw && message.channel.type !== 'dm' && !message.channel.nsfw) return message.channel.send('This command can only be used in NSFW chnanels.');

cmd.run(message);
}
}
7 changes: 6 additions & 1 deletion src/lib/structures/BasePiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class BasePiece<T> {
public readonly client: MoonlightClient;
/** Whether or not this piece is disabled */
public disabled: boolean;
/** The description of the piece */
public readonly description?: string;
/** The pool this piece is part of */
public readonly pool: BasePool<string, T>;
public options: BasePieceOptions | undefined;
Expand Down Expand Up @@ -37,7 +39,8 @@ export class BasePiece<T> {
constructor(client: MoonlightClient, pool: BasePool<string, T>, options?: BasePieceOptions) {
this.client = client;
this.options = options;
this.disabled = options?.disabled || false;
this.description = options?.description;
this.disabled = options?.disabled ?? false;
this.pool = pool;
}
}
Expand All @@ -46,4 +49,6 @@ export interface BasePieceOptions {
name?: string;
/** Whether or not this piece should be disabled */
disabled?: boolean;
/** The description of the piece */
description?: string;
}
16 changes: 14 additions & 2 deletions src/lib/structures/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ import { Message } from "discord.js";
export class Command extends BasePiece<Command> {
/** An array of aliases */
public readonly aliases: string[];
/** Whether or not this command can only be run in a nsfw channel */
public readonly nsfw: boolean;
/** Whether or not this command can be called by a user when DM-ing the bot */
public readonly canRunInDM: boolean;

public run(message: Message, ...arg: any[]): void {
public run(_message: Message, ..._arg: any[]): void {
throw new Error(`Run function not defined in ${__filename}`);
}

constructor(client: MoonlightClient, pool: BasePool<string, Command>, options?: CommandOptions) {
super(client, pool, options)
this.aliases = options?.aliases || new Array();
this.aliases = options?.aliases ?? new Array();
this.nsfw = options?.nsfw ?? false;
this.canRunInDM = options?.canRunInDM ?? true;

}
}

interface CommandOptions extends BasePieceOptions {
/** An array of aliases */
aliases?: string[];
/** Whether or not this command should only be run in a nsfw channel */
nsfw?: boolean;
/** Whether or not this command can be called by a user when DM-ing the bot */
canRunInDM?: boolean;
}

0 comments on commit 46c240c

Please sign in to comment.