handle maximum values for time option type

This commit is contained in:
Erik 2022-09-10 14:28:41 +03:00
parent 14f7a2fa84
commit b0a719d229
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 16 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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: () => {