Files
drb-server/src/discordBot/events/messageCreate.mjs
Logan Cusano 066404dd10
Some checks failed
Update Wiki from JSDoc / update-wiki (pull_request) Has been cancelled
Lint JavaScript/Node.js / lint-js (pull_request) Failing after 11s
DRB Tests / drb_mocha_tests (pull_request) Has been cancelled
Updated dir structure to put the actual source code in the general /src dir
2024-08-17 18:44:18 -04:00

56 lines
1.6 KiB
JavaScript

import { DebugBuilder } from "../../modules/debugger.mjs";
const log = new DebugBuilder("server", "discordBot.events.messageCreate");
import dotenv from "dotenv";
dotenv.config();
import { Events } from "discord.js";
import { gptInteraction } from "../addons/gptInteraction.mjs";
import { linkCop } from "../addons/linkCop.mjs";
import PresenceManager from "../modules/presenceManager.mjs";
import { getGuildConfig } from "../../modules/mongo-wrappers/mongoConfigWrappers.mjs";
export const name = Events.MessageCreate;
export async function execute(nodeIo, message) {
// Get the ignored channels from the server config
const IGNORED_CHANNELS = await getGuildConfig(
message.guild.id,
"ignoredChannels",
);
// Ignore ignored channels
if (
!Array.isArray(IGNORED_CHANNELS) ||
(Array.isArray(IGNORED_CHANNELS) &&
IGNORED_CHANNELS.includes(message.channel.id))
) {
return;
}
// Ignore messages from a bot
if (message.author.bot) {
return;
}
log.INFO("Message create", message);
// Set presence for reading message
const messagePm = new PresenceManager(message.client);
await messagePm.setPresence("online", "WATCHING", "latest messages");
// Check if the message mentions the bot
if (message.mentions.users.has(nodeIo.serverClient.user.id)) {
const interaction = await gptInteraction(nodeIo, message);
// Reset the presence
await messagePm.resetToDefault();
return interaction;
}
// Check if the message contains a link in a channel it shouldn't
await linkCop(nodeIo, message);
// Reset the presence
await messagePm.resetToDefault();
}