adjustmentos

This commit is contained in:
legop3
2026-01-22 01:10:09 -05:00
parent 12512b8856
commit c30325afc0
2 changed files with 5 additions and 44 deletions
-1
View File
@@ -47,4 +47,3 @@ discord:
roles: roles:
announcementPing: "123456789012345678" announcementPing: "123456789012345678"
adminPing: "123456789012345678" adminPing: "123456789012345678"
stalker: "123456789012345678"
+5 -43
View File
@@ -44,7 +44,6 @@ if (!enabled) {
const intents = [ const intents = [
GatewayIntentBits.Guilds, GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent, GatewayIntentBits.MessageContent,
]; ];
@@ -978,36 +977,10 @@ function buildBatteryCaption(type, payload) {
} }
} }
async function getRoleMemberIds(channelId, roleId) {
if (!channelId || !roleId) return [];
const channel = await fetchChannel(channelId);
if (!channel?.guild) return [];
const guild = channel.guild;
let role = guild.roles.cache.get(roleId) || null;
if (!role) {
try {
role = await guild.roles.fetch(roleId);
} catch (err) {
logger.warn('Failed to fetch Discord role', { roleId, error: err.message });
return [];
}
}
if (!role) return [];
if (!role.members || role.members.size === 0) {
try {
await guild.members.fetch();
} catch (err) {
logger.warn('Failed to fetch guild members', { guildId: guild.id, error: err.message });
}
}
return Array.from(role.members?.keys?.() || []);
}
async function announce({ async function announce({
channelId, channelId,
content, content,
pingRoleId, pingRoleId,
pingUserIds,
prefixMentions = true, prefixMentions = true,
includeSiteUrl = true, includeSiteUrl = true,
color, color,
@@ -1018,11 +991,6 @@ async function announce({
if (!channelId) return; if (!channelId) return;
const mentionChunks = []; const mentionChunks = [];
if (pingRoleId) mentionChunks.push(`<@&${pingRoleId}>`); if (pingRoleId) mentionChunks.push(`<@&${pingRoleId}>`);
if (Array.isArray(pingUserIds)) {
pingUserIds.forEach((id) => {
if (id) mentionChunks.push(`<@${id}>`);
});
}
const prefix = prefixMentions && mentionChunks.length ? `${mentionChunks.join(' ')} ` : ''; const prefix = prefixMentions && mentionChunks.length ? `${mentionChunks.join(' ')} ` : '';
const payloadEmbeds = const payloadEmbeds =
Array.isArray(embeds) && embeds.length > 0 Array.isArray(embeds) && embeds.length > 0
@@ -1031,32 +999,26 @@ async function announce({
const allowedMentions = { const allowedMentions = {
parse: [], parse: [],
roles: pingRoleId ? [pingRoleId] : [], roles: pingRoleId ? [pingRoleId] : [],
users: Array.isArray(pingUserIds) ? pingUserIds : [],
}; };
await sendToChannel( await sendToChannel(
channelId, channelId,
`${prefix}${content || ''}`.trim(), `${prefix}${content || ''}`.trim(),
{ embeds: payloadEmbeds }, { embeds: payloadEmbeds },
allowedMentions, allowedMentions,
!(pingRoleId || (Array.isArray(pingUserIds) && pingUserIds.length > 0)), // keep mentions intact when pinging !pingRoleId, // keep mention intact when pinging
); );
} }
async function announceUserStatus({ channelId, content, color, title, description, embeds }) { async function announceUserStatus({ channelId, content, color, title, description, embeds }) {
const roles = discordConfig.roles || {}; const roles = discordConfig.roles || {};
const pingRoleId = roles.announcementPing || null; const mode = getMode();
const pingUserIds = await getRoleMemberIds(channelId, roles.stalker || null); const allowPing = mode !== MODES.ADMIN && mode !== MODES.LOCKDOWN;
const pingRoleId = allowPing ? roles.announcementPing || null : null;
const mainLine = pingRoleId ? `<@&${pingRoleId}> ${content}`.trim() : content; const mainLine = pingRoleId ? `<@&${pingRoleId}> ${content}`.trim() : content;
const stalkerMentions =
Array.isArray(pingUserIds) && pingUserIds.length > 0
? pingUserIds.map((id) => `<@${id}>`).join(' ')
: '';
const message = [mainLine, stalkerMentions].filter(Boolean).join('\n');
await announce({ await announce({
channelId, channelId,
content: message, content: mainLine,
pingRoleId, pingRoleId,
pingUserIds,
prefixMentions: false, prefixMentions: false,
color, color,
title, title,