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;
|
||||
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"] },
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue