This Discord bot was converted from the Idle Champions Code Redeemer browser extension. All browser extension code has been removed; only the Discord bot remains.
This project consists of a single monolithic repository containing all source code:
| Component | Repository | Status | Purpose |
|---|---|---|---|
| Discord Bot | This repository | Active | Main bot codebase - handles commands, API interactions, and database |
No subprojects or submodules exist. All functionality is contained within this single repository and compiled into a single Docker container image for deployment.
idle-code-redeemer/
├── README.md ← Start here
├── docs/ ← All documentation
├── BUILD.md ← Build instructions
├── LICENSE
├── .env.example ← Configuration template
├── .gitignore
├── drizzle.config.ts ← Drizzle ORM / drizzle-kit configuration
│
├── src/
│ ├── bot/ ← Discord bot (ACTIVE)
│ │ ├── bot.ts ← Main Discord client & event handlers
│ │ ├── api/ ← Game server API client
│ │ ├── commands/ ← Slash command handlers (15 commands)
│ │ ├── database/ ← Database managers & Drizzle schema
│ │ │ ├── db.ts ← Drizzle connection & migrate()
│ │ │ ├── userManager.ts
│ │ │ ├── codeManager.ts
│ │ │ ├── auditManager.ts
│ │ │ ├── backfillManager.ts
│ │ │ ├── schema/ ← Drizzle table definitions (one file per table)
│ │ │ └── migrations/ ← Auto-generated SQL migration files
│ │ ├── handlers/ ← Message scanning for codes
│ │ └── utils/ ← Utilities (logger, crypto, debug, API request logging)
│ │
│ └── bot/api/types/ ← Type definitions from game API
│ ├── player_data.d.ts
│ ├── redeem_code_response.d.ts
│ ├── blacksmith_response.d.ts
│ └── server_definitions.d.ts
│
├── data/ ← SQLite database (git-ignored)
│ └── idle.db
│
├── debug/ ← API response logs (auto-cleanup) (git-ignored)
│ └── *.json
│
├── scripts/ ← Utility scripts
│ └── get-credentials.js
│
├── node_modules/ ← Dependencies (git-ignored)
├── package.json ← Bun dependencies & scripts
├── tsconfig.bot.json ← TypeScript config (noEmit: true, type-check only)
│
├── .mise.toml ← Mise task definitions & tool versions
├── Dockerfile ← Multi-stage Docker build
├── docker-compose.yml ← Multi-container orchestration
└── .dockerignore
- src/bot/bot.ts - Discord client initialization, event handlers, command routing
- src/bot/api/idleChampionsApi.ts - Game server API client with query-parameter format
- src/bot/commands/setup.ts -
/setup user_id:<id> user_hash:<hash> - src/bot/commands/redeem.ts -
/redeem code:<code> - src/bot/commands/catchup.ts -
/catchup(redeem all known codes the user hasn't claimed) - src/bot/commands/autoredeem.ts -
/autoredeem enabled:<on|off>(toggle automatic redemption per user) - src/bot/commands/inventory.ts -
/inventory(gold, rubies, equipment, progress) - src/bot/commands/open.ts -
/open chest_type:<type> count:<count> - src/bot/commands/blacksmith.ts -
/blacksmith contract_type:<type> hero_id:<id> count:<count> - src/bot/commands/codes.ts -
/codes(paginated redeemed codes history with loot, 5 per page) - src/bot/commands/makepublic.ts -
/makepublic code:<code>(share codes with other users) - src/bot/commands/notifications.ts -
/notifications(view/update DM preferences: dm_on_code, dm_on_success, dm_on_failure) - src/bot/commands/stats.ts -
/stats(server-wide stats: unique codes, total redemptions, registered users, aggregate loot) - src/bot/commands/logs.ts -
/logs [lines:<1-100>](admin only: show last N lines of combined.log) - src/bot/commands/backfill.ts -
/backfill [channel:<channel>](admin only: recover missed codes) - src/bot/commands/deleteaccount.ts -
/deleteaccount(permanently delete all stored user data, GDPR-friendly) - src/bot/commands/help.ts -
/help
- src/bot/database/db.ts - Drizzle ORM connection,
initializeDatabase(), andmigrate()on startup - src/bot/database/userManager.ts - User credential storage
- src/bot/database/codeManager.ts - Code tracking & history
- src/bot/database/auditManager.ts - Audit log operations
- src/bot/database/backfillManager.ts - Backfill operations & global lock
- src/bot/database/schema/ - Drizzle table definitions:
users.ts,redeemed_codes.ts,pending_codes.ts,audit_log.ts,backfill_operations.ts,loot_totals.ts - src/bot/database/migrations/ - Auto-generated SQL migrations (committed to source)
- src/bot/handlers/codeScanner.ts - Message scanning for codes (regex pattern)
- src/bot/handlers/autoRedeemer.ts - Automatically redeems detected codes for all users with auto-redeem enabled
- src/bot/utils/logger.ts - Winston structured logger (file + console, log rotation)
- src/bot/utils/crypto.ts - AES-256-GCM encryption/decryption for stored credentials
- src/bot/utils/apiRequestLogger.ts - API response logging with sanitized URLs and auto-cleanup
- src/bot/utils/debugLogger.ts - Debug utilities (auto-cleanup of old debug files)
- src/bot/handlers/codeScanner.test.ts - Unit tests for code detection regex, emoji stripping
- src/bot/handlers/autoRedeemer.test.ts - Queue serialization, DM sending
- src/bot/handlers/backfillHandler.test.ts - Message history backfill
- src/bot/database/codeManager.test.ts - All CodeManager methods: per-user redemption, public/private codes, pending, expiry, loot totals
- src/bot/database/userManager.test.ts - All UserManager CRUD operations (with encryption)
- src/bot/database/auditManager.test.ts - Audit log operations
- src/bot/database/backfillManager.test.ts - Backfill rate limiting
- src/bot/commands/notifications.test.ts -
/notificationscommand and preference updates - src/bot/commands/stats.test.ts -
/statswith empty/populated DB - src/bot/commands/logs.test.ts -
/logscommand with mocked filesystem - src/bot/utils/apiRequestLogger.test.ts - API log file cleanup
- src/test/setup.ts - Bun test preload: sets
DB_PATH=:memory:andMIGRATIONS_PATHbefore imports
- .env.example - Template for environment variables
- .mise.toml - Task definitions and tool versions (Bun 1.3.14, Gitleaks)
- bunfig.toml - Bun configuration (test preload, registered via
[test].preload) - package.json - Bun scripts & dependencies
- tsconfig.bot.json - TypeScript compiler options (
noEmit: true— type-check only) - drizzle.config.ts - Drizzle Kit configuration (schema path, migrations output)
Production
discord.js- Discord bot frameworkdrizzle-orm- Type-safe ORM for SQLitewinston- Logging framework
Note:
dotenv,node-fetch, andsqlite3were removed. Bun loads.envnatively, provides a built-in Fetch API, and includesbun:sqliteas a first-party module.
Development
typescript- Type checking (type-check only;noEmit: true)@types/bun- Bun type definitionsdrizzle-kit- Schema management & migration generationeslint- Code lintingprettier- Code formattinghusky- Git hookscommitlint- Commit message validationlint-staged- Pre-commit linting
Runtime (managed by Mise)
bun1.3.14 - JavaScript runtime, package manager, and bundler
The following browser extension code has been permanently removed:
src/chestManagement/- Extension chest management UIsrc/inject/- Extension content scriptsrc/options/- Extension options pagesrc/service_worker/- Extension background service workersrc/shared/- Shared extension codeextension/- Extension manifest, assets, distribution files
Reason: Converted to Discord bot; extension code no longer needed.
For local development:
bun install
mise run devFor production binary:
bun install
mise run prod:build
./dist-bundle/botFor Docker deployment:
docker-compose upFor production:
mise run prod:buildcompiles a self-contained binary (dist-bundle/bot) with Bun runtime embedded- No Bun, Node.js, or
node_modulesrequired at runtime - Docker image only needs the binary +
ca-certificates - Configure
DISCORD_TOKENfrom Discord Developer Portal - Set
DISCORD_GUILD_IDandDISCORD_CHANNEL_ID - Runs 24/7 in the cloud
See README.md and docs/development.md for details.