From c081b68c292c723d2f4d3a384f66d462bae9ace1 Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Sun, 20 Jun 2021 05:41:26 -0700 Subject: [PATCH] feat(commands): added ability for commands to be ran by owner only --- config/default.json.example | 5 +++-- src/index.ts | 5 +++++ src/lib/structures/command.ts | 2 +- src/lib/utils/defaults.ts | 6 +++++- src/lib/utils/types.ts | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/default.json.example b/config/default.json.example index 24f5629..cbfce30 100644 --- a/config/default.json.example +++ b/config/default.json.example @@ -1,5 +1,6 @@ { "token": "", "logLevel": "", - "prefix": "" -} \ No newline at end of file + "prefix": "", + "owner": "" +} diff --git a/src/index.ts b/src/index.ts index 162208d..5726605 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,6 +81,11 @@ client.on('message', async (msg) => { if(!findCommand) return; + if(findCommand.options.ownerOnly && msg.author.id !== config.get('owner')) { + await msg.reply('Only the bot owner can run this command!'); + return; + } + if((findCommand.options.runIn === ECommandRunIn.DM) && msg.channel.type !== 'dm') { await msg.reply('You can only run this command in DMs!'); return; diff --git a/src/lib/structures/command.ts b/src/lib/structures/command.ts index 7278056..b01250b 100644 --- a/src/lib/structures/command.ts +++ b/src/lib/structures/command.ts @@ -21,7 +21,7 @@ export default abstract class Command { public readonly client: Client; public readonly options: ICommandOptions; - public constructor(client: Client, options: ICommandOptions) { + protected constructor(client: Client, options: ICommandOptions) { this.client = client; this.options = options; } diff --git a/src/lib/utils/defaults.ts b/src/lib/utils/defaults.ts index 5818a18..ed6f295 100644 --- a/src/lib/utils/defaults.ts +++ b/src/lib/utils/defaults.ts @@ -19,7 +19,7 @@ export const Defaults = { logLevel: 'info', }, configSchema: { - required: ['token', 'logLevel', 'prefix'], + required: ['token', 'logLevel', 'prefix', 'owner'], type: 'object', properties: { token: { @@ -42,6 +42,10 @@ export const Defaults = { $id: '#/properties/prefix', type: 'string', }, + owner: { + $id: '#/properties/owner', + type: 'string', + }, }, additionalProperties: false, }, diff --git a/src/lib/utils/types.ts b/src/lib/utils/types.ts index d68a5e8..c4a324a 100644 --- a/src/lib/utils/types.ts +++ b/src/lib/utils/types.ts @@ -35,6 +35,7 @@ export interface ICommandOptions { shortDescription: string; extendedDescription: string; group: string; + ownerOnly: boolean; runIn: ECommandRunIn; }