fix discord bot pings and some of the session spam

This commit is contained in:
legop3
2025-11-27 02:01:31 -05:00
parent 6c43bcbf8d
commit 63871ccd17
3 changed files with 41 additions and 5 deletions
+10 -3
View File
@@ -91,11 +91,12 @@ async function fetchChannel(id) {
return null;
}
async function sendToChannel(id, content, options = {}, allowedMentions = { parse: [] }) {
async function sendToChannel(id, content, options = {}, allowedMentions = { parse: [] }, sanitizeContent = true) {
const channel = await fetchChannel(id);
if (!channel) return;
try {
await channel.send({ content: sanitizeMentions(content), allowedMentions, ...options });
const messageContent = sanitizeContent ? sanitizeMentions(content) : content;
await channel.send({ content: messageContent, allowedMentions, ...options });
} catch (err) {
logger.warn('Failed to send Discord message', { id, error: err.message });
}
@@ -260,7 +261,13 @@ async function announce({ channelId, content, pingRoleId, color, title, descript
const prefix = pingRoleId ? `<@&${pingRoleId}> ` : '';
const embed = buildEmbed({ title, description, color });
const allowedMentions = pingRoleId ? { roles: [pingRoleId], parse: [] } : { parse: [] };
await sendToChannel(channelId, `${prefix}${content || ''}`.trim(), { embeds: [embed] }, allowedMentions);
await sendToChannel(
channelId,
`${prefix}${content || ''}`.trim(),
{ embeds: [embed] },
allowedMentions,
!pingRoleId, // keep role mention intact when pinging
);
}
function handleBusEvent(event) {