Skip to content
lakesidegamedevPublic
forked from arle-bina/adhd-bot

About

A Discord bot for usage with the A House Divided political simulator game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Β 
Β 

Repository files navigation

πŸ€– A House Divided β€” Discord Bot

Discord companion bot for the A House Divided political simulation β€” look up politicians, track elections, read in-game news, and more without leaving Discord.


version 1.4.0 last commit recent PRs welcome license proprietary

discord.js v14 node v20+ TypeScript 5.3 PM2 managed


πŸ€– Overview

A House Divided is a browser-based political simulation where players create politicians, compete in elections, form coalitions, pass legislation, and climb from state office to national leadership. The game runs on a turn-based economy (1 turn = 1 real hour) with persistent world state across the US and UK.

This repository contains the Discord bot β€” a companion app that connects to the game's API and exposes live game data via slash commands, so players can check standings, elections, and news without switching to a browser.


πŸ€– Commands

Players

Command Description Options
/profile View a player's character(s) name (character name), user (Discord user)
/leaderboard Top politicians by influence or favorability metric, country, limit

Politics

Command Description Options
/elections Active and upcoming elections country, state
/election Drill into a specific race with candidate standings and vote shares country, state, race
/predict Projected vs current seat totals with parliament chart country, race
/party Look up a political party id (slug, e.g. labour)
/state State or region overview with current officials id (e.g. CA, UK_ENG)

Economy

Command Description Options
/corporation Look up a corporation with tabbed views (overview, bonds, financials) name
/bonds Browse the bond market across all corporations corp, page
/sectors Browse sector ownership by industry type type, unowned, page

World

Command Description Options
/news Latest in-game news posts category, limit
/turn Current game turn, year, and clock β€”

Server

Command Description Options
/accept Accept the server rules and gain access β€”
/ticket Open a support ticket (Bug, Suggestion, or Moderation) β€”
/close-ticket Close the current ticket channel (resolution modal; staff must message the opener) β€”
/merge-ticket Merge another user's ticket into the current channel (staff only; copies messages, notifies user, deletes source) user (required)
/ticket-panel Post a persistent ticket panel with buttons β€”
/help Browse all bot commands via an interactive select menu β€”
/serverstats View server activity graphs type, days
/starboard Configure the starboard channel, threshold, emoji, self-star, enabled
/sync-roles Backfill party and country roles for linked members β€”
/version Show bot version, commit, and uptime β€”

The bot also sends an automatic welcome message when a new member joins, prompting them to read the rules and run /accept.


πŸ€– Tech Stack

Layer Technology
Bot Framework discord.js v14
Language TypeScript 5.3
Runtime Node.js v20+
Dev Runner tsx (watch mode)
Process Manager PM2
Game Backend A House Divided API (hosted remotely)

πŸ€– Project Structure

