-
Notifications
You must be signed in to change notification settings - Fork 0
/
essentials.js
64 lines (58 loc) · 1.62 KB
/
essentials.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
const CastAPI = require('castapi')
const Case = require('./models/case')
const MuteSettings = {
name: 'Muted',
color: '#ff0000',
permissions: ['READ_MESSAGES', 'CONNECT', 'READ_MESSAGE_HISTORY'],
hoist: false,
mentionable: false
}
class Essentials extends CastAPI.Plugin {
constructor (cast, metadata, _path) {
super(cast, metadata, __dirname)
this.muteSettings = MuteSettings
this.mutedUpdate().then(() => {
this.log('Essentials plugin was enabled.')
})
}
createCase (caseType, issuerID, issueeID, message = null) {
return new Promise((resolve, reject) => {
var data = {caseType, issuerID, issueeID}
if (message) data.message = message
var newCase = new Case(data)
newCase.save().then(resolve).catch(reject)
})
}
/**
*
* @param {Guild[]} guilds
*/
mutedUpdate (guilds = this.cast.client.guilds.array()) {
return new Promise((resolve, reject) => {
guilds.forEach(guild => {
var mRole = null
guild.roles.some(role => {
if (role.name === MuteSettings.name) return !!(mRole = role)
})
if (!mRole) {
guild.createRole(MuteSettings).then(role => {
this.updateMutePermissions(guild, role)
})
} else this.updateMutePermissions(guild, mRole)
})
resolve()
})
}
updateMutePermissions (guild, role) {
return new Promise((resolve, reject) => {
guild.channels.forEach(channel => {
channel.overwritePermissions(role, {
SEND_MESSAGES: false,
SPEAK: false
})
})
resolve()
})
}
}
module.exports = Essentials