-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
65 lines (52 loc) · 2.26 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
var format = require('util').format;
var TennuBan = {
name: 'ban',
role: 'ban',
requiresRoles: ['admin'],
configDefaults: {
'ban': {
'denied-response': {
intent: 'notice',
query: true,
message: 'Permission denied, you are banned from running bot commands.'
}
}
},
init: function(client, imports) {
var banConfig = client.config('ban');
var deniedResponse = banConfig['denied-response'];
var ban = require('./lib/ban')(imports.admin.initalizeAdmins(client.config('banned')), imports.admin.initalizeAdmins, imports.admin.isAdmin);
return {
commandMiddleware: function(command) {
// Admin override
return imports.admin.isAdmin(command.hostmask)
.then(function(isAdmin) {
if (isAdmin) {
return command; // user is an admin.
}
// Banned check
return imports.admin.isAdmin(command.hostmask, {
customAdmins: ban.banned
})
.then(function(isBanned) {
if (!isBanned) {
return command; // not banned
}
var bannedUser = ban.getFirstHostname(command.hostmask.hostname);
if (!bannedUser) {
throw new Error('User is banned, but unable to find a match for the hostname.');
}
// Temp ban check
if (bannedUser.hasOwnProperty('expires') && !ban.isExpired(bannedUser)) {
return command;
}
client.note('PluginAdmin', format('banned user "%s" tried to run command "%s"', command.nickname, command.command));
return deniedResponse;
});
});
},
exports: ban
};
}
};
module.exports = TennuBan;