/
guildCooldown.js
63 lines (58 loc) · 1.98 KB
/
guildCooldown.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
const {Time} = require("../../utils/helpers/customParser.js");
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
let [time, errorObject = ""] = data.inside.splits;
let error;
let cooldown = await d.client.db.get(
d.client.db.tables[0],
"cooldown",
`${d.command.name}_${d.guild?.id || "dm"}`,
);
if (!cooldown) {
cooldown = Date.now() + Time.parse(time).ms;
d.client.db.set(
d.client.db.tables[0],
"cooldown",
`${d.command.name}_${d.guild?.id || "dm"}`,
cooldown,
);
} else if (Date.now() < cooldown.value) {
if (errorObject.trim() === "") {
} else {
const {object, humanize, toString} = Time.format(cooldown.value - Date.now());
errorObject = errorObject
.replaceAll("%time%", humanize())
.replaceAll("%year%", object.years)
.replaceAll("%month%", object.months)
.replaceAll("%week%", object.weeks)
.replaceAll("%day%", object.days)
.replaceAll("%hour%", object.hours)
.replaceAll("%min%", object.minutes)
.replaceAll("%sec%", object.seconds)
.replaceAll("%ms%", object.ms)
.replaceAll("%fullTime%", toString());
errorObject = await d.util.errorParser(errorObject, d);
d.aoiError.makeMessageError(
d.client,
d.channel,
errorObject.data ?? errorObject,
errorObject.options,
d
);
}
error = true;
} else {
cooldown = Date.now() + Time.parse(time).ms;
d.client.db.set(
d.client.db.tables[0],
"cooldown",
`${d.command.name}_${d.guild?.id || "dm"}`,
cooldown,
);
}
return {
code: d.util.setCode(data),
error,
};
};