adhd-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ commands/
β”‚   β”‚   β”œβ”€β”€ accept.ts        # /accept (server onboarding)
β”‚   β”‚   β”œβ”€β”€ bonds.ts         # /bonds (bond market browser)
β”‚   β”‚   β”œβ”€β”€ close-ticket.ts  # /close-ticket
β”‚   β”‚   β”œβ”€β”€ corporation.ts   # /corporation (overview/bonds/financials views)
β”‚   β”‚   β”œβ”€β”€ election.ts      # /election (race detail with interactive drill-down)
β”‚   β”‚   β”œβ”€β”€ elections.ts     # /elections (list view)
β”‚   β”‚   β”œβ”€β”€ help.ts          # /help (interactive menu)
β”‚   β”‚   β”œβ”€β”€ leaderboard.ts   # /leaderboard
β”‚   β”‚   β”œβ”€β”€ news.ts          # /news
β”‚   β”‚   β”œβ”€β”€ party.ts         # /party
β”‚   β”‚   β”œβ”€β”€ predict.ts       # /predict (seat projection with parliament chart)
β”‚   β”‚   β”œβ”€β”€ profile.ts       # /profile
β”‚   β”‚   β”œβ”€β”€ sectors.ts       # /sectors
β”‚   β”‚   β”œβ”€β”€ serverstats.ts   # /serverstats (activity graphs)
β”‚   β”‚   β”œβ”€β”€ starboard.ts     # /starboard config
β”‚   β”‚   β”œβ”€β”€ state.ts         # /state
β”‚   β”‚   β”œβ”€β”€ sync-roles.ts    # /sync-roles
β”‚   β”‚   β”œβ”€β”€ ticket-panel.ts  # /ticket-panel
β”‚   β”‚   β”œβ”€β”€ ticket.ts        # /ticket
β”‚   β”‚   β”œβ”€β”€ turn.ts          # /turn
β”‚   β”‚   └── version.ts       # /version
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ api.ts           # Game API client (all fetch functions + types)
β”‚   β”‚   β”œβ”€β”€ cooldown.ts      # Per-user command cooldown tracker
β”‚   β”‚   β”œβ”€β”€ env.ts           # Env validation
β”‚   β”‚   β”œβ”€β”€ helpRegistry.ts  # Help menu command metadata (source of truth)
β”‚   β”‚   β”œβ”€β”€ helpers.ts       # Shared helpers (hexToInt, errorMessage)
β”‚   β”‚   β”œβ”€β”€ starboard.ts     # Starboard reaction handler
β”‚   β”‚   β”œβ”€β”€ statsStore.ts    # Server stats storage
β”‚   β”‚   └── tickets.ts       # Ticket system utilities
β”‚   β”œβ”€β”€ index.ts             # Bot entry point (auto-discovers commands)
β”‚   └── register.ts          # Slash command registration (auto-discovers commands)
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ commands/
β”‚   β”‚   β”œβ”€β”€ elections.test.ts
β”‚   β”‚   β”œβ”€β”€ leaderboard.test.ts
β”‚   β”‚   β”œβ”€β”€ party.test.ts
β”‚   β”‚   └── state.test.ts
β”‚   └── utils/
β”‚       └── helpers.test.ts
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ setup.sh             # First-time server setup
β”‚   └── deploy.sh            # Update & restart bot
β”œβ”€β”€ ecosystem.config.cjs     # PM2 configuration
β”œβ”€β”€ eslint.config.js         # ESLint + typescript-eslint config
β”œβ”€β”€ vitest.config.ts         # Test runner config
β”œβ”€β”€ .env.example             # Required environment variables
β”œβ”€β”€ tsconfig.json
└── package.json

πŸ€– Getting Started

Prerequisites

  • Node.js v20 or later
  • npm v10 or later
  • A Discord bot token and application from the Discord Developer Portal
  • Server Members Intent enabled in the Discord Developer Portal (Bot β†’ Privileged Gateway Intents) β€” required for the welcome message flow
  • A valid GAME_API_KEY from A House Divided

Installation

# Clone the repository
git clone https://github.com/Egg3901/adhd-bot.git
cd adhd-bot

# Install dependencies
npm install

# Copy and fill in environment variables
cp .env.example .env

Environment Variables

Variable Description
DISCORD_BOT_TOKEN Your Discord bot token
DISCORD_CLIENT_ID Your Discord application client ID
GAME_API_URL Game API base URL (default: https://www.ahousedividedgame.com/)
GAME_API_KEY API key for the game backend
WELCOME_CHANNEL_ID Channel ID where welcome messages are sent to new members
RULES_CHANNEL_ID Channel ID linked in the welcome message
MEMBER_ROLE_ID Role ID assigned by /accept
ALPHA_TESTER_ROLE_ID Role ID assigned by /accept

Development

# Run in watch mode (auto-reloads on file changes)
npm run dev

Register Slash Commands

Commands must be registered with Discord before they appear in servers. Run once per deployment or after adding new commands:

npm run register

Production Build

# Compile TypeScript to dist/
npm run build

# Run compiled output
npm start

πŸ€– Deployment (Oracle Cloud / Ubuntu)

First-time Setup

bash scripts/setup.sh

This installs Node.js, PM2, builds the project, registers commands, and starts the bot under PM2 with startup persistence.

Updating

bash scripts/deploy.sh

Pulls latest changes, rebuilds, and restarts the PM2 process.

PM2 Commands

pm2 status              # Check bot status
pm2 logs adhd-bot       # View live logs
pm2 restart adhd-bot    # Manual restart

πŸ€– Testing

# Run unit tests (pure utility and formatting functions)
npm test

# Watch mode for development
npm run test:watch

33 unit tests cover hexToInt, errorMessage, getMetricValue, ideologyLabel, formatElectionType, and formatOfficeType. No mocking required β€” all tested functions are pure input/output.

Ticket limits: Users can have up to 3 tickets per category at a time.

Ticket merging: Staff can use /merge-ticket inside a ticket channel to merge another user's ticket into it β€” the source ticket's messages are copied, the user is pinged and DM'd, and the source channel is deleted.


πŸ€– Code Style & Linting

After installing dependencies, run:

# Check for lint errors
npm run lint

# Auto-fix where possible
npm run lint:fix

πŸ€– Related


πŸ€– License

Proprietary β€” All rights reserved.

About

A Discord bot for usage with the A House Divided political simulator game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages