-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.75 KB
/
index.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
'use strict';
const moment = require(`moment`);
class remind {
constructor() {
this.name = `remind`;
this.displayname = `Remind`;
this.description = `Set reminders for yourself`;
}
init() {
this.registerCronHandler(`sendMessage`, (params) => {
this.sendMessage(params.user, params.interfaceName, `Reminder to ${params.reminditem}`);
});
this.listen(
`(set reminder|remind me) to (:<reminder>.+) in (:<interval>.+?) (:<time_unit>(second|minute|hour|day)[s]*)`,
`standard`,
(from, interfaceName, params) => {
return this.addReminder(params.interval, params.time_unit, params.reminder, interfaceName, from);
}
);
this.listen(
`remind me in (:<interval>.+?) (:<time_unit>(second|minute|hour|day)[s]*) to (:<reminder>.+)`,
`standard`,
(from, interfaceName, params) => {
return this.addReminder(params.interval, params.time_unit, params.reminder, interfaceName, from);
}
);
this.listen(
`cancel reminder (:<reminder_id>[0-9]+)`,
`standard`,
(from, interfaceName, params) => {
this.removeCronJob(params.reminder_id);
return `Reminder with ID ${params.reminder_id} removed`;
}
);
}
addReminder(timevalue, timeunit, reminditem, interfaceName, user) {
const crontime = moment().add(timevalue, timeunit).toDate();
return this.addCronJob(crontime, `sendMessage`, {
reminditem,
interfaceName,
user
}).then((id) => {
return `Reminder added with ID ${id}`;
});
}
}
module.exports = remind;