2020-03-29 07:45:09 +00:00
|
|
|
// Woomy version 2
|
|
|
|
// Copyright 2020 mudkipscience
|
|
|
|
|
2020-03-30 08:47:55 +00:00
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:40:51 +00:00
|
|
|
// Libraries
|
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-04-02 08:17:42 +00:00
|
|
|
const isDocker = require('is-docker')
|
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 11:36:35 +00:00
|
|
|
// Logger
|
2020-03-31 07:59:09 +00:00
|
|
|
client.logger = require('tracer').colorConsole({
|
|
|
|
format: [
|
2020-04-03 00:07:51 +00:00
|
|
|
'{{timestamp}} | {{title}} | {{file}}:{{line}} | {{message}}',
|
2020-03-31 08:24:51 +00:00
|
|
|
{
|
2020-04-03 00:07:51 +00:00
|
|
|
debug: `{{timestamp}} | ${'{{title}}'.magenta} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
log: `{{timestamp}} | ${'{{title}}'.white} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
info: `{{timestamp}} | ${'{{title}}'.cyan} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
ready: `{{timestamp}} | ${'{{title}}'.green} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
warn: `{{timestamp}} | ${'{{title}}'.yellow} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
error: `{{timestamp}} | ${'{{title}}'.red} | {{file}}:{{line}} | {{message}}`,
|
|
|
|
fatal: `{{timestamp}} | ${'{{title}}'.red.bold} | {{file}}:{{line}} | {{message}}`
|
2020-03-31 08:24:51 +00:00
|
|
|
}
|
2020-03-31 07:59:09 +00:00
|
|
|
],
|
2020-04-01 08:33:02 +00:00
|
|
|
dateformat: 'yyyy-mm-dd"T"HH:MM:ss',
|
2020-03-31 07:59:09 +00:00
|
|
|
methods: ['log', 'debug', 'info', 'ready', 'warn', 'error', 'fatal'],
|
2020-03-31 15:45:45 +00:00
|
|
|
filters: [colors.white]
|
2020-03-31 07:59:09 +00:00
|
|
|
})
|
2020-03-31 04:09:50 +00:00
|
|
|
|
2020-04-03 00:07:51 +00:00
|
|
|
// Check to make sure config exists
|
2020-03-29 07:45:09 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-03-31 04:09:50 +00:00
|
|
|
client.config = require('./config')
|
2020-04-01 08:33:02 +00:00
|
|
|
require('./modules/functions')(client)
|
|
|
|
require('./modules/music')(client)
|
|
|
|
require('./modules/botlists')(client)
|
2020-03-29 07:45:09 +00:00
|
|
|
|
2020-04-02 08:17:42 +00:00
|
|
|
// Logs into Discord as WoomyDev if a docker container is not detected. Delete this if self-hosting.
|
|
|
|
if (isDocker() === true) {
|
2020-03-31 16:37:17 +00:00
|
|
|
client.devmode = true
|
|
|
|
client.logger.warn('Running in development mode.')
|
|
|
|
} else {
|
|
|
|
client.devmode = false
|
|
|
|
}
|
|
|
|
|
2020-04-01 08:33:02 +00:00
|
|
|
client.levelCache = {}
|
2020-03-30 16:01:13 +00:00
|
|
|
client.commands = new Discord.Collection()
|
2020-03-31 08:24:51 +00:00
|
|
|
client.cooldown = new Discord.Collection()
|
2020-03-30 16:01:13 +00:00
|
|
|
client.aliases = new Discord.Collection()
|
2020-03-29 07:45:09 +00:00
|
|
|
|
2020-03-30 08:47:55 +00:00
|
|
|
// Initialization function
|
2020-03-29 07:45:09 +00:00
|
|
|
const init = async () => {
|
2020-04-01 08:33:02 +00:00
|
|
|
// Command handler
|
|
|
|
fs.readdir('./commands', (err, files) => {
|
2020-03-31 11:43:58 +00:00
|
|
|
if (err) {
|
2020-04-01 08:33:02 +00:00
|
|
|
client.logger.fatal('Failed to get files in commands directory: ' + err)
|
2020-03-31 15:45:45 +00:00
|
|
|
process.exit()
|
2020-04-02 08:17:42 +00:00
|
|
|
}
|
2020-04-01 08:33:02 +00:00
|
|
|
client.logger.info(`Loading ${files.length} commands.`)
|
2020-03-30 08:47:55 +00:00
|
|
|
files.forEach(file => {
|
2020-03-31 07:59:09 +00:00
|
|
|
if (!file.endsWith('.js')) {
|
|
|
|
return
|
|
|
|
}
|
2020-04-01 08:33:02 +00:00
|
|
|
const response = client.loadCommand(file)
|
|
|
|
if (response) {
|
|
|
|
client.logger.error(response)
|
|
|
|
}
|
2020-03-30 16:01:13 +00:00
|
|
|
})
|
|
|
|
})
|
2020-03-30 08:47:55 +00:00
|
|
|
|
2020-04-01 08:33:02 +00:00
|
|
|
// Event handler
|
|
|
|
fs.readdir('./events', (err, files) => {
|
2020-03-31 11:43:58 +00:00
|
|
|
if (err) {
|
2020-04-01 08:33:02 +00:00
|
|
|
client.logger.fatal('Failed to get files in events directory: ' + err)
|
2020-03-31 15:45:45 +00:00
|
|
|
process.exit()
|
2020-04-02 08:17:42 +00:00
|
|
|
}
|
2020-04-01 08:33:02 +00:00
|
|
|
client.logger.info(`Loading ${files.length} events.`)
|
2020-03-31 07:59:09 +00:00
|
|
|
files.forEach(file => {
|
|
|
|
if (!file.endsWith('.js')) {
|
|
|
|
return
|
|
|
|
}
|
2020-04-01 08:33:02 +00:00
|
|
|
const event = require(`./events/${file}`)
|
|
|
|
client.on(file.substr(0, file.length - 3), event.bind(null, client))
|
2020-03-31 07:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
2020-03-30 08:52:08 +00:00
|
|
|
|
2020-04-01 08:33:02 +00:00
|
|
|
// Cache client permissions
|
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
|
|
|
|
2020-04-01 08:33:02 +00:00
|
|
|
// Log into Discord
|
2020-04-03 00:07:51 +00:00
|
|
|
if (client.devmode !== true) {
|
|
|
|
client.login(client.config.token)
|
2020-03-31 16:37:17 +00:00
|
|
|
} else {
|
2020-04-03 00:07:51 +00:00
|
|
|
client.login(client.config.token_dev)
|
2020-03-31 16:37:17 +00:00
|
|
|
}
|
2020-03-29 07:45:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 16:01:13 +00:00
|
|
|
init()
|