All files index.ts

80.76% Statements 21/26
56.25% Branches 9/16
50% Functions 1/2
80.76% Lines 21/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 544x 4x 4x 4x     4x     4x 3x 3x   2x 9x 9x 7x 7x 7x                   4x 4x       4x         4x     4x     4x               4x  
import { Client, GatewayIntentBits } from 'discord.js';
import { generateDependencyReport } from '@discordjs/voice';
import { readFileSync } from 'fs';
import { handleInteraction } from './bot';
 
// Inlined test environment check
const isTestEnv = !!process.env.JEST_WORKER_ID;
 
// Simple .env loader (skipped in test environment)
if (!isTestEnv) {
  try {
    const env = readFileSync('.env', 'utf-8');
    // split on actual newlines or literal "\\n" sequences
    env.split(/\\n|\r?\n/).forEach((line) => {
      const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
      if (match) {
        const [, key, value] = match;
        Eif (!process.env[key]) {
          process.env[key] = value.replace(/^['"]|['"]$/g, ''); // remove quotes
        }
      }
    });
  } catch {
    // Do nothing if .env does not exist
  }
}
 
// Read token from environment variable
const token = process.env.DISCORD_TOKEN;
Iif (!token && !isTestEnv) {
  throw new Error('DISCORD_TOKEN is not set in environment variables.');
}
 
const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
});
 
// Register event handlers
client.once('ready', () => {
  console.log(`Logged in as ${client.user?.tag}! client ready...`);
});
client.on('interactionCreate', handleInteraction);
 
// If this script is run directly and not in test environment, output dependency report and login
Iif (require.main === module && !isTestEnv) {
  console.log(generateDependencyReport());
  if (token) {
    client.login(token);
  }
}
 
// Export client for testing
export { client };