2023-03-14 21:16:54 +01:00
|
|
|
import DiscordApi from "discord.js";
|
|
|
|
import { Configuration as OpenAIApiConfiguration, OpenAIApi } from "openai";
|
2023-05-02 17:55:48 +02:00
|
|
|
import { PrismaClient } from "@prisma/client";
|
2023-03-14 21:16:54 +01:00
|
|
|
|
2023-03-24 15:44:22 +01:00
|
|
|
import config from "./config";
|
2023-05-08 01:30:32 +02:00
|
|
|
import { queueRequest } from "./execution";
|
2023-05-08 08:53:06 +02:00
|
|
|
import InteractionManager from "./interactionManager";
|
2023-03-14 21:16:54 +01:00
|
|
|
|
|
|
|
const discord = new DiscordApi.Client({
|
|
|
|
intents: [
|
|
|
|
DiscordApi.GatewayIntentBits.Guilds,
|
|
|
|
DiscordApi.GatewayIntentBits.GuildMessages,
|
|
|
|
DiscordApi.GatewayIntentBits.MessageContent,
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2023-03-14 23:44:43 +01:00
|
|
|
export const openai = new OpenAIApi(new OpenAIApiConfiguration({
|
2023-03-14 21:16:54 +01:00
|
|
|
apiKey: config.tokens.OpenAI
|
|
|
|
}));
|
|
|
|
|
2023-05-02 17:55:48 +02:00
|
|
|
export const database = new PrismaClient();
|
|
|
|
|
2023-05-08 08:53:06 +02:00
|
|
|
const interactionManager = new InteractionManager();
|
|
|
|
interactionManager.bindClient(discord);
|
|
|
|
|
2023-03-14 21:16:54 +01:00
|
|
|
discord.on("ready", async event => {
|
|
|
|
console.log(`Connected to Discord as ${event.user.tag} (${event.user.id})`);
|
|
|
|
});
|
|
|
|
|
|
|
|
discord.on("messageCreate", async message => {
|
|
|
|
if (message.author.bot) return;
|
|
|
|
if (!message.mentions.has(message.client.user)) return;
|
|
|
|
|
2023-05-08 01:30:32 +02:00
|
|
|
queueRequest(message);
|
2023-03-25 11:24:43 +01:00
|
|
|
});
|
|
|
|
|
2023-03-14 21:16:54 +01:00
|
|
|
discord.login(config.tokens.Discord);
|