Skip to content

nightcore-team/nightcore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

826 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’« Nightcore Discord Bot

A feature-rich Discord bot for Arizona RP community with economy system, moderation tools, forum integration, and much more.

Project Status
Tech Stack Python Discord.py PostgreSQL SQLAlchemy Pydantic uv Docker Alembic
Meta Linting - Ruff Code Style - Ruff License - MIT Type Checking - Mypy

πŸ“‹ Table of Contents

πŸ›  Tech Stack

  • Python 3.13
  • discord.py: Discord API wrapper
  • PostgreSQL 16: Database with asyncpg driver
  • SQLAlchemy 2.0: Async ORM
  • Alembic: Database migrations
  • Pydantic: Settings management and validation
  • Docker: Containerized deployment
  • uv: Fast Python package installer

πŸ“¦ Requirements

For Docker Setup:

  • Docker 20.10+
  • Docker Compose 2.0+

For Local Setup:

  • Python 3.13+
  • PostgreSQL 16+
  • UV package manager (or pip)
  • Git

πŸš€ Installation

Docker Setup (Recommended)

  1. Clone the repository
git clone https://github.com/nightcore-team/nightcore.git
cd nightcore
  1. Create environment file
cp .env.example .env
  1. Configure environment variables (see Configuration)

  2. Build and start containers

docker-compose up --build

The bot will automatically:

  • Build the Docker image
  • Start PostgreSQL database
  • Run database migrations
  • Launch the bot

To run in detached mode:

docker-compose up -d

To stop the bot:

docker-compose down

Local Setup

  1. Clone the repository
