From 3f6ec0227869398494bf80f8ad7c63320900778f Mon Sep 17 00:00:00 2001 From: Luis Otavio Martins Date: Mon, 28 Aug 2023 19:53:34 -0300 Subject: [PATCH] fix: !reset in dm (#158) --- src/handlers/command.ts | 16 +++++++++++++--- src/handlers/message.ts | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/handlers/command.ts b/src/handlers/command.ts index 6d93105..5f0077d 100644 --- a/src/handlers/command.ts +++ b/src/handlers/command.ts @@ -1,6 +1,6 @@ import { GroupChat, Message } from "whatsapp-web.js"; import { promptTracker } from "../clients/prompt"; -import { sydney } from "../clients/sydney"; +import { idsCache, sydney } from "../clients/sydney"; import { config } from "../config"; import { getAvailableTones, react } from "../utils"; import { reminderDB, reminders } from "./reminder"; @@ -40,14 +40,24 @@ export async function handleCommand( }); if (admins.includes(message.author)) { - await sydney.conversationsCache.delete(chat.id._serialized); + console.log("admins:", admins); + let onGoingConversation = await idsCache.get(chat.id._serialized); + const conversationData = JSON.parse(onGoingConversation); + let jailbreakId = conversationData.jailbreakConversationId; + console.log("jailbreakId:", jailbreakId); + await sydney.conversationsCache.delete(jailbreakId); + await idsCache.delete(chat.id._serialized); await message.reply("Conversation history reset."); } else { await message.reply("You are not allowed to perform this command."); } break; } else { - await sydney.conversationsCache.delete(chat.id._serialized); + let onGoingConversation = await idsCache.get(chat.id._serialized); + const conversationData = JSON.parse(onGoingConversation); + let jailbreakId = conversationData.jailbreakConversationId; + await idsCache.delete(chat.id._serialized); + await sydney.conversationsCache.delete(jailbreakId); await message.reply("Conversation history reset."); break; } diff --git a/src/handlers/message.ts b/src/handlers/message.ts index 02aea13..59b8120 100644 --- a/src/handlers/message.ts +++ b/src/handlers/message.ts @@ -237,6 +237,10 @@ async function askSydney(prompt: string, chatId: string, context: string) { const conversationData = JSON.parse(onGoingConversation); options.parentMessageId = conversationData.messageId; options.jailbreakConversationId = conversationData.jailbreakConversationId; + console.log( + "options.jailbreakConversationId:", + options.jailbreakConversationId + ); } const response: SydneyResponse = await sydney.sendMessage(prompt, options);