@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
41 lines (39 loc) • 1.24 kB
JavaScript
import { Option } from "@sapphire/result";
import { PrefixedStrategy } from "@sapphire/lexure";
//#region src/lib/utils/strategies/FlagUnorderedStrategy.ts
const never = () => Option.none;
const always = () => true;
var FlagUnorderedStrategy = class extends PrefixedStrategy {
constructor({ flags, options, prefixes = [
"--",
"-",
"—"
], separators = ["=", ":"] } = {}) {
super(prefixes, separators);
this.flags = flags || [];
this.options = options || [];
if (this.flags === true) this.allowedFlag = always;
else if (this.flags.length === 0) this.matchFlag = never;
if (this.options === true) this.allowedOption = always;
else if (this.options.length === 0) this.matchOption = never;
}
matchFlag(s) {
const result = super.matchFlag(s);
if (result.isSomeAnd((value) => this.allowedFlag(value))) return result;
return Option.none;
}
matchOption(s) {
const result = super.matchOption(s);
if (result.isSomeAnd((option) => this.allowedOption(option[0]))) return result;
return Option.none;
}
allowedFlag(s) {
return this.flags.includes(s);
}
allowedOption(s) {
return this.options.includes(s);
}
};
//#endregion
export { FlagUnorderedStrategy };
//# sourceMappingURL=FlagUnorderedStrategy.mjs.map