no impersonating :)

master
Skye 2 years ago
parent af36301c5e
commit 8b668d82bb
Signed by: me
GPG Key ID: 0104BC05F41B77B8

@ -33,9 +33,8 @@ const openai = new OpenAIApi(configuration);
client.on("ready", async () => { client.on("ready", async () => {
console.log(`Logged in as ${client.user?.tag}!`); console.log(`Logged in as ${client.user?.tag}!`);
const channel = await client.channels.fetch(process.env.CHANNEL ?? ''); const channel = await client.channels.fetch(process.env.CHANNEL ?? "");
if (channel?.type != ChannelType.GuildText) if (channel?.type != ChannelType.GuildText) return;
return
channel.send("\\Smolhaj Reset"); channel.send("\\Smolhaj Reset");
}); });
@ -50,7 +49,6 @@ client.on("messageCreate", async (message) => {
if (message.channel.type != ChannelType.GuildText) return; if (message.channel.type != ChannelType.GuildText) return;
if (message.content == "die") process.exit(1); if (message.content == "die") process.exit(1);
// "adapted" from https://github.com/ryanccn/blahaj/blob/main/src/chat.ts // "adapted" from https://github.com/ryanccn/blahaj/blob/main/src/chat.ts
await message.channel.sendTyping(); await message.channel.sendTyping();
@ -86,11 +84,12 @@ client.on("messageCreate", async (message) => {
if (msg.author === msg.author.client.user) { if (msg.author === msg.author.client.user) {
return { role: "assistant", content: msg.content }; 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 { return {
role: "user", role: "user",
content: `${msg.member?.displayName ?? msg.author.username}:${ content: `${username}:${msg.content}`,
msg.content
}`,
}; };
}) })
.values(), .values(),
@ -104,14 +103,16 @@ 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 const lastMessage =
msgs
.filter((msg) => { .filter((msg) => {
if (msg.webhookId && !msg.content.startsWith("\\")) return true; if (msg.webhookId && !msg.content.startsWith("\\")) return true;
if (msg.author.bot && msg.author !== msg.author.client.user) if (msg.author.bot && msg.author !== msg.author.client.user)
return false; return false;
if (msg.content.startsWith("\\")) return false; if (msg.content.startsWith("\\")) return false;
return true; return true;
}).first() ?? message; })
.first() ?? message;
const isAppropriate = await openai const isAppropriate = await openai
.createModeration({ input: responseMessage.content }) .createModeration({ input: responseMessage.content })

Loading…
Cancel
Save