woomy/modules/functions.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-29 07:45:09 +00:00
module.exports = client => {
2020-03-31 08:24:51 +00:00
client.permlevel = message => {
let permlvl = 0
const permOrder = client.config.permLevels.slice(0).sort((p, c) => p.level < c.level ? 1 : -1)
while (permOrder.length) {
const currentLevel = permOrder.shift()
if (message.guild && currentLevel.guildOnly) continue
if (currentLevel.check(message)) {
permlvl = currentLevel.level
break
}
}
return permlvl
}
2020-03-31 07:59:09 +00:00
client.loadCommand = (commandName) => {
try {
const props = require(`../commands/${commandName}`)
if (props.init) {
props.init(client)
}
client.commands.set(props.help.name, props)
2020-03-31 08:24:51 +00:00
// So commands can each have their own cooldown time
client.cooldown.set(props.help.name, new Map())
2020-03-31 07:59:09 +00:00
props.conf.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name)
})
return false
} catch (e) {
return `Failed to load ${commandName}: ${e}`
}
}
2020-03-29 07:45:09 +00:00
2020-03-31 07:59:09 +00:00
process.on('uncaughtException', (err) => {
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, 'g'), './')
client.logger.fatal(`Uncaught Exception: ${errorMsg}`)
process.exit(1)
})
process.on('unhandledRejection', err => {
client.logger.error(`Unhandled rejection: ${err}`)
})
2020-03-29 07:45:09 +00:00
}