From a2213e8321e16e674fcd13b76aef678548b49fb0 Mon Sep 17 00:00:00 2001 From: Skye Date: Mon, 13 Mar 2023 19:38:35 +0900 Subject: [PATCH] even less racy --- index.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/index.ts b/index.ts index 4946729..17ef01d 100644 --- a/index.ts +++ b/index.ts @@ -100,6 +100,8 @@ client.on("messageCreate", async (message) => { msgs.set(nextMessage.id, nextMessage); } + const lastMessage = nextMessage ?? message; + const context = [ ...msgs .filter((msg) => { @@ -135,17 +137,6 @@ client.on("messageCreate", async (message) => { const responseMessage = response.data.choices[0].message; if (!responseMessage) return; - const lastMessage = - msgs - .filter((msg) => { - if (msg.webhookId && !msg.content.startsWith("\\")) return true; - if (msg.author.bot && msg.author !== msg.author.client.user) - return false; - if (msg.content.startsWith("\\")) return false; - return true; - }) - .first() ?? message; - const isAppropriate = await openai .createModeration({ input: responseMessage.content }) .then(({ data }) => !data.results[0].flagged);