import { Bot, Interaction } from "@wackford/discordeno.ts"; import { sendInteractionResponse } from "@wackford/mod.ts"; import config from "../config.ts"; import { Channel, db } from "../database.ts"; import BaseAI from "./BaseAI.d.ts"; const dirname = new URL(".", import.meta.url).pathname; const AIs: Record = new Proxy({} as Record, { get: (target, prop: string) => { if (!Object.keys(AIs).includes(prop)) { return false; } return target[prop]; }, }); export default function initAI() { config.discord.channels.forEach(async (channelId) => { let channel = (await db.select(channelId))[0] as Channel; if (!channel) { db.create(channelId, { moduleName: "huggingface", name: config.general.name, description: config.general.desc, history: [], }); channel = (await db.select(channelId))[0] as Channel; } console.log(channel); changeAI(channel.moduleName, channelId, channel.name, channel.description); }); } export async function changeAI(moduleName: string, channelId: string, newName?: string, newDesc?: string) { const channel = (await db.select(channelId))[0] as Channel; const name = newName ?? AIs[channelId].name; const desc = newDesc ?? AIs[channelId].description; const mod = (await import(dirname + moduleName + ".ts")).default; AIs[channelId] = new mod(name, desc, config, channel); await db.change(channelId, { moduleName: moduleName }); } export function checkAI(bot: Bot, interaction: Interaction, AI: BaseAI | boolean) { if (!AI) { sendInteractionResponse(bot, interaction, { content: "AI unavailable in this channel; please check your server for the correct channel!", private: true, }); return false; } else { return true; } } export { AIs };