contrition/src/bot/inhibitors/HasRole.ts

34 lines
846 B
TypeScript

import { Command, Inhibitor } from "discord-akairo";
import { Role } from "discord.js";
import { Message } from "discord.js";
import { Guild } from "../../entity/Guild";
class HasRole extends Inhibitor {
constructor() {
super("HasRole", {
reason: "permissions",
type: "post",
priority: 0,
});
}
async exec(message: Message, command: Command) {
const author = message.member;
if (!author) return false;
// ADMINISTRATOR should override all other permissions, if available
if (author.hasPermission("ADMINISTRATOR")) return false;
if (command.id === "setup") return true;
const guild = await Guild.findOneOrFail({
where: { guild: author.guild.id },
});
return !author.roles.cache.some(
(role: Role) => role.id === guild.staffRole
);
}
}
export default HasRole;