guild only options

This commit is contained in:
Erik 2022-07-28 22:04:08 +03:00
parent 77ec8f8785
commit 81c307a11b
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,9 @@ This is an issue that should be reported to a bot developer.
[O_COMMANDHANDLER_GUILDONLY]
This command can only be run in servers.
[O_COMMANDHANDLER_GUILDONLY_OPT]
The option `{option}` is only valid in servers.
[O_COMMANDHANDLER_TYPEINTEGER]
The command option {option} requires an integer between `{min}` and `{max}`.

View File

@ -221,6 +221,7 @@ class CommandHandler extends Observer {
continue;
}
if (matched.guildOnly) return { error: true, params: { option: matched.name }, index: 'O_COMMANDHANDLER_GUILDONLY_OPT' };
const rawValue = matched.plural && typeof option.value === 'string' ? Util.parseQuotes(option.value).map(([x]) => x) : option.value;
const newOption = matched.clone(rawValue, guild, true);
const parsed = await newOption.parse();
@ -320,6 +321,7 @@ class CommandHandler extends Observer {
return f.name === _flag || aliased;
});
if (!flag) return { error: true, index: 'O_COMMANDHANDLER_UNRECOGNISED_FLAG', params: { flag: _flag } };
else if (flag.guildOnly) return { error: true, params: { option: flag.name }, index: 'O_COMMANDHANDLER_GUILDONLY_OPT' };
// console.log('aliased', aliased);
params.splice(index, 1, null);
@ -349,7 +351,8 @@ class CommandHandler extends Observer {
}
// console.log('params', params);
const options = activeCommand.options.filter((opt) => !opt.flag && (opt.type !== 'STRING' || opt.choices.length));
let options = activeCommand.options.filter((opt) => !opt.flag && (opt.type !== 'STRING' || opt.choices.length));
if(!guild) options = options.filter((opt) => !opt.guildOnly);
// const choiceOpts = activeCommand.options.filter((opt) => opt.choices.length);
const stringOpts = activeCommand.options.filter((opt) => !opt.flag && !opt.choices.length && opt.type === 'STRING');
// console.log('non-flag options', options.map((opt) => opt.name));
@ -590,7 +593,7 @@ class CommandHandler extends Observer {
async _getCommand(message) {
if (!this._mentionPattern) this._mentionPattern = new RegExp(`^(<@!?${this.client.user.id}>)`, 'iu');
const [arg1, arg2, ...args] = message.content.split(' ');
const [arg1, arg2, ...args] = message.content.split(' ').filter((str) => str.length);
if (message.guild) await message.guild.settings();
const userWrapper = await this.client.getUserWrapper(message.author.id);

View File

@ -111,6 +111,10 @@ class CommandOption {
}
get guildOnly() {
return ['ROLE', 'MEMBER', 'CHANNEL'].some((t) => this.type.includes(t));
}
usage(guild, verbose = false) {
let name = `${this.name.toUpperCase()} [${this.type}]`;
let flagProps = ['flag'];