git clone https://github.com/nightcore-team/nightcore.git
cd nightcore
  1. Install UV package manager (if not installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Create virtual environment and install dependencies
uv sync
  1. Set up PostgreSQL database
# Create database
psql -U postgres
CREATE DATABASE database;
CREATE USER user WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE database TO user;
\q
  1. Create environment file
cp .env.example .env
  1. Configure environment variables (see Configuration)

  2. Run database migrations

uv run alembic upgrade head
  1. Start the bot
uv run python main.py

βš™οΈ Configuration

Create a .env file in the root directory with the following variables:

Required Variables

# Discord Bot
BOT_TOKEN=discord_bot_token

# PostgreSQL Database
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_HOST=host # Use 'localhost' for local setup
POSTGRES_PORT=port
POSTGRES_DB=database

# Alternative: Use full database URI instead of individual fields
# POSTGRES_DATABASE_URI=postgresql+asyncpg://user:password@host:port/database

# Forum API Integration
FORUM_API_URL=https://forum.arzguard.com/api
FORUM_API_KEY=your_forum_api_key

Optional Variables

# Bot Configuration
EMBED_DESCRIPTION_LIMIT=4096
VIEW_V2_DESCRIPTION_LIMIT=3000
VIEW_V2_COMPONENTS_LIMIT=40
DELETE_MESSAGES_SECONDS=604800
VOTEBAN_ATTACHMENTS_LIMIT=7
CLOSED_TICKET_ALIVE_HOURS=48
ROLE_REQUESTS_ALIVE_HOURS=2
CASE_REWARDS_LIMIT=30
MAX_CUSTOM_REWARD_SIZE=100
BUG_REPORT_CHANNEL_ID=1442803332233171088
DISABLE_FORUM_TASK=false

# Developer User IDs (comma-separated)
DEVELOPER_IDS=1280700292530176131,566255833684508672,451359852418039808

# Database Connection Pool
POSTGRES_ECHO=false
POSTGRES_ECHO_POOL=true
POSTGRES_POOL_MAX_OVERFLOW=30
POSTGRES_POOL_SIZE=10
POSTGRES_POOL_TIMEOUT=0
POSTGRES_POOL_PRE_PING=true

Getting Discord Bot Token

  1. Go to Discord Developer Portal
  2. Create a new application or select existing one
  3. Go to "Bot" section
  4. Click "Reset Token" and copy the token
  5. Enable required privileged intents:
    • Presence Intent
    • Server Members Intent
    • Message Content Intent

πŸ—„οΈ Database Migrations

The project uses Alembic for database migrations.

Create a new migration

make migration
# or manually:
alembic revision --autogenerate -m "Your migration message"

Apply migrations

make migrate
# or manually:
alembic upgrade head

Rollback migration

alembic downgrade -1

View migration history

alembic history

πŸ‘¨β€πŸ’» Development

Code Style

The project uses Ruff for linting and formatting:

# Check code
uv run ruff check .

# Format code
uv run ruff format .

# Fix auto-fixable issues
uv run ruff check --fix .

Check pyproject.toml for ruff configuration

Development Mode

For development, you can mount local files in Docker:

# Already configured in docker-compose.yml
volumes:
  - ./src/:/app/src/
  - ./main.py:/app/main.py

This allows live code reloading without rebuilding the container.

πŸ“ Project Structure

nightcore/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ config/                           # Global configuration
β”‚   β”‚   β”œβ”€β”€ config.py                     # Main config composition
β”‚   β”‚   └── env.py                       # Base environment settings
β”‚   β”œβ”€β”€ infra/                           # Infrastructure layer
β”‚   β”‚   β”œβ”€β”€ api/                         # External APIs
β”‚   β”‚   β”‚   β”œβ”€β”€ forum/                   # NightForo API client
β”‚   β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   └── db/                          # Database layer
β”‚   β”‚       β”œβ”€β”€ config.py                 # Database configuration
β”‚   β”‚       β”œβ”€β”€ operations.py            # Common DB operations
β”‚   β”‚       β”œβ”€β”€ session.py               # Session management
β”‚   β”‚       β”œβ”€β”€ uow.py                   # Unit of Work pattern
β”‚   β”‚       β”œβ”€β”€ utils.py                 # Database utilities
β”‚   β”‚       └── models/                  # SQLAlchemy models
β”‚   β”œβ”€β”€ nightcore/                       # Bot core
β”‚   β”‚   β”œβ”€β”€ bot.py                       # Bot class
β”‚   β”‚   β”œβ”€β”€ config.py                     # Bot configuration
β”‚   β”‚   β”œβ”€β”€ exceptions.py                # Custom exceptions
β”‚   β”‚   β”œβ”€β”€ setup.py                     # Setup bot instance and modules to load
β”‚   β”‚   β”œβ”€β”€ components/                  # Reusable global UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ embed/                   # embeds
β”‚   β”‚   β”‚   └── v2/                      # v2 (modals, views)
β”‚   β”‚   β”œβ”€β”€ events/                      # Discord event handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ error.py                 # Error handling
β”‚   β”‚   β”‚   β”œβ”€β”€ interaction.py           # Interaction events
β”‚   β”‚   β”‚   β”œβ”€β”€ channel/                 # Channel events
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/                     # Event DTOs
β”‚   β”‚   β”‚   β”œβ”€β”€ member/                  # Member events (join, leave, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ message/                 # Message events
β”‚   β”‚   β”‚   β”œβ”€β”€ reaction/                # Reaction events
β”‚   β”‚   β”‚   β”œβ”€β”€ role/                    # Role events
β”‚   β”‚   β”‚   └── voice/                   # Voice state events
β”‚   β”‚   β”œβ”€β”€ features/                    # Feature modules
β”‚   β”‚   β”‚   β”œβ”€β”€ clans/                   # Clan management system
β”‚   β”‚   β”‚   β”œβ”€β”€ compbuilder/             # Component builder
β”‚   β”‚   β”‚   β”œβ”€β”€ config/                   # Bot configuration commands
β”‚   β”‚   β”‚   β”œβ”€β”€ economy/                 # Economy & casino system
β”‚   β”‚   β”‚   β”œβ”€β”€ faq/                     # FAQ system
β”‚   β”‚   β”‚   β”œβ”€β”€ forum/                   # Forum integration
β”‚   β”‚   β”‚   β”œβ”€β”€ meta/                    # Meta commands (info, stats)
β”‚   β”‚   β”‚   β”œβ”€β”€ moderation/              # Moderation tools
β”‚   β”‚   β”‚   β”œβ”€β”€ private_rooms/           # Private voice rooms
β”‚   β”‚   β”‚   β”œβ”€β”€ proposals/               # Community voting system
β”‚   β”‚   β”‚   β”œβ”€β”€ role_requests/           # Role request system
β”‚   β”‚   β”‚   β”œβ”€β”€ system/                  # System commands
β”‚   β”‚   β”‚   └── tickets/                 # Support ticket system
β”‚   β”‚   β”œβ”€β”€ services/                    # Business logic services
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ tasks/                       # Background tasks
β”‚   β”‚   β”‚   β”œβ”€β”€ ...
β”‚   β”‚   └── utils/                       # Bot utilities
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ ...
β”‚   β”‚       β”œβ”€β”€ field_validators/         # Field validation utilities
β”‚   β”‚       β”œβ”€β”€ permissions/             # Permission helpers
β”‚   β”‚       └── transformers/            # Command transformers
β”‚   └── utils/                           # Shared utilities
β”‚       └── logging/                     # Logging configuration
β”‚           β”œβ”€β”€ config.py                 # Logging config
β”‚           └── setup.py                 # Logging setup
β”œβ”€β”€ migrations/                          # Alembic database migrations
β”‚   β”œβ”€β”€ drop_structure.sql               # Drop all triggers and functions
β”‚   β”œβ”€β”€ env.py                           # Alembic environment
β”‚   β”œβ”€β”€ README                           # Alembic readme
β”‚   β”œβ”€β”€ script.py.mako                   # Migration template
β”‚   β”œβ”€β”€ structure.sql                    # Full DB triggers and functions structure
β”‚   └── versions/                        # Migration versions
β”‚       └── ...
β”œβ”€β”€ docker/                              # Docker configuration
β”‚   β”œβ”€β”€ docker-entrypoint.sh             # Container entrypoint script
β”œβ”€β”€ main.py                              # Application entry point
β”œβ”€β”€ pyproject.toml                       # Project metadata & dependencies # rules
β”œβ”€β”€ docker-compose.yml                   # Docker orchestration
β”œβ”€β”€ Dockerfile                            # Docker image definition
β”œβ”€β”€ alembic.ini                          # Alembic configuration
β”œβ”€β”€ Makefile                              # Common development commands (only migrations)
β”œβ”€β”€ LICENSE                              # License file
└── README.md                            # This file

πŸ“ License

This project is licensed under the terms specified in the LICENSE file.

About

A feature-rich Discord bot for Arizona RP community with economy system, moderation tools, forum integration, and much more.

Resources

License

Stars

Watchers

Forks

Contributors

Languages