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();
|
dotenv.config();
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ActivityType,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
Client,
|
Client,
|
||||||
Colors,
|
Colors,
|
||||||
|
@ -31,11 +32,23 @@ const configuration = new Configuration({
|
||||||
});
|
});
|
||||||
const openai = new OpenAIApi(configuration);
|
const openai = new OpenAIApi(configuration);
|
||||||
|
|
||||||
|
async function sleep(ms: number) {
|
||||||
|
await new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
|
||||||
|
}
|
||||||
|
|
||||||
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) return;
|
if (channel?.type != ChannelType.GuildText) return;
|
||||||
channel.send("\\Smolhaj Reset");
|
channel.send("\\Smolhaj Reset");
|
||||||
|
client.user?.setPresence({
|
||||||
|
activities: [
|
||||||
|
{
|
||||||
|
type: ActivityType.Playing,
|
||||||
|
name: "actually nice pluralkit support",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let resetTime = Date.now();
|
let resetTime = Date.now();
|
||||||
|
@ -59,18 +72,32 @@ client.on("messageCreate", async (message) => {
|
||||||
|
|
||||||
const recieved = SnowflakeUtil.timestampFrom(message.id);
|
const recieved = SnowflakeUtil.timestampFrom(message.id);
|
||||||
|
|
||||||
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1500));
|
sleep(250);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const msgs = await message.channel.messages.fetch({
|
let msgs = await message.channel.messages.fetch({
|
||||||
after: SnowflakeUtil.generate({
|
after: SnowflakeUtil.generate({
|
||||||
timestamp: Math.max(Date.now() - 5 * 60 * 1000, resetTime),
|
timestamp: Math.max(Date.now() - 5 * 60 * 1000, resetTime),
|
||||||
}).toString(),
|
}).toString(),
|
||||||
before: SnowflakeUtil.generate({
|
before: message.id,
|
||||||
timestamp: recieved + 250,
|
|
||||||
}).toString(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 = [
|
const context = [
|
||||||
...msgs
|
...msgs
|
||||||
.filter((msg) => {
|
.filter((msg) => {
|
||||||
|
@ -85,7 +112,10 @@ client.on("messageCreate", async (message) => {
|
||||||
return { role: "assistant", content: msg.content };
|
return { role: "assistant", content: msg.content };
|
||||||
}
|
}
|
||||||
let username = msg.member?.displayName ?? msg.author.username;
|
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 :)
|
username = msg.author.username; // no impersonating :)
|
||||||
return {
|
return {
|
||||||
role: "user",
|
role: "user",
|
||||||
|
|
Loading…
Reference in a new issue