woomy/index.js

96 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-03-29 07:45:09 +00:00
// Woomy version 2
// Copyright 2020 mudkipscience
// Check node.js version
2020-03-30 16:01:13 +00:00
if (Number(process.version.slice(1).split('.')[0]) < 12) {
2020-03-29 07:45:09 +00:00
console.log('NodeJS 12.0.0 or higher is required. Please update NodeJS on your system.')
process.exit()
}
// Load environment variables / config
2020-03-29 07:45:09 +00:00
const fs = require('fs')
2020-03-31 07:59:09 +00:00
const colors = require('colors')
2020-03-30 16:01:13 +00:00
const Discord = require('discord.js')
const client = new Discord.Client({ disabledEvents: ['TYPING_START'] })
2020-03-29 07:45:09 +00:00
2020-03-31 04:09:50 +00:00
require('./modules/functions')(client)
2020-03-31 07:59:09 +00:00
client.logger = require('tracer').colorConsole({
format: [
'{{timestamp}} <{{title}}> ({{file}}) {{message}}'
],
dateformat: 'dd-mm-yyyy HH:MM:ss',
methods: ['log', 'debug', 'info', 'ready', 'warn', 'error', 'fatal'],
filters: [{
log: colors.white,
debug: colors.magenta,
info: colors.cyan,
ready: colors.green,
warn: colors.yellow,
error: colors.red,
fatal: [colors.red, colors.bold]
}]
})
2020-03-31 04:09:50 +00:00
2020-03-29 07:45:09 +00:00
if (fs.existsSync('./.env') === false) {
2020-03-31 07:59:09 +00:00
client.logger.fatal('The .env file is missing! Please create a .env file.')
2020-03-29 07:45:09 +00:00
process.exit()
}
if (fs.existsSync('./config.js') === false) {
2020-03-31 07:59:09 +00:00
client.logger.fatal('The config.js file is missing! Please create a config.js file.')
2020-03-29 07:45:09 +00:00
process.exit()
}
require('dotenv').config()
2020-03-31 04:09:50 +00:00
client.config = require('./config')
2020-03-29 07:45:09 +00:00
2020-03-30 16:01:13 +00:00
// Command/alias cache
client.commands = new Discord.Collection()
client.aliases = new Discord.Collection()
2020-03-29 07:45:09 +00:00
// Initialization function
2020-03-29 07:45:09 +00:00
const init = async () => {
// Load modules
2020-03-30 16:01:13 +00:00
// Load events
fs.readdir('./events', (err, files) => {
2020-03-31 04:09:50 +00:00
if (err) {}
2020-03-31 07:59:09 +00:00
client.logger.info(`Loading ${files.length} events.`)
files.forEach(file => {
2020-03-31 07:59:09 +00:00
if (!file.endsWith('.js')) {
return
}
2020-03-31 04:09:50 +00:00
const event = require(`./events/${file}`)
client.on(file.substr(0, file.length - 3), event.bind(null, client))
2020-03-30 16:01:13 +00:00
})
})
// Load commands
2020-03-31 07:59:09 +00:00
fs.readdir('./commands', (err, files) => {
if (err) {}
client.logger.info(`Loading ${files.length} commands.`)
files.forEach(file => {
if (!file.endsWith('.js')) {
return
}
const response = client.loadCommand(file)
if (response) {
client.logger.error(response)
}
})
})
2020-03-30 16:01:13 +00:00
// Level cache
2020-03-31 04:09:50 +00:00
client.levelCache = {}
2020-03-30 16:01:13 +00:00
for (let i = 0; i < client.config.permLevels.length; i++) {
2020-03-31 04:09:50 +00:00
const thisLevel = client.config.permLevels[i]
client.levelCache[thisLevel.name] = thisLevel.level
2020-03-30 16:01:13 +00:00
}
2020-03-31 04:09:50 +00:00
// Login into Discord
2020-03-30 16:01:13 +00:00
client.login(process.env.TOKEN)
2020-03-29 07:45:09 +00:00
}
2020-03-30 16:01:13 +00:00
init()