Files
drb-server/discordBot/modules/presenceManager.mjs
Logan Cusano 117cbea67f
All checks were successful
release-tag / release-image (push) Successful in 1m52s
Lint JavaScript/Node.js / lint-js (push) Successful in 11s
DRB Tests / drb_mocha_tests (push) Successful in 29s
Linting
2024-08-11 15:57:46 -04:00

52 lines
1.5 KiB
JavaScript

import { getConfig } from "./configHandler.mjs";
class PresenceManager {
/**
* Creates an instance of PresenceManager.
* @param {import('discord.js').Client} client - The Discord client instance.
*/
constructor(client) {
this.client = client;
this.defaultStatus = "online";
this.defaultActivityType = "LISTENING";
this.defaultActivityName = "for your commands";
this.defaultUrl = null;
}
/**
* Set the bot's presence.
* @param {"online"|"idle"|"dnd"} status - The status of the bot (online, idle, dnd).
* @param {"PLAYING"|"STREAMING"|"LISTENING"|"WATCHING"|"COMPETING"} activityType - The type of activity.
* @param {string} activityName - The name of the activity.
* @param {string} [url=null] - The URL for STREAMING activity type (optional).
*/
setPresence(status, activityType, activityName, url = null) {
const activityOptions = {
type: activityType.toUpperCase(),
name: activityName,
};
if (activityType.toUpperCase() === "STREAMING" && url) {
activityOptions.url = url;
}
this.client.user.setPresence({
status: status,
activities: [activityOptions],
});
}
/**
* Reset the bot's presence to the default state.
*/
resetToDefault() {
const defaultPresence = getConfig("presence");
console.log("Default Presence:", defaultPresence);
// Update your bot's presence using this configuration
this.client.user.setPresence(defaultPresence);
}
}
export default PresenceManager;