even
This commit is contained in:
parent
b572ed3111
commit
7adaebe7b5
1 changed files with 10 additions and 1 deletions
11
index.ts
11
index.ts
|
@ -97,13 +97,22 @@ client.on("messageCreate", async (message) => {
|
||||||
const responseMessage = response.data.choices[0].message;
|
const responseMessage = response.data.choices[0].message;
|
||||||
if (!responseMessage) return;
|
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
|
const isAppropriate = await openai
|
||||||
.createModeration({ input: responseMessage.content })
|
.createModeration({ input: responseMessage.content })
|
||||||
.then(({ data }) => !data.results[0].flagged);
|
.then(({ data }) => !data.results[0].flagged);
|
||||||
|
|
||||||
if (isAppropriate) {
|
if (isAppropriate) {
|
||||||
try {
|
try {
|
||||||
await message.reply({
|
await lastMessage.reply({
|
||||||
content: responseMessage.content,
|
content: responseMessage.content,
|
||||||
allowedMentions: { parse: ["users"] },
|
allowedMentions: { parse: ["users"] },
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue