even less racy

This commit is contained in:
Skye 2023-03-13 19:38:35 +09:00
parent 97b74ec81f
commit a2213e8321
Signed by: me
GPG key ID: 0104BC05F41B77B8

View file

@ -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);