-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
78 lines (61 loc) · 2.42 KB
/
plugin.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
const units = function iife () {
const seconds = ["seconds", "second", "s"];
const minutes = ["minutes", "minute", "mins", "min", "m"];
const hours = ["hours", "hour", "h"];
const days = ["days", "day", "d"];
const units = new Map();
seconds.forEach(function (unit) {
units.set(unit, 1e3);
});
minutes.forEach(function (unit) {
units.set(unit, 60e3);
});
hours.forEach(function (unit) {
units.set(unit, 3600e3);
});
days.forEach(function (unit) {
units.set(unit, 86400e3);
});
return units;
}();
module.exports = {
init: function (client, _deps) {
return {
handlers: {
"!remindme": function (command) {
const scalar = Number(command.args[0]);
const unit = command.args[1];
const message = command.args.slice(2).join(" ");
if (Number.isNaN(scalar)) {
return "Syntax: !remindme <time> <unit> <messag> | Note: <time> must be a number.";
}
if (scalar <= 0) {
return "Syntax: !remindme <time> <unit> <messag> | Note: <time> must be positive.";
}
const unitMultiplier = units.get(unit);
if (unitMultiplier === undefined) {
return `Unknown unit. Use one of ${Object.keys(units).join(", ")}.`;
}
if (message.length === 0) {
return "Syntax: !remindme <time> <unit> <messag> | Note: <message> cannot be empty.";
}
if (scalar * unitMultiplier > 86400e3 * 30) {
return "Can only remind you in less than 30 days."
}
setTimeout(function () {
client.say(command.nickname, "You wanted me to remind you that:");
client.say(command.nickname, message);
}, Math.floor(scalar * unitMultiplier));
return {
query: true,
message: `Set to remind you in ${command.args[0]} ${command.args[1]}.`
};
}
},
"help": {
"remindme": "!remindme <time> <unit> <message>"
},
"commands": ["remindme"]
};
}
};