This repository has been archived by the owner on Jan 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmessage.js
54 lines (44 loc) · 1.99 KB
/
message.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
const structures = require('../structures')
const translations = require('../translations')
const config = require('../config')
const commands = require('../commands')
module.exports = async (client, message) => {
if (message.channel.type === 'dm') return
const permissions = await structures.permissions.accumulate(message.member)
const settings = {
user: await structures.settings.get.user(message.member.id),
guild: await structures.settings.get.guild(message.guild.id)
}
message.command = await message.content.replace(config.app.ux.prefix, '').split(' ').filter(a => a !== '')
message.parameters = message.command.splice(1)
const basicCondition =
(message.content.startsWith(settings.guild.prefix)) &&
(
!config.app.ux.basicPermissions.length ||
config.app.ux.basicPermissions.every(permission => message.guild.me.permissions.toArray().includes(permission))
) &&
/*
NOTE: You may change rule like below to support only one basic permissions:
(message.guild.me.hasPermission('SEND_MESSAGES'))
*/
(commands[message.command])
if (!basicCondition) return
const filters = {
missingPermission: !structures.permissions.compare(permissions, commands[message.command].properties.permission.flag)
}
const filtered = await structures.functions.findKeyByValue(filters, false)
if (filtered) return message.reply(translations[settings.user.language].general.filtered[filtered])
const opts = {
permissions,
settings,
translations: translations[settings.user.language].commands[commands[message.command].properties.name]
}
opts.translations = opts.translations || {}
opts.translations._metadata = {
language: translations[settings.user.language].language,
languageNative: translations[settings.user.language].languageNative,
languageCode: translations[settings.user.language].languageCode,
countryCode: translations[settings.user.language].countryCode
}
commands[message.command].execute(client, message, opts)
}