Error handling: DB connection & RustCommits

master
Cristiano Pires 2 years ago
parent d1cad5afa5
commit 406c376408

@ -582,6 +582,7 @@ class rustCommits
for(var j = 0; j<this.channels.length; j++) for(var j = 0; j<this.channels.length; j++)
{ {
if(!this.channels[j].lastid) this.channels[j].lastid = 0;
const Pos = Res.map(e => e.id).indexOf(this.channels[j].lastid); const Pos = Res.map(e => e.id).indexOf(this.channels[j].lastid);
Res.splice(Pos, Res.length-Pos); Res.splice(Pos, Res.length-Pos);
for(var i = Res.length-1; i>0; i--) for(var i = Res.length-1; i>0; i--)
@ -590,7 +591,6 @@ class rustCommits
{ {
send( send(
{ {
Author:Res[i].user.name, Author:Res[i].user.name,
Avatar:Res[i].user.avatar, Avatar:Res[i].user.avatar,
Time:Res[i].created.split("T")[1]+ " of "+ Res[i].created.split("T")[0], Time:Res[i].created.split("T")[1]+ " of "+ Res[i].created.split("T")[0],
@ -644,7 +644,7 @@ class rustCommits
if(!content||!content.embeds||!content.embeds.length>0) return 0; if(!content||!content.embeds||!content.embeds.length>0) return 0;
return parseInt(content.embeds[0].fields[1].value) return parseInt(content.embeds[0].fields[1].value)
}) })
channel.lastid = lastid; channel['lastid'] = lastid;
} }
} }
return channels; return channels;

@ -56,10 +56,19 @@ const bot = new Client({ intents: [
}); });
bot.login(process.env.discord_token); bot.login(process.env.discord_token);
function connectToDB()
{
mongoose.connect(mongoDB)
.catch(err=>
{
console.log('Server: Error: There was an Error with the connection to the database, attempting to restart it.', err)
connectToDB();
});
}
bot.on('ready', () => bot.on('ready', () =>
{ {
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose.connect(mongoDB).catch(err=>console.log(err));
console.log(`--------------------------\n ${bot.user.tag.split('#')[0]} \n Ready \n on `+bot.guilds.cache.size+" guilds \n serving "+bot.users.cache.size+" users \n--------------------------") console.log(`--------------------------\n ${bot.user.tag.split('#')[0]} \n Ready \n on `+bot.guilds.cache.size+" guilds \n serving "+bot.users.cache.size+" users \n--------------------------")
bot.user.setPresence({ bot.user.setPresence({
activities: [{ name: `!help`, type: ActivityType.Listening }], activities: [{ name: `!help`, type: ActivityType.Listening }],

Loading…
Cancel
Save