-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
68 lines (58 loc) · 2.35 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const Discord = require("discord.js");
const Enmap = require("enmap");
const fs = require("fs");
const request = require('request');
const client = new Discord.Client();
const config = require("./config.json");
client.config = config;
Logger = require('./modules/logger');
client.logger = new Logger('main');
client.commands = new Enmap();
client.aliases = new Enmap();
const url = "https://raw.githubusercontent.com/hydrostaticcog/Grick-Heart/master/package.json";
let options = {json: true};
let GHversion = require('./package.json')
client.logger.info(`Starting Grick Heart version ${GHversion.version} running Node version ${(Number(process.version.slice(1).split(".")[0]))}`);
if (Number(process.version.slice(1).split(".")[0]) < 12) {
let errorN = new Error("Node 12.0.0 or higher is required. Update Node on your system.");
client.logger.error(errorN)
return;
}
request(url, options, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
let GHversion = require("./package.json")
if (body.version > GHversion.version) {
logger.info("**************** YOU ARE RUNNING A OLD VERSION OF GRICK HEART ****************")
logger.info(`******* YOU ARE RUNNING VERSION ${GHversion.version}. LATEST VERSION IS VERSION ${body.version} *******`)
}
if (body.version < GHversion.version) {
logger.info("***************** YOU ARE RUNNING A BETA VERSION OF GRICK HEART ******************")
logger.info(`*** THIS VERSION COULD HAVE FATAL BUGS AND IS NOT VALIDATED FOR PRODUCTION USE ***`)
}
}
})
fs.readdir("./events/", (err, files) => {
client.logger.info(`Attempting to load events`);
if (err) return client.logger.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
client.logger.info(`Successfully loaded events!`);
});
fs.readdir("./commands/", (err, files) => {
client.logger.info(`Attempting to load commands`);
if (err) return client.logger.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
client.commands.set(commandName, props);
});
client.logger.info(`Successfully loaded commands!`);
});
client.login(config.token);