mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
8f9aa4d1bb28a85707f40190932339b5b9555179
Discord.js v14 Framework Template
Professional command framework template for Discord.js 14.26.2 with:
- Single command object schema
- Minimal command authoring (
name,category,execute) - Optional per-user command cooldown (
cooldownin seconds) - Shared execution logic for prefix and slash
- Dispatch pipeline ready for local execution or worker queue mode
- Global user rate limiting (memory or Redis backend)
- Structured JSON logging with
pino - External JSON i18n
- Automatic prefix and slash localizations from locale files
- One localized
nameper language drives both prefix and slash triggers - Typed argument schema
- User permission checks
- Auto-generated help from command metadata
Presence Storage
- The
presencecommand is persisted in PostgreSQL. - Storage is keyed by
bot_id(Discord user id), so one PostgreSQL instance can serve multiple bots. - Presence survives bot restarts and container restarts.
Setup
- Install dependencies: npm install
- Create environment file: cp .env.example .env
- Fill required values in
.env:DISCORD_TOKENDISCORD_CLIENT_IDDATABASE_URL
- Optional values:
DATABASE_SSL(truefor managed cloud DB,falsefor local Docker)DATABASE_SSL_REJECT_UNAUTHORIZED(trueby default for secure TLS verification)DATABASE_SSL_CA(optional CA cert chain, supports escaped newlines)ALLOW_INSECURE_DB_SSL(falseby default; settrueonly for local/dev exceptions)PRESENCE_STREAM_URL(used when activity type isSTREAMING)AUTO_DEPLOY_SLASH(trueto sync slash commands on startup)DEV_GUILD_ID(optional guild scope for faster slash sync)LOG_LEVEL(defaultinfo, JSON logs)STATE_BACKEND(memoryorredis)REDIS_URL(required whenSTATE_BACKEND=redis)GLOBAL_RATE_LIMIT_MAX_REQUESTS(global per-user request budget)GLOBAL_RATE_LIMIT_WINDOW_SECONDS(window size in seconds)COMMAND_DISPATCH_MODE(localorworker; enableworkeronly if a queue consumer is deployed)COMMAND_QUEUE_NAME(Redis list used inworkermode)ENABLE_LEADER_ELECTION(trueto guard startup jobs in multi-instance)
- Run migrations: npm run migrate
- Start in development: npm run dev
- Validate code quality:
- npm run typecheck
- npm run test
- npm run check
Docker Deployment (2 Bots + PostgreSQL)
- Fill production env files:
.env.bot-alpha.prod.env.bot-beta.prod
- Set strong shared DB credentials:
POSTGRES_DBPOSTGRES_USERPOSTGRES_PASSWORD
- Start stack: docker compose up -d --build
- Stop stack: docker compose down
By default, docker-compose.yml provisions:
bot_alpha: Discord bot instance Abot_beta: Discord bot instance Bpostgres: PostgreSQL 16 with persistent volumepostgres_data
Both bots use the same PostgreSQL service, and data remains isolated per bot through bot_id keys.
Security defaults:
- PostgreSQL is exposed only on the internal Compose network (
expose: 5432, no host bind). - Bot containers enforce
no-new-privilegesand graceful stop. - Log rotation is enabled (
max-size=10m,max-file=3). - Database TLS verification remains strict by default when SSL is enabled.
Architecture
src/app/bootstrap.ts: runtime bootstrap, dependency wiring, graceful shutdownsrc/commands/*: thin command wrappers (defineCommand+ delegated execute)src/modules/help/*: help command module (service + command contract)src/modules/presence/*: module entrypoint for presence runtime and contractssrc/modules/memberMessages/*: module entrypoint for member-message runtime and contractssrc/features/*: implementation details used behindsrc/modules/*src/core/commands/*: registry, parsing, slash payload, usage helperssrc/core/execution/CommandExecutor.ts: execution core (permissions, cooldown, global rate limit)src/core/execution/dispatch.ts: dispatch abstraction (localorworker)src/core/execution/cooldownStore.ts: cooldown store contracts and memory/Redis implementationssrc/core/execution/globalRateLimitStore.ts: global limiter contracts and memory/Redis implementationssrc/core/runtime/leaderCoordinator.ts: leader-only startup coordination for multi-instance deploymentssrc/core/logging/logger.ts: centralized structured logger (pino)src/core/discord/*: shared Discord helpers (reply message resolver, panel session registry)src/database/stores/*: PostgreSQL store implementationssrc/database/dbLifecycle.ts: centralized DB init/shutdown lifecyclesrc/validators/*: business validation/sanitizationsrc/types/*: pure shared types and contractssrc/i18n/*.json: external i18n dictionaries
Included Commands
kiss(fun) with requireduserargping(utility)welcome(utility) interactive welcome-message panelgoodbye(utility) interactive goodbye-message panelpresence(utility) with interactive status/activity/text panelhelp(core) with auto category and usage generation
Adding A Command
- Create a command object in
src/commands/... - Follow the schema in
src/types/command.ts - Add command to
src/commands/index.ts - Put business logic in
src/modules/<module>/...and keepsrc/commands/*as wrappers only - If
AUTO_DEPLOY_SLASH=true, restart the bot to sync slash commands automatically
Description
Template Discord.js avec commandes prefix & slash auto, components v2, help auto, multi-langue et variables dynamiques (ex: {{bot_latency}}).
Readme
3.6 MiB
Languages
TypeScript
93.3%
JavaScript
3.2%
PLpgSQL
1.7%
CSS
0.9%
Dockerfile
0.9%