Files

94 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2022-07-30 16:09:49 +02:00
// Import config and export
const config = require('./config');
2022-07-30 16:19:58 +02:00
const mongoose = require('mongoose');
2022-08-08 10:55:08 +02:00
const colors = require('colors');
2022-07-30 16:09:49 +02:00
// Connect to mongoDB
try {
2022-07-30 16:19:58 +02:00
mongoose.connect(config.mongodb);
2022-07-30 16:09:49 +02:00
} catch (err) {
2022-07-30 16:19:58 +02:00
console.log(err);
2022-08-08 10:55:08 +02:00
console.log(colors.red("MongoDB: "), 'Error connecting to mongoDB');
2022-07-30 16:09:49 +02:00
process.exit(1);
}
2022-08-02 18:14:51 +02:00
// Create discord.js client
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
2022-08-16 16:51:42 +02:00
GatewayIntentBits.DirectMessages
2022-08-02 18:14:51 +02:00
]
});
2022-08-05 20:09:35 +02:00
const bsl = new Client({
intents: [
GatewayIntentBits.Guilds,
2022-08-10 20:17:21 +02:00
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
2022-08-05 20:09:35 +02:00
]
})
2022-08-02 18:14:51 +02:00
client.config = config;
2022-08-05 20:09:35 +02:00
bsl.config = config
2022-08-02 18:14:51 +02:00
// Set intents
client.on('ready', () => {
2022-08-08 10:55:08 +02:00
console.log(colors.green("Website: "), 'Website bot is ready!');
2022-08-05 14:59:15 +02:00
require('./website')
2022-08-06 18:16:45 +02:00
require('./website/bot')
2022-08-08 10:55:08 +02:00
require('./bsl')
2022-08-02 18:14:51 +02:00
});
// Login
client.login(client.config.bot.token);
2022-08-05 20:09:35 +02:00
bsl.login(bsl.config.bot.bsl.token);
2022-08-15 13:33:14 +02:00
bsl.on('rateLimit', (info) => {
console.log(`Rate limit hit ${info.timeDifference ? info.timeDifference : info.timeout ? info.timeout : 'Unknown timeout '}`)
})
2022-08-02 18:14:51 +02:00
// Node Error Handler
process.on('uncaughtException', function (err) {
console.log(err);
console.log('Uncaught Exception');
client.channels.cache.get(client.config.bot.channels.error).send(`Uncaught Exception: ${err}`);
});
// Node Exit Handler
process.on('exit', function (code) {
console.log('About to exit with code:', code);
client.channels.cache.get(client.config.bot.channels.error).send(`About to exit with code: ${code}`);
});
// Node Unhandled Rejection Handler
process.on('unhandledRejection', function (err) {
console.log(err);
console.log('Unhandled Rejection');
client.channels.cache.get(client.config.bot.channels.error).send(`Unhandled Rejection: ${err}`);
});
// Node Warning Handler
process.on('warning', function (warning) {
console.log(warning);
console.log('Warning');
client.channels.cache.get(client.config.bot.channels.error).send(`Warning: ${warning}`);
});
// Node Error Handler
process.on('error', function (err) {
console.log(err);
console.log('Error');
client.channels.cache.get(client.config.bot.channels.error).send(`Error: ${err}`);
});
// Node Disconnect Handler
process.on('disconnect', function (err) {
console.log(err);
console.log('Disconnect');
client.channels.cache.get(client.config.bot.channels.error).send(`Disconnect: ${err}`);
});
2022-07-30 16:09:49 +02:00
//export config
module.exports.config = config;
module.exports.mongoose = mongoose;
2022-08-02 18:14:51 +02:00
module.exports.client = client;
2022-08-05 20:09:35 +02:00
module.exports.bsl = bsl;
2022-08-06 18:16:45 +02:00
module.exports.embed = EmbedBuilder;
global.client = client;
global.bsl = bsl;
2022-08-10 20:17:21 +02:00
global.config = config;
global.discord = require('discord.js');