update
This commit is contained in:
parent
55447cb462
commit
d676ca2c98
@ -38,10 +38,27 @@ let userLastInteraction = {};
|
|||||||
let conversationHistories = {};
|
let conversationHistories = {};
|
||||||
|
|
||||||
// Function to reset conversation history if more than one hour has passed
|
// Function to reset conversation history if more than one hour has passed
|
||||||
function resetConversationIfExpired(userId) {
|
async function resetConversationIfExpired(userId) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (userLastInteraction[userId] && now - userLastInteraction[userId] >= 3600000) { // 1 hour in milliseconds
|
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.`);
|
console.log(`Conversation history reset for user ${userId} due to inactivity.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,9 +189,22 @@ async function handleUserMessage(interaction, content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function resetConversation(interaction) {
|
async function resetConversation(interaction) {
|
||||||
const userId = interaction.user.id;
|
try {
|
||||||
conversationHistories[userId] = []; // Reset conversation history for the user
|
const userId = interaction.user.id;
|
||||||
interaction.reply({ content: 'Conversation reset successfully.', ephemeral: isEphemeral(userId) });
|
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) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restartCore(interaction) {
|
async function restartCore(interaction) {
|
||||||
|
Loading…
Reference in New Issue
Block a user