Update ESLint rules, enhance environment schema with new metrics and health port, and refactor Redis import. Change TypeScript definitions path in package.json.

This commit is contained in:
smueller
2026-07-22 11:11:39 +02:00
parent c2271485a5
commit bc97d1d74c
15 changed files with 801 additions and 6 deletions

63
apps/bot/src/index.ts Normal file
View File

@@ -0,0 +1,63 @@
import {
Client,
Events,
GatewayIntentBits,
Partials,
ShardingManager,
type Interaction
} from 'discord.js';
import { env } from './env.js';
import { logger } from './logger.js';
import { prisma } from './db.js';
import { redis } from './redis.js';
import { registerCommands, routeCommand } from './commands.js';
import { startWorkers } from './jobs.js';
import type { BotContext } from './types.js';
import { startHealthServer } from './health.js';
const isShard = process.argv.includes('--shard');
if (!isShard) {
startHealthServer();
const manager = new ShardingManager(new URL('./index.js', import.meta.url).pathname, {
token: env.BOT_TOKEN,
totalShards: 'auto',
shardArgs: ['--shard']
});
manager.on('shardCreate', (shard) => logger.info({ shardId: shard.id }, 'Shard spawned'));
await manager.spawn();
} else {
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel]
});
const context: BotContext = { client, prisma, redis };
startWorkers(context);
client.on(Events.ClientReady, async () => {
logger.info({ tag: client.user?.tag }, 'Bot ready');
await registerCommands();
});
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) return;
try {
await routeCommand(interaction, context);
} catch (error) {
logger.error({ error }, 'Command execution failed');
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'An error occurred.', ephemeral: true });
} else {
await interaction.reply({ content: 'An error occurred.', ephemeral: true });
}
}
});
await client.login(env.BOT_TOKEN);
}