-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
87 lines (68 loc) · 2.4 KB
/
plugin.js
File metadata and controls
87 lines (68 loc) · 2.4 KB
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
var format = require("util").format;
var noticeResponse = function(msg) {
return {
intent: 'notice',
query: true,
message: msg
};
}
var TennuUserAlert = {
configDefaults: {
"user-alert": {
"notice": true
}
},
init: function(client) {
const helps = {
"useralert": [
"{{!}}useralert <target>",
"Alerts a user when another user talks in the channel."
]
};
var memDb = require("./lib/memory-database");
var userAlertConfig = client.config("user-alert");
var alertmethod = "";
if(userAlertConfig.notice){
alertmethod = "notice";
} else {
alertmethod = "say";
}
return {
handlers: {
"privmsg": function(message) {
var alerts = memDb.find(message.nickname);
if (alerts.length > 0) {
alerts.forEach(function(alert){
var message = format("At your request, we are notifying you that %s has returned.", alert.target);
if(alert.note){
message += format(" Note: ", alert.note);
}
client[alertmethod](alert.setter, message);
});
}
},
"!useralert": function(message) {
if (!message.args[0] || message.args[0].length < 1) {
return noticeResponse("Invalid target. Usage is: `!useralert <target>`");
}
var target = message.args[0]
var note = null;
// Do we have a note?
if(message.args.length > 1){
note = message.args.slice(1, message.args.length).join(' ');
}
memDb.add(message.nickname, target, note);
return noticeResponse(format("We will ping you when %s talks next.", target));
},
},
help: {
"useralert": helps.useralert
},
commands: ["useralert"],
testExports: {
memDb: memDb
}
}
}
};
module.exports = TennuUserAlert;