1 |
import { GuildMember } from "discord.js"; |
2 |
import DiscordClient from "../client/Client"; |
3 |
import BaseCommand from "../utils/structures/BaseCommand"; |
4 |
|
5 |
export default class Auth { |
6 |
constructor(protected client: DiscordClient) { |
7 |
|
8 |
} |
9 |
|
10 |
async verify(member: GuildMember, command: BaseCommand): Promise<boolean> { |
11 |
const cmds: string[] = await this.client.config.get('global_commands'); |
12 |
|
13 |
if (cmds.indexOf(command.getName()) !== -1) { |
14 |
return true; |
15 |
} |
16 |
|
17 |
if (command.ownerOnly && !this.client.config.props.global.owners.includes(member.user.id)) { |
18 |
return false; |
19 |
} |
20 |
|
21 |
if (await member.roles.cache.has(await this.client.config.get('mod_role'))) { |
22 |
let restricted: string[] = []; |
23 |
const roleCommands: { [key: string]: string[] } = await this.client.config.get('role_commands'); |
24 |
|
25 |
for (const roleID in roleCommands) { |
26 |
if (await member.roles.cache.has(roleID)) { |
27 |
restricted = await roleCommands[roleID]; |
28 |
break; |
29 |
} |
30 |
} |
31 |
|
32 |
return restricted.indexOf(command.getName()) === -1; |
33 |
} |
34 |
|
35 |
return false; |
36 |
} |
37 |
}; |