-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.js
187 lines (156 loc) · 5.06 KB
/
command.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const { Permissions } = require('discord.js')
class Command {
constructor(name) {
this.help = new Help(name)
}
get name() {
return this.help.name;
}
set name(value) {
if(this.help.name === "") {
this.help.name = value;
} else {
throw new Error(`Can't change command name from '${this.help.name}' to (type: ${typeof(value)}) '${value}'. Command names are immutable`)
}
}
get aliases() {
return this.help.alias.join(", ");
}
addAliases(...aliases) {
if(aliases.length === 0) return;
for (const alias of aliases) {
this.help.alias.push(alias);
}
}
deleteAliases(...aliases) {
if(aliases.length === 0) return;
let newAlias = []
for (const alias of this.help.alias) {
if(!aliases.includes(alias)) {
newAlias.push(alias);
}
}
this.help.alias = newAlias;
}
get cooldown() {
return this.help.cooldown;
}
set cooldown(value) {
if (typeof(value) !== "number") {
throw new Error(`Tried setting cooldown of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a number.`)
}
this.help.cooldown = value;
}
get usePerCooldown() {
return this.help.use_per_cooldown;
}
set usePerCooldown(value) {
if(typeof(value) !== "number") {
throw new Error(`Tried setting uses per cooldown of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a number.`);
}
this.help.use_per_cooldown = value;
}
get deleted() {
return this.help.deleted;
}
set deleted(value) {
if(typeof(value) !== "boolean") {
throw new Error(`Tried setting deleted value of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a boolean value.`);
}
this.help.deleted = value;
}
get description() {
return this.help.description;
}
set description(value) {
if(typeof(value) === "string") {
this.help.description = value;
} else {
throw new Error(`Tried setting description of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a string.`);
}
}
get userPermission() {
return this.help.permissions.user;
}
set userPermission(value) {
if(Permissions.FLAGS[value]) {
this.help.permissions.user = value;
} else {
throw new Error(`Tried setting the user permission of the command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a valid Discord.Permissions FLAG.`)
}
return false;
}
get botPermission() {
return this.help.permissions.bot;
}
set botPermission(value) {
if(Permissions.FLAGS[value]) {
this.help.permissions.bot = value;
} else {
throw new Error(`Tried setting the user permission of the command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a valid Discord.Permissions FLAG.`)
}
return false;
}
get rolePermission() {
return this.help.permissions.role;
}
set rolePermission(value) {
if(Permissions.FLAGS[value]) {
this.help.permissions.role = value;
} else {
throw new Error(`Tried setting the user permission of the command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a valid Discord.Permissions FLAG.`)
}
return false;
}
get developer() {
return this.help.developer;
}
set developer(value) {
if(typeof(value) === "boolean") {
this.help.developer = value;
} else {
throw new Error(`Tried setting developer value of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a boolean value.`);
}
}
get status() {
return this.help.status;
}
set status(value) {
if(typeof(value) === "boolean") {
this.help.status = value;
} else {
throw new Error(`Tried setting status value of command ${this.name} to (type: ${typeof(value)}) ${value}, which is not a boolean value.`)
}
}
}
module.exports.Command = Command
class Help {
#nameChanged = false
constructor(name) {
this.name = name;
this.alias = []
this.cooldown = 0
this.use_per_cooldown = 1
this.deleted = false
this.description = ""
this.permissions = {
bot: "",
user: "",
role: ""
}
this.developer = false
this.status = true
this.category = "developer"
}
get name() {
return this._name;
}
set name(name) {
if(!this.#nameChanged) {
this._name = name;
this.#nameChanged = true;
} else {
throw new Error(`Can't change command name from '${this.name}' to '${name}'. Command names are immutable`)
}
}
}