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:
@@ -7,7 +7,7 @@ const {
|
||||
EmbedBuilder
|
||||
} = require('discord.js');
|
||||
const { mongoose, withRetry } = require('./db-connection');
|
||||
const { CONFIG, GAME_NAME_TO_KEY } = require('./config');
|
||||
const { CONFIG } = require('./config');
|
||||
const {
|
||||
getCleanBody,
|
||||
extractRawEmail,
|
||||
@@ -19,7 +19,7 @@ const {
|
||||
} = require('./utils');
|
||||
const { getGmailClient } = require('./services/gmail');
|
||||
const { getNextTicketNumber, checkTicketLimits, getOrCreateTicketCategory, toDiscordSafeName, getSenderLocal } = require('./services/tickets');
|
||||
const { logError, logGmail, logAutomation } = require('./services/debugLog');
|
||||
const { logError } = require('./services/debugLog');
|
||||
const { enqueueSend } = require('./services/channelQueue');
|
||||
const { getTicketActionRow } = require('./utils/ticketComponents');
|
||||
|
||||
@@ -29,7 +29,6 @@ const Transcript = mongoose.model('Transcript');
|
||||
let isPolling = false;
|
||||
let authErrorNotified = false;
|
||||
let pollSuspended = false;
|
||||
let pollCount = 0, totalProcessed = 0, totalSkipped = 0, totalErrors = 0;
|
||||
|
||||
function setPollSuspended(val) {
|
||||
pollSuspended = !!val;
|
||||
@@ -45,13 +44,6 @@ async function poll(client) {
|
||||
if (isPolling || pollSuspended) return;
|
||||
isPolling = true;
|
||||
try {
|
||||
pollCount++;
|
||||
if (pollCount % 10 === 0) {
|
||||
if (totalProcessed > 0 || totalSkipped > 0 || totalErrors > 0) {
|
||||
logAutomation('Gmail poll summary', null, `polls: ${pollCount}, processed: ${totalProcessed}, skipped: ${totalSkipped}, errors: ${totalErrors}`).catch(() => {});
|
||||
}
|
||||
pollCount = 0; totalProcessed = 0; totalSkipped = 0; totalErrors = 0;
|
||||
}
|
||||
console.log('Running poll()...');
|
||||
try {
|
||||
const gmail = getGmailClient();
|
||||
@@ -89,7 +81,6 @@ async function poll(client) {
|
||||
email.data.payload.headers.find(h => h.name === 'From')
|
||||
?.value || '';
|
||||
if (from.toLowerCase().includes(CONFIG.MY_EMAIL)) {
|
||||
totalSkipped++;
|
||||
await gmail.users.messages.batchModify({
|
||||
userId: 'me',
|
||||
requestBody: {
|
||||
@@ -173,7 +164,6 @@ async function poll(client) {
|
||||
// Check ticket limits before creating
|
||||
const limitCheck = await checkTicketLimits(sEmail);
|
||||
if (!limitCheck.ok) {
|
||||
totalSkipped++;
|
||||
console.log(`Ticket limit reached for ${sEmail}: ${limitCheck.reason}`);
|
||||
await gmail.users.messages.batchModify({
|
||||
userId: 'me',
|
||||
@@ -224,11 +214,6 @@ async function poll(client) {
|
||||
|
||||
const detectedGame = detectGame(subject, rawBody);
|
||||
|
||||
const gameKey =
|
||||
detectedGame && detectedGame !== 'Not Mentioned'
|
||||
? GAME_NAME_TO_KEY[detectedGame] || null
|
||||
: null;
|
||||
|
||||
const buttons = getTicketActionRow({ escalationTier: 0 });
|
||||
|
||||
const ticketInfoEmbed = new EmbedBuilder()
|
||||
@@ -326,8 +311,6 @@ async function poll(client) {
|
||||
},
|
||||
{ upsert: true, new: true }
|
||||
));
|
||||
totalProcessed++;
|
||||
logGmail(subject, sEmail, number, detectedGame).catch(() => {});
|
||||
}
|
||||
console.log('Archiving/reading Gmail message', msgRef.id);
|
||||
await gmail.users.messages.batchModify({
|
||||
@@ -359,7 +342,6 @@ async function poll(client) {
|
||||
}
|
||||
}
|
||||
|
||||
totalErrors++;
|
||||
console.error('POLL ERROR:', e);
|
||||
logError('Gmail poll', e, null, client).catch(() => {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user