All MicroEvals
Discord bot test
Create MicroEval

Discord bot test

Prompt

Build a production-grade Discord bot in TypeScript (Node 20, discord.js v14, better-sqlite3, zod, vitest). Deliver the full project as files: package.json, tsconfig, src/, tests/, README. It must pass `npm run build` and `npm test` with zero errors. No placeholders, no TODOs, no "implement this yourself". Do not ask me questions, make reasonable decisions and note them in the README. ARCHITECTURE - Plugin system: each feature is a module in src/modules/<name>/ exporting {name, commands, events, tasks, migrations}. A loader auto-discovers modules, validates them with zod, and supports hot-reload of a single module via an owner-only /module reload command without dropping the gateway connection. - Versioned SQL migrations run on startup inside transactions, with a schema_migrations table. Rolling back on failure must leave the DB untouched. - Config via env, validated with zod at startup. Fail fast with a readable error. Never hardcode secrets. - Central error handler: every command/event/task error is logged with a correlation id, and the user sees an ephemeral message containing that id. The bot must never crash on a handler error. - Graceful shutdown on SIGINT/SIGTERM: stop accepting interactions, finish in-flight work, flush tasks, close the DB. FEATURES 1. Economy: /balance, /daily (24h cooldown), /pay <user> <amount>, /leaderboard, /shop with buy/sell of items. All money logic must be atomic and safe against concurrent interactions (double-spend, negative balances, self-pay, integer overflow). Store amounts as integers. Every change writes a ledger row, and the ledger must always sum to the balances. 2. Leveling: XP per message with per-user cooldown, level-up roles with role-hierarchy checks (the bot must not try to assign roles above its own top role), /rank with an image card rendered via @napi-rs/canvas. 3. Moderation: /warn /timeout /ban /kick /purge with permission and role-hierarchy checks, reason required, DM attempt that handles closed DMs, and a case system (/case view|edit|delete) with a full audit log channel. 4. Automod: spam (N messages in T seconds), mass-mention, invite-link, and raid detection (join-rate spike triggers auto-lockdown of channels, reversible with /lockdown off). Rules configurable per guild via /automod config, with sliding-window counters kept in memory and pruned to avoid leaks. 5. Tickets: button-created private channels, claim/close/transcript (transcript exported as an HTML file), per-user ticket limits, and recovery after a restart (buttons must still work on old messages, so use persistent custom_id routing). 6. Reminders/scheduler: /remind with natural time parsing ("in 2h30m", "tomorrow 9am"), persistent across restarts, with catch-up for reminders missed during downtime, and timezone per user. 7. Dashboard-less admin: /stats shows uptime, memory, DB size, command latency p50/p95 from an in-memory histogram. NON-FUNCTIONAL / TRAPS (these are checked) - Respond to every interaction within 3 seconds: defer when work may be slow. Handle the "already replied/deferred" states correctly. - Respect Discord limits: 2000 char messages, 25 select options, 5 buttons per row, embed size limits. Paginate long output. - Handle API rate limits and failures with retries/backoff, not busy loops. - Snowflakes are strings, never numbers. - Slash command registration must diff against the existing set and only re-register on changes. - Every user-supplied string rendered back must be sanitized (no @everyone/@here pings: use allowedMentions). - Cooldowns/rate limits per user per command, configurable. - No global mutable state shared unsafely between modules. TESTS (vitest, must be real) - Economy: 100 concurrent /pay calls cannot create or destroy money; ledger sum equals balances. - Migration rollback leaves the DB unchanged. - Time parser: at least 25 cases including DST edge cases and invalid input. - Raid detector window logic with a fake clock. - Role-hierarchy checks for moderation. Use an in-memory DB and mock the Discord client, no network in tests. OUTPUT FORMAT First, a short architecture summary with the file tree. Then each file in full, in a separate fenced block labelled with its path. End with a checklist mapping every requirement above to the file(s) that implement it, and honestly list anything you could not complete.

Response not available

Drag to resize

Response not available

Drag to resize
Drag to resize
Drag to resize

Response not available

Drag to resize