-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermissionManager.js
59 lines (58 loc) · 1.67 KB
/
PermissionManager.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
module.exports = Paper => class PermissionManager {
constructor() {
this.permissionLevels = [
{
name: 'infinity',
check: () => false
},
{
name: 'master',
check: ({ client, nick }) => client.paperConfig.master === nick
},
{
name: 'owner',
check: ({ client, nick, channel }) => new Promise(resolve => {
client.once(`names${channel}`, nicks => resolve(nicks[nick] === '~'))
client.send('NAMES', channel)
})
},
{
name: 'admin',
check: ({ client, nick, channel }) => new Promise(resolve => {
client.once(`names${channel}`, nicks => resolve(nicks[nick] === '&'))
client.send('NAMES', channel)
})
},
{
name: 'operator',
check: ({ client, nick, channel }) => new Promise(resolve => {
client.once(`names${channel}`, nicks => resolve(nicks[nick] === '@'))
client.send('NAMES', channel)
})
},
{
name: 'half-op',
check: ({ client, nick, channel }) => new Promise(resolve => {
client.once(`names${channel}`, nicks => resolve(nicks[nick] === '%'))
client.send('NAMES', channel)
})
},
{
name: 'voiced',
check: ({ client, nick, channel }) => new Promise(resolve => {
client.once(`names${channel}`, nicks => resolve(nicks[nick] === '+'))
client.send('NAMES', channel)
})
},
{
name: 'none',
check: () => true
}
]
}
async get(data) {
for (const level of this.permissionLevels) {
if (await level.check(data)) return level.name
}
}
}