kluralpit
This commit is contained in:
parent
ce7eca870e
commit
204b17533e
1 changed files with 36 additions and 6 deletions
42
index.ts
42
index.ts
|
@ -2,6 +2,7 @@ import * as dotenv from "dotenv"; // see https://github.com/motdotla/dotenv#how-
|
|||
dotenv.config();
|
||||
|
||||
import {
|
||||
ActivityType,
|
||||
ChannelType,
|
||||
Client,
|
||||
Colors,
|
||||
|
@ -31,11 +32,23 @@ const configuration = new Configuration({
|
|||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
async function sleep(ms: number) {
|
||||
await new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
|
||||
}
|
||||
|
||||
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;
|
||||
channel.send("\\Smolhaj Reset");
|
||||
client.user?.setPresence({
|
||||
activities: [
|
||||
{
|
||||
type: ActivityType.Playing,
|
||||
name: "actually nice pluralkit support",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
let resetTime = Date.now();
|
||||
|
@ -59,18 +72,32 @@ client.on("messageCreate", async (message) => {
|
|||
|
||||
const recieved = SnowflakeUtil.timestampFrom(message.id);
|
||||
|
||||
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1500));
|
||||
sleep(250);
|
||||
|
||||
try {
|
||||
const msgs = await message.channel.messages.fetch({
|
||||
let msgs = await message.channel.messages.fetch({
|
||||
after: SnowflakeUtil.generate({
|
||||
timestamp: Math.max(Date.now() - 5 * 60 * 1000, resetTime),
|
||||
}).toString(),
|
||||
before: SnowflakeUtil.generate({
|
||||
timestamp: recieved + 250,
|
||||
}).toString(),
|
||||
before: message.id,
|
||||
});
|
||||
|
||||
const msgsAfter = await message.channel.messages.fetch({
|
||||
after: message.id,
|
||||
});
|
||||
|
||||
const nextMessage = msgsAfter.last();
|
||||
|
||||
if (nextMessage?.webhookId) {
|
||||
// pluralkit moment
|
||||
|
||||
// remove current message
|
||||
msgs.delete(message.id);
|
||||
|
||||
// add the pk message
|
||||
msgs.set(nextMessage.id, nextMessage);
|
||||
}
|
||||
|
||||
const context = [
|
||||
...msgs
|
||||
.filter((msg) => {
|
||||
|
@ -85,7 +112,10 @@ client.on("messageCreate", async (message) => {
|
|||
return { role: "assistant", content: msg.content };
|
||||
}
|
||||
let username = msg.member?.displayName ?? msg.author.username;
|
||||
if (username.toLowerCase().includes("skyevg") && msg.author.id != "1038096782963507210")
|
||||
if (
|
||||
username.toLowerCase().includes("skyevg") &&
|
||||
msg.author.id != "1038096782963507210"
|
||||
)
|
||||
username = msg.author.username; // no impersonating :)
|
||||
return {
|
||||
role: "user",
|
||||
|
|
Loading…
Reference in a new issue