Implement Dynamic Presence #19
## Added Dynamic Presence to Functions - Added default to startup - Added to RSS manager - Added to interaction create event - Added to message create function ## Related Work #15 ### LinkCop - Updated with new regex string and logic approved and restricted channels - Implemented new config storage ### Guild Member Add (event) - Implemented new config storage for welcome channel ### Message Create (event) - Implemented new config storage for ignored channel IDs - Improved the logic for gpt interactions to reset presence ### Mongo Config Wrappers - Updated logic in order to handle different data types the same way - Updated set functions to wrap the value in the key - Updated get functions to return the keyyed value ie `config[key]`
This commit is contained in:
@@ -5,25 +5,40 @@ dotenv.config();
|
||||
import { Events } from "discord.js";
|
||||
import { gptInteraction } from "../addons/gptInteraction.mjs";
|
||||
import { linkCop } from "../addons/linkCop.mjs";
|
||||
|
||||
const IGNORED_CHANNELS = process.env.IGNORED_CHANNEL_IDS.split(",");
|
||||
import PresenceManager from "../modules/presenceManager.mjs";
|
||||
import { getGuildConfig, setGuildConfig } 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 (IGNORED_CHANNELS.includes(message.channel.id)) return;
|
||||
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;
|
||||
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)) {
|
||||
return await gptInteraction(nodeIo, message);
|
||||
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
|
||||
if (await linkCop(nodeIo, message)) return;
|
||||
await linkCop(nodeIo, message);
|
||||
|
||||
// Reset the presence
|
||||
await messagePm.resetToDefault();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user