You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
import { Bot, Interaction } from "@wackford/discordeno.ts";
|
|
import { sendInteractionResponse } from "@wackford/mod.ts";
|
|
import { GoofyAhhException } from "../bot.ts";
|
|
import config from "../config.ts";
|
|
import { db, Channel } from "../database.ts";
|
|
import BaseAI from "./BaseAI.d.ts";
|
|
import HuggingFaceAI from "./huggingface.ts";
|
|
|
|
const dirname = new URL(".", import.meta.url).pathname;
|
|
|
|
const AIs: Record<string, BaseAI> = new Proxy({} as Record<string, BaseAI>, {
|
|
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 };
|