Removed the excessive connecting and closing of the MongoDb databases

This commit is contained in:
ION606
2022-07-31 10:11:55 +03:00
parent 6d8aa991b6
commit 14dd4e002a
10 changed files with 197 additions and 221 deletions
+2 -6
View File
@@ -11,8 +11,7 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
const singleCommandGames = ['ttt']; // Use when you have more single-player games
const musicCommandList = ['PLAY', 'PAUSE', 'RESUME', 'STOP', 'SKIP'];
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(async (err) => {
bot.mongoconnection.then(async (client) => {
if (battlecommandlist.indexOf(interaction.customId) != -1) {
await interaction.deferReply();
@@ -75,8 +74,6 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
resolveComplaint(interaction);
} //Button else ifs here
});
client.close();
}
//Menu Selection
@@ -85,8 +82,7 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
// const command = interaction.customId.substring(interaction.customId.indexOf('|'), interaction.customId.length - interaction.customId.indexOf('|'))
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(err => {
bot.mongoconnection.then(client => {
console.log(id);
if (id != interaction.user.id) { return; }