1 | const log = logger.withScope('handleCommand')
|
2 | const commands = require('./commands')
|
3 | const hasAdmin = user => discord.guilds.getAll('members').find(member => member.id === user.id).hasPermission('ADMINISTRATOR')
|
4 |
|
5 | module.exports = ({ content, author, channel }) => {
|
6 | log.info('Command received!')
|
7 | content = content.trim()
|
8 | let command = content.trim().split(' ')[0]
|
9 | const argv = content.replace(command, '').split(' ').map(str => str.trim()).filter(str => str)
|
10 | if (!command) command = 'help'
|
11 | if (!Object.keys(commands).includes(command)) return channel.send(`Command \`${command}\` not found!`)
|
12 | if (command === 'eval' && channel.type !== 'dm' && !hasAdmin(author)) return channel.send(`You have no permission!`)
|
13 | if (command === 'set' && argv[1] && argv[1].startsWith('`') && channel.type !== 'dm' && !hasAdmin(author)) return channel.send(`You have no permission!`)
|
14 | commands[command].run(argv, channel)
|
15 | }
|