Attempt at fixing user sessions not closing which left the bot in a busy state
This commit is contained in:
parent
91ad04aeb3
commit
5ea2e73942
@ -1,6 +1,8 @@
|
|||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const jsonfile = require('jsonfile');
|
const jsonfile = require('jsonfile');
|
||||||
|
const util = require('util');
|
||||||
|
const readFile = util.promisify(jsonfile.readFile);
|
||||||
let session2;
|
let session2;
|
||||||
let isProcessing = false; // Semaphore variable
|
let isProcessing = false; // Semaphore variable
|
||||||
|
|
||||||
@ -25,8 +27,8 @@ module.exports = {
|
|||||||
// Set the semaphore to true
|
// Set the semaphore to true
|
||||||
isProcessing = true;
|
isProcessing = true;
|
||||||
|
|
||||||
await jsonfile.readFile(file, async function (err, session) {
|
try {
|
||||||
if (err) return interaction.editReply('Please create a session using /create-session.');
|
const session = await readFile(file);
|
||||||
|
|
||||||
session2 = session.id;
|
session2 = session.id;
|
||||||
|
|
||||||
@ -49,9 +51,12 @@ module.exports = {
|
|||||||
console.log(response.data.answer);
|
console.log(response.data.answer);
|
||||||
|
|
||||||
interaction.editReply(response.data.answer);
|
interaction.editReply(response.data.answer);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
interaction.editReply('Please create a session using /create-session.');
|
||||||
|
} finally {
|
||||||
// Set the semaphore to false
|
// Set the semaphore to false
|
||||||
isProcessing = false;
|
isProcessing = false;
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user