dressed
Version:
A sleek, serverless-ready Discord bot framework.
89 lines • 3.63 kB
JavaScript
export function getOption(name, required, options, resolved) {
const option = options.find((o) => o.name === name);
if (!option) {
if (required)
throw new Error(`Required option "${name}" not found`);
return undefined;
}
return {
subcommand: () => {
if (option.type !== 1)
throw new Error("Not a subcommand");
return {
name,
getOption: (name, required) => { var _a; return getOption(name, required !== null && required !== void 0 ? required : false, (_a = option.options) !== null && _a !== void 0 ? _a : [], resolved); },
};
},
subcommandGroup: () => {
if (option.type !== 2)
throw new Error("Not a subcommand group");
return {
name,
getSubcommand: (name) => { var _a; return (_a = getOption(name, false, option.options, resolved)) === null || _a === void 0 ? void 0 : _a.subcommand(); },
};
},
string: () => {
if (option.type !== 3)
throw new Error("Not a string");
return option.value;
},
integer: () => {
if (option.type !== 4)
throw new Error("Not an integer");
return option.value;
},
boolean: () => {
if (option.type !== 5)
throw new Error("Not a boolean");
return option.value;
},
user: () => {
if (option.type !== 6)
throw new Error("Not a user");
if (!(resolved === null || resolved === void 0 ? void 0 : resolved.users))
throw new Error("No users found");
return resolved.users[option.value];
},
channel: () => {
if (option.type !== 7)
throw new Error("Not a channel");
if (!(resolved === null || resolved === void 0 ? void 0 : resolved.channels))
throw new Error("No channels found");
return resolved.channels[option.value];
},
role: () => {
if (option.type !== 8)
throw new Error("Not a role");
if (!(resolved === null || resolved === void 0 ? void 0 : resolved.roles))
throw new Error("No roles found");
return resolved.roles[option.value];
},
mentionable: () => {
var _a, _b;
if (option.type !== 9)
throw new Error("Not a mentionable");
if ((_a = resolved === null || resolved === void 0 ? void 0 : resolved.users) === null || _a === void 0 ? void 0 : _a[option.value]) {
return resolved.users[option.value];
}
else if ((_b = resolved === null || resolved === void 0 ? void 0 : resolved.roles) === null || _b === void 0 ? void 0 : _b[option.value]) {
return resolved.roles[option.value];
}
else {
throw new Error("No mentionables found");
}
},
number: () => {
if (option.type !== 10)
throw new Error("Not a number");
return option.value;
},
attachment: () => {
if (option.type !== 11)
throw new Error("Not an attachment");
if (!(resolved === null || resolved === void 0 ? void 0 : resolved.attachments))
throw new Error("No attachments found");
return resolved.attachments[option.value];
},
};
}
//# sourceMappingURL=options.js.map