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 () => {
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…
Cancel
Save