GPTcord/src/index.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-03-14 21:16:54 +01:00
import DiscordApi from "discord.js";
import { Configuration as OpenAIApiConfiguration, OpenAIApi } from "openai";
import { PrismaClient } from "@prisma/client";
2023-03-14 21:16:54 +01:00
import config from "./config";
import { queueRequest } from "./execution";
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,
]
});
export const openai = new OpenAIApi(new OpenAIApiConfiguration({
2023-03-14 21:16:54 +01:00
apiKey: config.tokens.OpenAI
}));
export const database = new PrismaClient();
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;
queueRequest(message);
});
if (require.main === module) discord.login(config.tokens.Discord);