-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccess.js
38 lines (34 loc) · 1.1 KB
/
access.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
function checkAccess({ from, node, callback }) {
const name = /libera/.test(node.config.address)
? 'ACC'
: 'STATUS';
const ref = {};
const noticeHandler = (from, to, text) => {
if (text.toUpperCase().includes(name)) {
const [msg, nick, status] = text.trim().split(' ');
if (status == 3) {
callback();
} else {
callback(new Error('not identified'));
}
node.client.removeListener('notice', noticeHandler);
clearTimeout(ref.timer);
}
};
ref.timer = setTimeout(() => {
node.client.removeListener('notice', noticeHandler);
}, 3000);
node.client.addListener('notice', noticeHandler);
node.client.say('NickServ', `${name} ${from}`);
}
function auth({ callback, node, from }) {
checkAccess({ node, from, callback });
}
function sudo({ callback, node, from }) {
if (node.get('admins', []).includes(from)) {
checkAccess({ from, node, callback });
} else {
callback(new Error('no access'));
}
}
module.exports = { sudo, auth };