no impersonating :)
This commit is contained in:
parent
af36301c5e
commit
8b668d82bb
1 changed files with 20 additions and 19 deletions
39
index.ts
39
index.ts
|
@ -33,9 +33,8 @@ const openai = new OpenAIApi(configuration);
|
|||
|
||||
client.on("ready", async () => {
|
||||
console.log(`Logged in as ${client.user?.tag}!`);
|
||||
const channel = await client.channels.fetch(process.env.CHANNEL ?? '');
|
||||
if (channel?.type != ChannelType.GuildText)
|
||||
return
|
||||
const channel = await client.channels.fetch(process.env.CHANNEL ?? "");
|
||||
if (channel?.type != ChannelType.GuildText) return;
|
||||
channel.send("\\Smolhaj Reset");
|
||||
});
|
||||
|
||||
|
@ -50,7 +49,6 @@ client.on("messageCreate", async (message) => {
|
|||
if (message.channel.type != ChannelType.GuildText) return;
|
||||
if (message.content == "die") process.exit(1);
|
||||
|
||||
|
||||
// "adapted" from https://github.com/ryanccn/blahaj/blob/main/src/chat.ts
|
||||
|
||||
await message.channel.sendTyping();
|
||||
|
@ -86,11 +84,12 @@ client.on("messageCreate", async (message) => {
|
|||
if (msg.author === msg.author.client.user) {
|
||||
return { role: "assistant", content: msg.content };
|
||||
}
|
||||
let username = msg.member?.displayName ?? msg.author.username;
|
||||
if (username == "skyevg" && msg.author.id != "1038096782963507210")
|
||||
username = msg.author.username; // no impersonating :)
|
||||
return {
|
||||
role: "user",
|
||||
content: `${msg.member?.displayName ?? msg.author.username}:${
|
||||
msg.content
|
||||
}`,
|
||||
content: `${username}:${msg.content}`,
|
||||
};
|
||||
})
|
||||
.values(),
|
||||
|
@ -104,14 +103,16 @@ 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 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 })
|
||||
|
@ -120,13 +121,13 @@ client.on("messageCreate", async (message) => {
|
|||
if (isAppropriate) {
|
||||
try {
|
||||
await lastMessage.reply({
|
||||
content: responseMessage.content,
|
||||
allowedMentions: { parse: ["users"] },
|
||||
content: responseMessage.content,
|
||||
allowedMentions: { parse: ["users"] },
|
||||
});
|
||||
} catch {
|
||||
await message.channel.send({
|
||||
content: responseMessage.content,
|
||||
allowedMentions: { parse: ["users"] },
|
||||
content: responseMessage.content,
|
||||
allowedMentions: { parse: ["users"] },
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue