This commit is contained in:
Raven 2024-10-04 04:17:57 -04:00
parent 55447cb462
commit d676ca2c98

View File

@ -38,10 +38,27 @@ let userLastInteraction = {};
let conversationHistories = {};
// Function to reset conversation history if more than one hour has passed
function resetConversationIfExpired(userId) {
async function resetConversationIfExpired(userId) {
const now = Date.now();
if (userLastInteraction[userId] && now - userLastInteraction[userId] >= 3600000) { // 1 hour in milliseconds
conversationHistories[userId] = []; // Reset conversation history
try {
const userId = interaction.user.id;
conversationHistories[userId] = []; // Reset conversation history for the user
const response = await axios.post(`${process.env.API_PATH}/reset-conversation`, {}, {
headers: {
'Content-Type': 'application/json',
'x-forwarded-for-id': interaction.user.id,
'x-forwarded-for-name': interaction.user.username
}
});
console.log(response.status);
interaction.reply({ content: 'Conversation reset successfully.', ephemeral: isEphemeral(interaction.user.id) });
} catch (error) {
console.log(error);
interaction.reply({ content: 'Failed to reset the conversation.', ephemeral: isEphemeral(interaction.user.id) });
}
console.log(`Conversation history reset for user ${userId} due to inactivity.`);
}
}
@ -172,9 +189,22 @@ async function handleUserMessage(interaction, content) {
}
async function resetConversation(interaction) {
try {
const userId = interaction.user.id;
conversationHistories[userId] = []; // Reset conversation history for the user
interaction.reply({ content: 'Conversation reset successfully.', ephemeral: isEphemeral(userId) });
const response = await axios.post(`${process.env.API_PATH}/reset-conversation`, {}, {
headers: {
'Content-Type': 'application/json',
'x-forwarded-for-id': interaction.user.id,
'x-forwarded-for-name': interaction.user.username
}
});
console.log(response.status);
interaction.reply({ content: 'Conversation reset successfully.', ephemeral: isEphemeral(interaction.user.id) });
} catch (error) {
console.log(error);
interaction.reply({ content: 'Failed to reset the conversation.', ephemeral: isEphemeral(interaction.user.id) });
}
}
async function restartCore(interaction) {