huge changes
This commit is contained in:
48
services/staffPresence.js
Normal file
48
services/staffPresence.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Staff presence detection — checks Discord presence status for staff members.
|
||||
* Requires GuildPresences intent enabled in Discord Developer Portal.
|
||||
*/
|
||||
const { CONFIG } = require('../config');
|
||||
|
||||
/**
|
||||
* Get categorized availability of all configured staff members.
|
||||
* @param {import('discord.js').Guild} guild
|
||||
* @returns {{ online: string[], dnd: string[], offline: string[], unknown: string[] }}
|
||||
*/
|
||||
function getStaffAvailability(guild) {
|
||||
const results = {
|
||||
online: [],
|
||||
dnd: [],
|
||||
offline: [],
|
||||
unknown: []
|
||||
};
|
||||
|
||||
for (const staffId of CONFIG.STAFF_IDS) {
|
||||
const member = guild.members.cache.get(staffId);
|
||||
if (!member) { results.offline.push(staffId); continue; }
|
||||
|
||||
const status = member.presence?.status;
|
||||
if (!status) { results.unknown.push(staffId); continue; }
|
||||
|
||||
if (status === 'online' || status === 'idle') results.online.push(staffId);
|
||||
else if (status === 'dnd') results.dnd.push(staffId);
|
||||
else results.offline.push(staffId);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any staff member is currently available.
|
||||
* @param {import('discord.js').Guild} guild
|
||||
* @returns {{ available: boolean|null, source: string }}
|
||||
*/
|
||||
function isAnyStaffAvailable(guild) {
|
||||
const { online, dnd, unknown } = getStaffAvailability(guild);
|
||||
if (online.length > 0) return { available: true, source: 'presence' };
|
||||
if (CONFIG.STAFF_DND_COUNTS_AS_AVAILABLE && dnd.length > 0) return { available: true, source: 'presence_dnd' };
|
||||
if (unknown.length === CONFIG.STAFF_IDS.length) return { available: null, source: 'unknown' };
|
||||
return { available: false, source: 'presence' };
|
||||
}
|
||||
|
||||
module.exports = { getStaffAvailability, isAnyStaffAvailable };
|
||||
Reference in New Issue
Block a user