diff --git a/index.ts b/index.ts index 5260e11..2f7c8cd 100644 --- a/index.ts +++ b/index.ts @@ -97,13 +97,22 @@ 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); if (isAppropriate) { try { - await message.reply({ + await lastMessage.reply({ content: responseMessage.content, allowedMentions: { parse: ["users"] }, });