@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
38 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoleOptionResolver = void 0;
const eris_1 = require("eris");
const OptionType_1 = require("../constants/OptionType");
class RoleOptionResolver {
constructor() {
this.option = OptionType_1.OptionType.ROLE;
this.convert = eris_1.Constants.ApplicationCommandOptionTypes.ROLE;
}
async reduce(ctx, option, role) {
return { display: `@${role.name}`, extra: role.id };
}
async resolve(ctx, option, input) {
const guild = ctx.guild;
if (!guild)
return null;
const roles = guild.roles;
// Attempt filter
const filter = Array.from(roles.filter(r => this.checkRole(input, r)).values());
if (filter.length > 0)
return filter;
return Array.from(roles.values());
}
checkRole(input, role) {
if (role.id === input)
return true;
// handle mention
const id = /^<@&(\d{17,19})>$/i.exec(input);
if (id && role.id === id[1])
return true;
// handle name
input = input.replace(/^@/, '');
return role.name.toLocaleLowerCase().includes(input.toLocaleLowerCase());
}
}
exports.RoleOptionResolver = RoleOptionResolver;
//# sourceMappingURL=RoleOption.js.map