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.
55 lines
1.9 KiB
55 lines
1.9 KiB
import { db, Channel } from "../database.ts";
|
|
import { BotEmitter } from "@wackford/mod.ts";
|
|
import { AIs } from "../ai/index.ts";
|
|
import config from "../config.ts";
|
|
import blacklist from "../../blacklist.json" assert { type: "json" };
|
|
|
|
//const dirname = new URL(".", import.meta.url).pathname;
|
|
|
|
export default function init() {
|
|
BotEmitter.on("message", async (bot, message) => {
|
|
if (
|
|
message.content &&
|
|
!message.content.startsWith("!") &&
|
|
config.discord.channels.includes(message.channelId.toString()) &&
|
|
!message.isFromBot &&
|
|
message.member
|
|
) {
|
|
const channel = (await db.select(message.channelId.toString()))[0] as Channel
|
|
const user = await bot.helpers.getUser(message.member?.id);
|
|
|
|
await bot.helpers.startTyping(message.channelId);
|
|
|
|
let res = await AIs[message.channelId.toString()].complete(user.username, message.content)
|
|
|
|
const history = channel.history ?? []
|
|
|
|
history.push({
|
|
name: user.username,
|
|
content: message.content
|
|
}, {
|
|
name: AIs[message.channelId.toString()].name,
|
|
content: res
|
|
})
|
|
|
|
db.change(message.channelId.toString(), {
|
|
history
|
|
})
|
|
|
|
blacklist.forEach((val) => {
|
|
res = res.replaceAll(val, `${val[0]}${"\\*".repeat(val.length - 1)}`)
|
|
})
|
|
|
|
await bot.helpers.sendMessage(message.channelId, {
|
|
content: `[${AIs[message.channelId.toString()].name}] ${res}`,
|
|
messageReference: {
|
|
messageId: message.id,
|
|
channelId: message.channelId,
|
|
guildId: message.guildId,
|
|
failIfNotExists: false,
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|