diff --git a/src/localization/en_gb/observers/en_gb_commandHandler.lang b/src/localization/en_gb/observers/en_gb_commandHandler.lang index 781c11a..b5f8e33 100644 --- a/src/localization/en_gb/observers/en_gb_commandHandler.lang +++ b/src/localization/en_gb/observers/en_gb_commandHandler.lang @@ -32,6 +32,9 @@ The command option {option} requires a date in the format `YYYY/MM/DD` [O_COMMANDHANDLER_TYPETIME] The command option {option} requires a timestring (e.g. 5 min, 2w). +[O_COMMANDHANDLER_TYPETIME_MAX] +Time value cannot be over `{maximum}`. + [O_COMMANDHANDLER_TYPEUSER] The command option {option} requires a user. diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index e18a873..21abe1d 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -123,7 +123,11 @@ class CommandHandler extends Observer { const { command } = invoker; if (response.error && response.index) { if (!response.emoji) response.emoji = 'failure'; - if (!response.params) response.params = response.option; + if (!response.params) + response.params = response.option; + else + response.params = { ...response.option, ...response.params }; + return invoker.reply(response); } else if (response.error) { let content = invoker.format(`O_COMMANDHANDLER_TYPE${response.option.type}`, { @@ -384,7 +388,10 @@ class CommandHandler extends Observer { if (!removed.error) break; index++; } - if (removed.error) continue; + if (removed.error) { + if (removed.index) return { option: cloned, ...removed }; + continue; + } args[cloned.name] = cloned; // Clean up params for string parsing diff --git a/src/structure/interfaces/CommandOption.js b/src/structure/interfaces/CommandOption.js index 195e183..ca77b78 100644 --- a/src/structure/interfaces/CommandOption.js +++ b/src/structure/interfaces/CommandOption.js @@ -1,6 +1,7 @@ /* eslint-disable camelcase */ const { ChannelType } = require("discord.js"); +const { Util } = require("../../utilities"); const Constants = { CommandOptionTypes: { @@ -173,11 +174,11 @@ class CommandOption { if((this._rawValue === null || this._rawValue === undefined) && !this.valueOptional) throw new Error(`Null _rawValue passed to ${this.name}`); // console.log('-------PARSE BEGIN---------'); // console.log('1', this.name, this._rawValue, this.valueOptional); - const { removed, value, error } = await this.types[this.type](); + const { removed, value, error, index, params } = await this.types[this.type](); if (this.valueOptional && error) { this.value = this.defaultValue; } else { - if(error) return { error }; + if(error) return { error, index, params }; this.value = value; } @@ -298,6 +299,7 @@ class CommandOption { TIME: () => { const value = this.client.resolver.resolveTime(this._rawValue); if (value === null) return { error: true }; + if (value > this.maximum) return { error: true, index: 'O_COMMANDHANDLER_TYPETIME_MAX', params: { maximum: Util.humanise(this.maximum) } }; return { value, removed: [this._rawValue] }; }, COMPONENT: () => {