-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.js
More file actions
42 lines (40 loc) · 1.17 KB
/
command.js
File metadata and controls
42 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const flagTemplate = {
alias: [''],
usage: '',
default: '',
description: '',
};
module.exports = class Command {
constructor({
title = '',
alias = [''],
examples = [''],
usage = '',
description = '',
permission = '',
flags = [flagTemplate],
handler = (context, args = [''], flags = {}) => context.reply('Missing Handler'),
} = {}) {
alias = alias.filter(_ => _.trim());
if (!alias.length) throw new Error('No aliases provided.');
this.title = title;
this.alias = alias;
this.examples = examples.filter(_ => _.trim());
this.usage = usage;
this.permission = permission;
this.description = description;
this.flags = flags.filter(_ => _.alias.filter(_ => _.trim()).length);
this.handler = handler;
}
handle(context, ...rest) {
if (this.permission) {
const permissions = context.channel.permissionsOf(context.user.id);
const allowed = Array.isArray(this.permission) ? this.permission.find((perm) => permissions.has(perm)) : permissions.has(this.permission);
if (!allowed) {
context.reply('Missing permissions');
return;
}
}
this.handler(context, ...rest);
}
};