forked from notunderctrl/discordjs-v14-series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
areCommandsDifferent.js
55 lines (48 loc) · 1.46 KB
/
areCommandsDifferent.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
module.exports = (existingCommand, localCommand) => {
const areChoicesDifferent = (existingChoices, localChoices) => {
for (const localChoice of localChoices) {
const existingChoice = existingChoices?.find(
(choice) => choice.name === localChoice.name
);
if (!existingChoice) {
return true;
}
if (localChoice.value !== existingChoice.value) {
return true;
}
}
return false;
};
const areOptionsDifferent = (existingOptions, localOptions) => {
for (const localOption of localOptions) {
const existingOption = existingOptions?.find(
(option) => option.name === localOption.name
);
if (!existingOption) {
return true;
}
if (
localOption.description !== existingOption.description ||
localOption.type !== existingOption.type ||
(localOption.required || false) !== existingOption.required ||
(localOption.choices?.length || 0) !==
(existingOption.choices?.length || 0) ||
areChoicesDifferent(
localOption.choices || [],
existingOption.choices || []
)
) {
return true;
}
}
return false;
};
if (
existingCommand.description !== localCommand.description ||
existingCommand.options?.length !== (localCommand.options?.length || 0) ||
areOptionsDifferent(existingCommand.options, localCommand.options || [])
) {
return true;
}
return false;
};