simplify: prune dead code, dedup gmail send, drop neutered log stubs
- Remove no-op log stubs (logGmail, logAutomation, logSecurity, logSystem) and ~17 callsites; dead counters in tickets.js and gmail-poll.js go too - Dedup three near-identical Gmail send paths into sendThreadedEmail helper - Drop dead Mongoose fields: broccoliniTicketId, lastSyncedBroccoliniArticleId, renameCount, renameWindowStart, reminderSent, staffChannelId, unclaimedRemindersSent, lastMessageAuthorIsStaff - Drop dead config fields and their .env.example entries - Inline api/botClient.js (3-line wrapper, 2 callers) - Trim unused exports across utils.js, tickets.js, configSchema.js, debugLog.js - Fix handlers/messages.js to use isStaff() — old partial check ignored ADDITIONAL_STAFF_ROLES, so those members were treated as customers - Drop unused deps p-queue + dotenv-expand; move mongodb to devDependencies Net: -583 LOC source + -57 LOC lockfile. All 23 modules load clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
49
utils.js
49
utils.js
@@ -173,31 +173,6 @@ function extractRawEmail(headerValue) {
|
||||
return match ? match[1].trim() : headerValue.trim();
|
||||
}
|
||||
|
||||
// --- DATE ---
|
||||
|
||||
const getFormattedDate = () => {
|
||||
const now = new Date();
|
||||
const datePart = now
|
||||
.toLocaleDateString('en-US', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
year: 'numeric'
|
||||
})
|
||||
.replace(/\//g, '-');
|
||||
const timePart = now.toLocaleTimeString('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: true
|
||||
});
|
||||
const tzPart = new Intl.DateTimeFormat('en-US', {
|
||||
timeZoneName: 'short'
|
||||
})
|
||||
.formatToParts(now)
|
||||
.find(p => p.type === 'timeZoneName').value;
|
||||
return `${datePart} ${timePart} ${tzPart}`;
|
||||
};
|
||||
|
||||
// --- GAME DETECTION ---
|
||||
// Map<lowercase-alias, { canonical, re }> built once at module load so detectGame
|
||||
// doesn't allocate a fresh RegExp per game/alias per call.
|
||||
@@ -233,16 +208,6 @@ function getPriorityEmoji(priority) {
|
||||
}
|
||||
}
|
||||
|
||||
function getPriorityColor(priority) {
|
||||
switch (priority) {
|
||||
case 'high': return 0xFF0000;
|
||||
case 'low': return 0x00FF00;
|
||||
case 'normal':
|
||||
case 'medium':
|
||||
default: return CONFIG.EMBED_COLOR_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
// --- TEMPLATE VARIABLES ---
|
||||
|
||||
function replaceVariables(template, context = {}) {
|
||||
@@ -292,13 +257,6 @@ function sanitizeEmbedText(str) {
|
||||
|
||||
// --- EMBED TRUNCATION ---
|
||||
|
||||
/** Truncate a string for use as an embed field value (max 1024). */
|
||||
function truncateEmbedField(str, max = 1024) {
|
||||
if (str == null) return '';
|
||||
const s = String(str);
|
||||
return s.length > max ? s.slice(0, max - 3) + '...' : s;
|
||||
}
|
||||
|
||||
/** Truncate a string for use as an embed description (max 4096). */
|
||||
function truncateEmbedDescription(str, max = 4096) {
|
||||
if (str == null) return '';
|
||||
@@ -381,24 +339,17 @@ function enforceEmbedLimit(embeds) {
|
||||
|
||||
module.exports = {
|
||||
sanitizeEmbedText,
|
||||
truncateEmbedField,
|
||||
truncateEmbedDescription,
|
||||
enforceEmbedLimit,
|
||||
BLOCK_TAG_REGEX,
|
||||
escapeRegex,
|
||||
escapeHtml,
|
||||
safeEqual,
|
||||
isStaff,
|
||||
decodeHtmlEntities,
|
||||
htmlToTextWithBlocks,
|
||||
decodeGmailData,
|
||||
getCleanBody,
|
||||
stripEmailQuotes,
|
||||
stripMobileFooter,
|
||||
extractRawEmail,
|
||||
getFormattedDate,
|
||||
detectGame,
|
||||
getPriorityEmoji,
|
||||
getPriorityColor,
|
||||
replaceVariables
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user