even less racy
This commit is contained in:
parent
97b74ec81f
commit
a2213e8321
1 changed files with 2 additions and 11 deletions
13
index.ts
13
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);
|
||||
|
|
Loading…
Reference in a new issue