Skip to content

Commit

Permalink
feat: modified command handler (#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolfx committed Jan 18, 2023
1 parent f6596f1 commit 6509ae5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/classes/Commands/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as c from './sub-classes/export';
// Import all commands
import InformationCommands from './commands/information';
import CartCommands from './commands/cart';
import InventoryCommands from './commands/inventory';

export interface ICommand {
/**
Expand Down Expand Up @@ -41,7 +42,7 @@ export interface ICommand {
/**
* Allow the steamID to be invalid
*/
allowInvalidType?: boolean;
dontAllowInvalidType?: boolean;
/**
* Is only allowed for admins
*/
Expand Down Expand Up @@ -70,7 +71,7 @@ function hasAliases(command: ICommand): command is ICommand & { aliases: string[
}

export default class CommandHandler {
private manager: c.ManagerCommands;
manager: c.ManagerCommands;

private message: c.MessageCommand;

Expand Down Expand Up @@ -121,7 +122,7 @@ export default class CommandHandler {
// We will also include aliases and point them to the command

// We want to initialize all our commands
const commands = [...InformationCommands, ...CartCommands];
const commands = [...InformationCommands, ...CartCommands, ...InventoryCommands];
for (const command of commands) {
const cmd = new command(this.bot, this.pricer, this);
this.commands.set(cmd.name, cmd);
Expand Down Expand Up @@ -149,6 +150,12 @@ export default class CommandHandler {
log.debug(`Received command ${command} from ${steamID.getSteamID64()}`);

if (command === null) {
const custom = this.bot.options.customMessage.commandNotFound;

this.bot.sendMessage(
steamID,
custom ? custom.replace('%command%', command) : `❌ Command "${command}" not found!`
);
return;
}

Expand All @@ -167,7 +174,8 @@ export default class CommandHandler {
return;
}

if (!cmd.allowInvalidType && isInvalidType) {
// By default dontAllowInvalidType is false
if (cmd.dontAllowInvalidType && isInvalidType) {
return this.bot.sendMessage(steamID, '❌ Command not available.');
}

Expand Down

0 comments on commit 6509ae5

Please sign in to comment.