Skip to content

Commit

Permalink
logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Doze42 committed Oct 18, 2022
1 parent 7baceb4 commit 62e2f8f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions assets/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"botver": "3.0 (Beta Build 170)",
"botver": "3.0 (Release Candidate 1)",
"release": 2,
"debugMode": 1,
"cmdCD": 7000,
Expand All @@ -16,7 +16,7 @@
"database": "MCSS",
"options": {"enableArithAbort": false}},
"token": "NzkwMDc1Nzk2MDQyOTQwNDQ4.Gfni2-.lpUr73JRyr-JFs20kR0Yg513-SW10H2z4hg04M",
"activity": {"text": "put something here idk", "type": "WATCHING"},
"activity": {"text": "for slash commands | Back and better than ever!", "type": "WATCHING"},
"supportServer": "799882620913319957",
"suggestionChannel": "799890506757963857",
"expressPort": 4889,
Expand Down
6 changes: 3 additions & 3 deletions assets/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
"lang": "en",
"liveElementCount": 0,
"limits": {
"liveElements": 2000,
"savedServers": 5,
"savedEmbedTemplates": 7
"liveElements": 25,
"savedServers": 10,
"savedEmbedTemplates": 10
},
"ephemeral": {
"statusPanel": false,
Expand Down
20 changes: 16 additions & 4 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ global.pool.connect();
global.statusCache = new Map();
var statusQueue = [];

const chalk = require ('chalk')
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const DBL = require('dblapi.js');
Expand Down Expand Up @@ -58,21 +59,32 @@ module.exports = class extends BaseCluster {
launch() {
this.client.login(global.botConfig.configs[global.botConfig.release].token);
var client = this.client
console.info('Spawning Shard...')

global.toConsole = { //Categorized Console Logging
log: function(msg){console.log(chalk.magenta('[Shard ' + client.shard.id + '] ') + chalk.bgBlue('[log]') + ' ' + msg)},
info: function(msg){console.log(chalk.magenta('[Shard ' + client.shard.id + '] ') + chalk.bgGreen('[info]') + ' ' + msg)},
error: function(msg){console.log(chalk.magenta('[Shard ' + client.shard.id + '] ') + chalk.bgRed('[error]') + ' ' + msg)},
debug: function(msg){console.log(chalk.magenta('[Shard ' + client.shard.id + '] ') + chalk.bgRed('[debug]') + ' ' + msg)}
}

global.toConsole.log('Spawning Shard...')

sql.on('error', err => {
console.log('SQL Error: ' + err, 'error');
})

process.on('unhandledRejection', err => {
process.on('unhandledRejection', err => { //Logs error and restarts shard on unhandledRejection
global.toConsole.error('Reloading Shard: ' + err);
try{fs.writeFileSync('./logs/shardCrash/' + new Date().toISOString() + '.log', err)}
catch(err){console.log(err)
global.toConsole.error('Failed to write error log')}
client.shard.restart(client.shard.id);
});

client.on('rateLimit', (info) => {
global.toConsole.error(`Rate limit hit ${info.timeDifference ? info.timeDifference : info.timeout ? info.timeout: 'Unknown timeout '}`)
})

throw 'crash'
client.on("ready", async function(){
global.toConsole.info('Successfully logged in using Token ' + botConfig.release + ' at ' + new Date())
if(global.botConfig.enableMessageEdit || global.botConfig.enableChannelEdit || global.botConfig.enableNotifer){liveStatus()} //starts live update loop
Expand Down Expand Up @@ -100,7 +112,7 @@ try {
else if (interaction.commandName == 'help'){commands.help.run(client, interaction, stringJSON);}
//else if (interaction.commandName == 'autocnl'){commands.autocnl.run(client, interaction, stringJSON);}
else if (interaction.commandName == 'test'){
console.log(!client.guilds.cache.has(interaction.guildId))

}
}
catch (err){global.toConsole.error("Interaction Failed: " + err)}
Expand Down
2 changes: 1 addition & 1 deletion funcs/queryServer.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ const { join } = require('path');
const { Client, Intents } = require('discord.js');
const chalk = require ('chalk')

global.toConsole = {
log: function(msg, shardID = 'Unknown'){console.log(chalk.magenta('[Shard ' + shardID + '] ') + chalk.bgBlue('[log]') + ' ' + msg)},
info: function(msg, shardID = 'Unknown'){console.log(chalk.magenta('[Shard ' + shardID + '] ') + chalk.bgGreen('[info]') + ' ' + msg)},
error: function(msg, shardID = 'Unknown'){console.log(chalk.magenta('[Shard ' + shardID + '] ') + chalk.bgRed('[error]') + ' ' + msg)},
debug: function(msg, shardID = 'Unknown'){console.log(chalk.magenta('[Shard ' + shardID + '] ') + chalk.bgRed('[debug]') + ' ' + msg)}
}
global.shardCrashCount = 0;

setInterval(function(){global.shardCrashCount = 0}, 86400000) //resets shard reconnect count daily

const sharder = new ShardingManager(join(__dirname, 'bot'), {
clusterCount: 1,
Expand All @@ -20,4 +17,8 @@ const sharder = new ShardingManager(join(__dirname, 'bot'), {

sharder.spawn();

sharder.on('error', (err) => {console.log('Sharder Error: ' + err)});
sharder.on('error', (err) => {
global.shardCrashCount++;
if (global.shardCrashCount > 500){process.exit(1)} //Kills process to avoid shard reconnection ratelimit
console.log('Sharder Error: ' + err)
});
Empty file added logs/shardCrash/.gitkeep
Empty file.

0 comments on commit 62e2f8f

Please sign in to comment.