From 4af21dc2e6e877aca01c8377ac4bb0162b62d3d5 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 10 Mar 2023 11:16:52 -0700 Subject: [PATCH] Make it so you can't reset while it's busy --- index.js | 13 ++++++++++--- lang.json | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b52db19..3fc53d2 100644 --- a/index.js +++ b/index.js @@ -67,8 +67,12 @@ client.on('interactionCreate', async (interaction) => { switch (interaction.commandName) { case "reset": // Remove the session - await resetSession(interaction.channelId); - interaction.reply(lang.reset); + if (!sessions[interaction.channelId].processing) { + await resetSession(interaction.channelId); + interaction.reply(lang.reset); + } else { + interaction.reply(lang.busy); + } break; case "info": // Info about the current session // If the session is empty other than the base prompt, say so @@ -130,11 +134,13 @@ client.on('messageCreate', async (message) => { await clearTimeout(timers[message.channelId]); delete timers[message.channelId]; } - + // Set the timer message.channel.sendTyping(); var typing = setInterval(() => { message.channel.sendTyping(); }, 5000) + // Set processing to true + sessions[message.channelId].processing = true; // Add the message to the session sessions[message.channelId].messages.push({ "name": `${message.author.id}`, @@ -171,6 +177,7 @@ client.on('messageCreate', async (message) => { } else { message.channel.send(output.content); } + sessions[message.channelId].processing = false; // Set the reset timer timers[message.channelId] = setTimeout(() => { resetSession(message.channelId); diff --git a/lang.json b/lang.json index 566074e..84f9692 100644 --- a/lang.json +++ b/lang.json @@ -17,5 +17,6 @@ "description": "The AI has decided to terminate the session.", "color": 16711680 }] - } + }, + "busy": "The bot is busy right now. Please try again later." } \ No newline at end of file