Skip to content

Commit

Permalink
feat: hard disable commands globally from code
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Dec 17, 2018
1 parent fdaff9e commit bec524a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion commands.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/commands/Ondemand/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PriceCheck extends Command {
parameters: ['in-game name (PC only)'],
},
];
this.enabled = false;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/commands/Ondemand/Raid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Raid extends Command {
parameters: ['username'],
},
];
this.enabled = false;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/eventHandlers/CommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class CommandHandler extends Handler {
* @returns {Promise<boolean>} Whether or not the current command can be called by the author
*/
async checkCanAct(command, message) {
if (!command.enabled) {
return false;
}
if (command.ownerOnly && message.author.id !== this.bot.owner) {
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/models/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ class Command {
if (bot.path) {
this.path = bot.path;
}

/**
* Hard value to toggle a command off from code
* @type {Boolean}
*/
this.enabled = true;
}

/**
Expand Down Expand Up @@ -184,6 +190,7 @@ class Command {
path: this.path,
usages: this.usages,
blacklistable: this.blacklistable,
enabled: this.enabled,
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tools/generateManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const generateManifest = async () => {
const command = new Cmd({
md: {}, messageManager: {}, settings: {}, path: f,
});

return command;
if (command.enabled) {
return command;
}
}
return null;
} catch (err) {
Expand Down

0 comments on commit bec524a

Please sign in to comment.