Compare commits
109 Commits
feat/web-s
...
5ff3fa9ab5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ff3fa9ab5 | ||
|
|
c8bf69a969 | ||
|
|
fee4969910 | ||
|
|
dabcb4cab3 | ||
|
|
1a3f5c6654 | ||
|
|
422db6479b | ||
|
|
35ecea16f7 | ||
|
|
9ff679ee5c | ||
|
|
ebefd8c0df | ||
|
|
73531f38ae | ||
|
|
5a6356d271 | ||
|
|
f9dafeac3b | ||
|
|
1a2bbb011c | ||
|
|
2ead35789d | ||
|
|
c1da71227d | ||
|
|
17e636c4e5 | ||
|
|
d7543d9f48 | ||
|
|
afe82c449b | ||
|
|
3c1334b30e | ||
|
|
58f261562a | ||
|
|
4ecbffd617 | ||
|
|
5491551544 | ||
|
|
7d658bbef9 | ||
|
|
d117bcb697 | ||
|
|
94e332ba57 | ||
|
|
3ef9773990 | ||
|
|
d243a11bd3 | ||
|
|
47ce0f12e6 | ||
|
|
f2caa1a3ee | ||
|
|
2a72beb0ef | ||
|
|
2f73f38877 | ||
|
|
9e5c6b5ac3 | ||
|
|
eb108695d3 | ||
|
|
7d541825d8 | ||
|
|
52f8ab11f0 | ||
|
|
f8436e9755 | ||
|
|
194a032c7f | ||
|
|
94a5a183d0 | ||
|
|
c7730b9355 | ||
|
|
1e20a5a7a0 | ||
|
|
54944283a3 | ||
|
|
f79ee6fbc7 | ||
|
|
915f1bc4ad | ||
|
|
4af2690bab | ||
|
|
6e57ab07e4 | ||
|
|
3a620a84c5 | ||
|
|
7d68652ea5 | ||
|
|
35bd1f58dd | ||
|
|
1cd3dbcd72 | ||
|
|
c97249f2ca | ||
|
|
0d923491b5 | ||
|
|
d870ef69d5 | ||
|
|
682e9d208e | ||
|
|
4a691ac71d | ||
|
|
1b84dbd36d | ||
|
|
a5b8d922e3 | ||
|
|
238d9a8803 | ||
|
|
713ea07040 | ||
|
|
bea6c33024 | ||
|
|
8fe300c8a2 | ||
|
|
9caa95a0d8 | ||
|
|
c6fd23b5fa | ||
|
|
d46434de18 | ||
|
|
cf4c28e1df | ||
|
|
39e405afde | ||
|
|
6763e3c543 | ||
|
|
11e07a0068 | ||
|
|
5d2d4bb0c6 | ||
|
|
19206b5cc7 | ||
|
|
0f6cce9b6e | ||
|
|
3f3a6c88e8 | ||
|
|
8253de9f73 | ||
|
|
1251df286e | ||
|
|
fff90804c0 | ||
|
|
8ebaf7b4ee | ||
|
|
17cb70ec00 | ||
|
|
a207d511be | ||
|
|
cf4f180124 | ||
|
|
5df1396b3f | ||
|
|
daad7be01c | ||
|
|
05f27ca604 | ||
|
|
d37059d50f | ||
|
|
caafe6b34d | ||
|
|
017f5ad818 | ||
|
|
f92415b89c | ||
|
|
3f028eb76a | ||
|
|
2b641c952d | ||
|
|
88b266f81b | ||
|
|
53a2f1ff0c | ||
|
|
dc15212ecf | ||
|
|
99e847175e | ||
|
|
b2c7fa6e83 | ||
|
|
9e7f18787b | ||
| 47507dd65a | |||
|
|
e6f94c3e71 | ||
|
|
66af870aa9 | ||
|
|
8047bce755 | ||
|
|
9804456257 | ||
|
|
259b8d6875 | ||
|
|
a2cb684b71 | ||
|
|
9c2098bc46 | ||
|
|
618d973863 | ||
|
|
63f55b6dfd | ||
|
|
ac4025e179 | ||
|
|
ff23f22337 | ||
|
|
292991c605 | ||
|
|
4640cd11a7 | ||
|
|
43a003f641 | ||
|
|
6f4426e49d |
@@ -1,57 +0,0 @@
|
|||||||
---
|
|
||||||
description: Create a new Ticket
|
|
||||||
---
|
|
||||||
|
|
||||||
### Role
|
|
||||||
You are a Senior Technical Product Manager and Lead Engineer. Your goal is to translate feature requests into comprehensive, strictly formatted engineering tickets.
|
|
||||||
|
|
||||||
### Task
|
|
||||||
When I ask you to "scope a feature" or "create a ticket" for a specific functionality:
|
|
||||||
1. Analyze the request for technical implications, edge cases, and architectural fit.
|
|
||||||
2. Generate a new Markdown file.
|
|
||||||
3. Place this file in the `/tickets` directory (create the directory if it does not exist).
|
|
||||||
|
|
||||||
### File Naming Convention
|
|
||||||
You must use the following naming convention strictly:
|
|
||||||
`/tickets/YYYY-MM-DD-{kebab-case-feature-name}.md`
|
|
||||||
|
|
||||||
*Example:* `/tickets/2024-10-12-user-authentication-flow.md`
|
|
||||||
|
|
||||||
### File Content Structure
|
|
||||||
The markdown file must adhere to the following template exactly. Do not skip sections. If a section is not applicable, write "N/A" but explain why.
|
|
||||||
|
|
||||||
```markdown
|
|
||||||
# [Ticket ID]: [Feature Title]
|
|
||||||
|
|
||||||
**Status:** Draft
|
|
||||||
**Created:** [YYYY-MM-DD]
|
|
||||||
**Tags:** [comma, separated, tags]
|
|
||||||
|
|
||||||
## 1. Context & User Story
|
|
||||||
* **As a:** [Role]
|
|
||||||
* **I want to:** [Action]
|
|
||||||
* **So that:** [Benefit/Value]
|
|
||||||
|
|
||||||
## 2. Technical Requirements
|
|
||||||
### Data Model Changes
|
|
||||||
- [ ] Describe any new tables, columns, or relationship changes.
|
|
||||||
- [ ] SQL migration required? (Yes/No)
|
|
||||||
|
|
||||||
### API / Interface
|
|
||||||
- [ ] Define endpoints (method, path) or function signatures.
|
|
||||||
- [ ] Payload definition (JSON structure or Types).
|
|
||||||
|
|
||||||
## 3. Constraints & Validations (CRITICAL)
|
|
||||||
*This section must be exhaustive. Do not be vague.*
|
|
||||||
- **Input Validation:** (e.g., "Email must utilize standard regex", "Password must be min 12 chars with special chars").
|
|
||||||
- **System Constraints:** (e.g., "Image upload max size 5MB", "Request timeout 30s").
|
|
||||||
- **Business Logic Guardrails:** (e.g., "User cannot upgrade if balance < $0").
|
|
||||||
|
|
||||||
## 4. Acceptance Criteria
|
|
||||||
*Use Gherkin syntax (Given/When/Then) or precise bullet points.*
|
|
||||||
1. [ ] Criteria 1
|
|
||||||
2. [ ] Criteria 2
|
|
||||||
|
|
||||||
## 5. Implementation Plan
|
|
||||||
- [ ] Step 1: ...
|
|
||||||
- [ ] Step 2: ...
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
---
|
|
||||||
description: Review the most recent changes critically.
|
|
||||||
---
|
|
||||||
|
|
||||||
### Role
|
|
||||||
You are a Lead Security Engineer and Senior QA Automator. Your persona is **"The Hostile Reviewer."**
|
|
||||||
* **Mindset:** You do not trust the code. You assume it contains bugs, security flaws, and logic gaps.
|
|
||||||
* **Goal:** Your objective is to reject the most recent git changes by finding legitimate issues. If you cannot find issues, only then do you approve.
|
|
||||||
|
|
||||||
### Phase 1: The Security & Logic Audit
|
|
||||||
Analyze the code changes for specific vulnerabilities. Do not summarize what the code does; look for what it *does wrong*.
|
|
||||||
|
|
||||||
1. **TypeScript Strictness:**
|
|
||||||
* Flag any usage of `any`.
|
|
||||||
* Flag any use of non-null assertions (`!`) unless strictly guarded.
|
|
||||||
* Flag forced type casting (`as UnknownType`) without validation.
|
|
||||||
2. **Bun/Runtime Specifics:**
|
|
||||||
* Check for unhandled Promises (floating promises).
|
|
||||||
* Ensure environment variables are not hardcoded.
|
|
||||||
3. **Security Vectors:**
|
|
||||||
* **Injection:** Check SQL/NoSQL queries for concatenation.
|
|
||||||
* **Sanitization:** Are inputs from the generic request body validated against the schema defined in the Ticket?
|
|
||||||
* **Auth:** Are sensitive routes actually protected by middleware?
|
|
||||||
|
|
||||||
### Phase 2: Test Quality Verification
|
|
||||||
Do not just check if tests pass. Check if the tests are **valid**.
|
|
||||||
1. **The "Happy Path" Trap:** If the tests only check for success (status 200), **FAIL** the review.
|
|
||||||
2. **Edge Case Coverage:**
|
|
||||||
* Did the code handle the *Constraints & Validations* listed in the original ticket?
|
|
||||||
* *Example:* If the ticket says "Max 5MB upload", is there a test case for a 5.1MB file?
|
|
||||||
3. **Mocking Integrity:** Are mocks too permissive? (e.g., Mocking a function to always return `true` regardless of input).
|
|
||||||
|
|
||||||
### Phase 3: The Verdict
|
|
||||||
Output your review in the following strict format:
|
|
||||||
|
|
||||||
---
|
|
||||||
# 🛡️ Code Review Report
|
|
||||||
|
|
||||||
**Ticket ID:** [Ticket Name]
|
|
||||||
**Verdict:** [🔴 REJECT / 🟢 APPROVE]
|
|
||||||
|
|
||||||
## 🚨 Critical Issues (Must Fix)
|
|
||||||
*List logic bugs, security risks, or failing tests.*
|
|
||||||
1. ...
|
|
||||||
2. ...
|
|
||||||
|
|
||||||
## ⚠️ Suggestions (Refactoring)
|
|
||||||
*List code style improvements, variable naming, or DRY opportunities.*
|
|
||||||
1. ...
|
|
||||||
|
|
||||||
## 🧪 Test Coverage Gap Analysis
|
|
||||||
*List specific scenarios that are NOT currently tested but should be.*
|
|
||||||
- [ ] Scenario: ...
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
---
|
|
||||||
description: Pick a Ticket and work on it.
|
|
||||||
---
|
|
||||||
|
|
||||||
### Role
|
|
||||||
You are an Autonomous Senior Software Engineer specializing in TypeScript and Bun. You are responsible for the full lifecycle of feature implementation: selection, coding, testing, verification, and closure.
|
|
||||||
|
|
||||||
|
|
||||||
### Phase 1: Triage & Selection
|
|
||||||
1. **Scan:** Read all files in the `/tickets` directory.
|
|
||||||
2. **Filter:** Ignore tickets marked `Status: Done` or `Status: Archived`.
|
|
||||||
3. **Prioritize:** Select a single ticket based on the following hierarchy:
|
|
||||||
* **Tags:** `Critical` > `High Priority` > `Bug` > `Feature`.
|
|
||||||
* **Age:** Oldest created date first (FIFO).
|
|
||||||
4. **Announce:** Explicitly state: "I am picking ticket: [Ticket ID/Name] because [Reason]."
|
|
||||||
|
|
||||||
### Phase 2: Setup (Non-Destructive)
|
|
||||||
1. **Branching:** Create a new git branch based on the ticket name.
|
|
||||||
* *Format:* `feat/{ticket-kebab-name}` or `fix/{ticket-kebab-name}`.
|
|
||||||
* *Command:* `git checkout -b feat/user-auth-flow`.
|
|
||||||
2. **Context:** Read the selected ticket markdown file thoroughly, paying special attention to "Constraints & Validations."
|
|
||||||
|
|
||||||
### Phase 3: Implementation & Testing (The Loop)
|
|
||||||
*Iterate until the requirements are met.*
|
|
||||||
|
|
||||||
1. **Write Code:** Implement the feature or fix using TypeScript.
|
|
||||||
2. **Tightened Testing:**
|
|
||||||
* You must create or update test files (`*.test.ts` or `*.spec.ts`).
|
|
||||||
* **Requirement:** Tests must cover happy paths AND the edge cases defined in the ticket's "Constraints" section.
|
|
||||||
* *Mocking:* Mock external dependencies where appropriate to ensure isolation.
|
|
||||||
3. **Type Safety Check:**
|
|
||||||
* Run: `bun x tsc --noEmit`
|
|
||||||
* **CRITICAL:** If there are ANY TypeScript errors, you must fix them immediately. Do not proceed.
|
|
||||||
4. **Runtime Verification:**
|
|
||||||
* Run: `bun test`
|
|
||||||
* Ensure all tests pass. If a test fails, analyze the stack trace, fix the implementation, and rerun.
|
|
||||||
|
|
||||||
### Phase 4: Self-Review & Clean Up
|
|
||||||
Before declaring the task finished, perform a self-review:
|
|
||||||
1. **Linting:** Check for unused variables, any types, or console logs.
|
|
||||||
2. **Refactor:** Ensure code is DRY (Don't Repeat Yourself) and strictly typed.
|
|
||||||
3. **Ticket Update:**
|
|
||||||
* Modify the Markdown ticket file.
|
|
||||||
* Change `Status: Draft` to `Status: In Review` or `Status: Done`.
|
|
||||||
* Add a new section at the bottom: `## Implementation Notes` listing the specific files changed.
|
|
||||||
|
|
||||||
### Phase 5: Handover
|
|
||||||
Only when `bun x tsc` and `bun test` pass with 0 errors:
|
|
||||||
1. Commit the changes with a semantic message (e.g., `feat: implement user auth logic`).
|
|
||||||
2. Present a summary of the work done and ask for a human code review.
|
|
||||||
39
.dockerignore
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Dependencies - handled inside container
|
||||||
|
node_modules
|
||||||
|
web/node_modules
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Logs and data
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
shared/db/data
|
||||||
|
shared/db/log
|
||||||
|
|
||||||
|
# Development tools
|
||||||
|
.env
|
||||||
|
.env.example
|
||||||
|
.opencode
|
||||||
|
.agent
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
docs
|
||||||
|
*.md
|
||||||
|
!README.md
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
dist
|
||||||
|
.cache
|
||||||
|
*.tsbuildinfo
|
||||||
18
.env.example
@@ -1,12 +1,26 @@
|
|||||||
|
# =============================================================================
|
||||||
|
# Aurora Environment Configuration
|
||||||
|
# =============================================================================
|
||||||
|
# Copy this file to .env and update with your values
|
||||||
|
# For production, see .env.prod.example with security recommendations
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# For production: use a strong password (openssl rand -base64 32)
|
||||||
DB_USER=aurora
|
DB_USER=aurora
|
||||||
DB_PASSWORD=aurora
|
DB_PASSWORD=aurora
|
||||||
DB_NAME=aurora
|
DB_NAME=aurora
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_HOST=db
|
DB_HOST=db
|
||||||
|
DATABASE_URL=postgres://aurora:aurora@db:5432/aurora
|
||||||
|
|
||||||
|
# Discord
|
||||||
|
# Get from: https://discord.com/developers/applications
|
||||||
DISCORD_BOT_TOKEN=your-discord-bot-token
|
DISCORD_BOT_TOKEN=your-discord-bot-token
|
||||||
DISCORD_CLIENT_ID=your-discord-client-id
|
DISCORD_CLIENT_ID=your-discord-client-id
|
||||||
DISCORD_GUILD_ID=your-discord-guild-id
|
DISCORD_GUILD_ID=your-discord-guild-id
|
||||||
DATABASE_URL=postgres://aurora:aurora@db:5432/aurora
|
|
||||||
|
|
||||||
VPS_USER=your-vps-user
|
# Server (for remote access scripts)
|
||||||
|
# Use a non-root user (see shared/scripts/setup-server.sh)
|
||||||
|
VPS_USER=deploy
|
||||||
VPS_HOST=your-vps-ip
|
VPS_HOST=your-vps-ip
|
||||||
|
|||||||
38
.env.prod.example
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# =============================================================================
|
||||||
|
# Aurora Production Environment Template
|
||||||
|
# =============================================================================
|
||||||
|
# Copy this file to .env and fill in the values
|
||||||
|
# IMPORTANT: Use strong, unique passwords in production!
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Database Configuration
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Generate strong password: openssl rand -base64 32
|
||||||
|
DB_USER=aurora_prod
|
||||||
|
DB_PASSWORD=CHANGE_ME_USE_STRONG_PASSWORD
|
||||||
|
DB_NAME=aurora_prod
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_HOST=localhost
|
||||||
|
|
||||||
|
# Constructed database URL (used by Drizzle)
|
||||||
|
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Discord Configuration
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Get these from Discord Developer Portal: https://discord.com/developers
|
||||||
|
DISCORD_BOT_TOKEN=your_bot_token_here
|
||||||
|
DISCORD_CLIENT_ID=your_client_id_here
|
||||||
|
DISCORD_GUILD_ID=your_guild_id_here
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Server Configuration (for SSH deployment scripts)
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Use a non-root user for security!
|
||||||
|
VPS_USER=deploy
|
||||||
|
VPS_HOST=your_server_ip_here
|
||||||
|
|
||||||
|
# Optional: Custom ports for remote access
|
||||||
|
# DASHBOARD_PORT=3000
|
||||||
|
# STUDIO_PORT=4983
|
||||||
136
.github/workflows/deploy.yml
vendored
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Aurora CI/CD Pipeline
|
||||||
|
# Builds, tests, and deploys to production server
|
||||||
|
|
||||||
|
name: Deploy to Production
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch: # Allow manual trigger
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# ==========================================================================
|
||||||
|
# Test Job
|
||||||
|
# ==========================================================================
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: latest
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
run: bash shared/scripts/test-sequential.sh
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# Build Job
|
||||||
|
# ==========================================================================
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
outputs:
|
||||||
|
image_tag: ${{ steps.meta.outputs.tags }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=sha,prefix=
|
||||||
|
type=raw,value=latest
|
||||||
|
|
||||||
|
- name: Build and Push Docker Image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile.prod
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# Deploy Job
|
||||||
|
# ==========================================================================
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment: production
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Deploy to Production Server
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.VPS_HOST }}
|
||||||
|
username: ${{ secrets.VPS_USER }}
|
||||||
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
script: |
|
||||||
|
cd ~/Aurora
|
||||||
|
|
||||||
|
# Pull latest code
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# Pull latest Docker image
|
||||||
|
docker compose -f docker-compose.prod.yml pull 2>/dev/null || true
|
||||||
|
|
||||||
|
# Build and restart containers
|
||||||
|
docker compose -f docker-compose.prod.yml build --no-cache
|
||||||
|
docker compose -f docker-compose.prod.yml down
|
||||||
|
docker compose -f docker-compose.prod.yml up -d
|
||||||
|
|
||||||
|
# Wait for health checks
|
||||||
|
sleep 15
|
||||||
|
|
||||||
|
# Verify deployment
|
||||||
|
docker ps | grep aurora
|
||||||
|
|
||||||
|
# Cleanup old images
|
||||||
|
docker image prune -f
|
||||||
|
|
||||||
|
- name: Verify Deployment
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.VPS_HOST }}
|
||||||
|
username: ${{ secrets.VPS_USER }}
|
||||||
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
script: |
|
||||||
|
# Check if app container is healthy
|
||||||
|
if docker ps | grep -q "aurora_app.*healthy"; then
|
||||||
|
echo "✅ Deployment successful - aurora_app is healthy"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "⚠️ Health check pending, checking container status..."
|
||||||
|
docker ps | grep aurora
|
||||||
|
docker logs aurora_app --tail 20
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
8
.gitignore
vendored
@@ -1,7 +1,9 @@
|
|||||||
.env
|
.env
|
||||||
node_modules
|
node_modules
|
||||||
db-logs
|
docker-compose.override.yml
|
||||||
db-data
|
shared/db-logs
|
||||||
|
shared/db/data
|
||||||
|
shared/db/loga
|
||||||
.cursor
|
.cursor
|
||||||
# dependencies (bun install)
|
# dependencies (bun install)
|
||||||
|
|
||||||
@@ -44,4 +46,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||||||
src/db/data
|
src/db/data
|
||||||
src/db/log
|
src/db/log
|
||||||
scratchpad/
|
scratchpad/
|
||||||
|
tickets/
|
||||||
244
AGENTS.md
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
# AGENTS.md - AI Coding Agent Guidelines
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
AuroraBot is a Discord bot with a web dashboard built using Bun, Discord.js, React, and PostgreSQL with Drizzle ORM.
|
||||||
|
|
||||||
|
## Build/Lint/Test Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Development
|
||||||
|
bun --watch bot/index.ts # Run bot with hot reload
|
||||||
|
bun --hot web/src/index.ts # Run web dashboard with hot reload
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
bun test # Run all tests ( expect some tests to fail when running all at once like this due to the nature of the tests )
|
||||||
|
bun test path/to/file.test.ts # Run single test file
|
||||||
|
bun test --watch # Watch mode
|
||||||
|
bun test shared/modules/economy # Run tests in directory
|
||||||
|
|
||||||
|
# Database
|
||||||
|
bun run generate # Generate Drizzle migrations (Docker)
|
||||||
|
bun run migrate # Run migrations (Docker)
|
||||||
|
bun run db:push # Push schema changes (Docker)
|
||||||
|
bun run db:push:local # Push schema changes (local)
|
||||||
|
bun run db:studio # Open Drizzle Studio
|
||||||
|
|
||||||
|
# Web Dashboard
|
||||||
|
cd web && bun run build # Build production web assets
|
||||||
|
cd web && bun run dev # Development server
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
bot/ # Discord bot
|
||||||
|
├── commands/ # Slash commands by category
|
||||||
|
├── events/ # Discord event handlers
|
||||||
|
├── lib/ # Bot core (BotClient, handlers, loaders)
|
||||||
|
├── modules/ # Feature modules (views, interactions)
|
||||||
|
└── graphics/ # Canvas image generation
|
||||||
|
|
||||||
|
shared/ # Shared between bot and web
|
||||||
|
├── db/ # Database schema and migrations
|
||||||
|
├── lib/ # Utils, config, errors, types
|
||||||
|
└── modules/ # Domain services (economy, user, etc.)
|
||||||
|
|
||||||
|
web/ # React dashboard
|
||||||
|
├── src/pages/ # React pages
|
||||||
|
├── src/components/ # UI components (ShadCN/Radix)
|
||||||
|
└── src/hooks/ # React hooks
|
||||||
|
```
|
||||||
|
|
||||||
|
## Import Conventions
|
||||||
|
|
||||||
|
Use path aliases defined in tsconfig.json:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// External packages first
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
|
// Path aliases second
|
||||||
|
import { economyService } from "@shared/modules/economy/economy.service";
|
||||||
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
import { users } from "@db/schema";
|
||||||
|
import { createErrorEmbed } from "@lib/embeds";
|
||||||
|
import { handleTradeInteraction } from "@modules/trade/trade.interaction";
|
||||||
|
|
||||||
|
// Relative imports last
|
||||||
|
import { localHelper } from "./helper";
|
||||||
|
```
|
||||||
|
|
||||||
|
**Available Aliases:**
|
||||||
|
|
||||||
|
- `@/*` - bot/
|
||||||
|
- `@shared/*` - shared/
|
||||||
|
- `@db/*` - shared/db/
|
||||||
|
- `@lib/*` - bot/lib/
|
||||||
|
- `@modules/*` - bot/modules/
|
||||||
|
- `@commands/*` - bot/commands/
|
||||||
|
|
||||||
|
## Naming Conventions
|
||||||
|
|
||||||
|
| Element | Convention | Example |
|
||||||
|
| ---------------- | ----------------------- | ---------------------------------------- |
|
||||||
|
| Files | camelCase or kebab-case | `BotClient.ts`, `economy.service.ts` |
|
||||||
|
| Classes | PascalCase | `CommandHandler`, `UserError` |
|
||||||
|
| Functions | camelCase | `createCommand`, `handleShopInteraction` |
|
||||||
|
| Constants | UPPER_SNAKE_CASE | `EVENTS`, `BRANDING` |
|
||||||
|
| Enums | PascalCase | `TimerType`, `TransactionType` |
|
||||||
|
| Services | camelCase singleton | `economyService`, `userService` |
|
||||||
|
| Types/Interfaces | PascalCase | `Command`, `Event`, `GameConfigType` |
|
||||||
|
| DB tables | snake_case | `users`, `moderation_cases` |
|
||||||
|
| Custom IDs | snake_case with prefix | `shop_buy_`, `trade_accept_` |
|
||||||
|
|
||||||
|
## Code Patterns
|
||||||
|
|
||||||
|
### Command Definition
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export const commandName = createCommand({
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("commandname")
|
||||||
|
.setDescription("Description"),
|
||||||
|
execute: async (interaction) => {
|
||||||
|
await interaction.deferReply();
|
||||||
|
// Implementation
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Service Pattern (Singleton Object)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export const serviceName = {
|
||||||
|
methodName: async (params: ParamType): Promise<ReturnType> => {
|
||||||
|
return await withTransaction(async (tx) => {
|
||||||
|
// Database operations
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Module File Organization
|
||||||
|
|
||||||
|
- `*.view.ts` - Creates Discord embeds/components
|
||||||
|
- `*.interaction.ts` - Handles button/select/modal interactions
|
||||||
|
- `*.types.ts` - Module-specific TypeScript types
|
||||||
|
- `*.service.ts` - Business logic (in shared/modules/)
|
||||||
|
- `*.test.ts` - Test files (co-located with source)
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
### Custom Error Classes
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { UserError, SystemError } from "@shared/lib/errors";
|
||||||
|
|
||||||
|
// User-facing errors (shown to user)
|
||||||
|
throw new UserError("You don't have enough coins!");
|
||||||
|
|
||||||
|
// System errors (logged, generic message shown)
|
||||||
|
throw new SystemError("Database connection failed");
|
||||||
|
```
|
||||||
|
|
||||||
|
### Standard Error Pattern
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
try {
|
||||||
|
const result = await service.method();
|
||||||
|
await interaction.editReply({ embeds: [createSuccessEmbed(result)] });
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof UserError) {
|
||||||
|
await interaction.editReply({ embeds: [createErrorEmbed(error.message)] });
|
||||||
|
} else {
|
||||||
|
console.error("Unexpected error:", error);
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createErrorEmbed("An unexpected error occurred.")],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Database Patterns
|
||||||
|
|
||||||
|
### Transaction Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { withTransaction } from "@/lib/db";
|
||||||
|
|
||||||
|
return await withTransaction(async (tx) => {
|
||||||
|
const user = await tx.query.users.findFirst({
|
||||||
|
where: eq(users.id, discordId),
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx
|
||||||
|
.update(users)
|
||||||
|
.set({ coins: newBalance })
|
||||||
|
.where(eq(users.id, discordId));
|
||||||
|
await tx.insert(transactions).values({ userId: discordId, amount, type });
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}, existingTx); // Pass existing tx if in nested transaction
|
||||||
|
```
|
||||||
|
|
||||||
|
### Schema Notes
|
||||||
|
|
||||||
|
- Use `bigint` mode for Discord IDs and currency amounts
|
||||||
|
- Relations defined separately from table definitions
|
||||||
|
- Schema location: `shared/db/schema.ts`
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
### Test File Structure
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
||||||
|
|
||||||
|
// Mock modules BEFORE imports
|
||||||
|
mock.module("@shared/db/DrizzleClient", () => ({
|
||||||
|
DrizzleClient: { query: mockQuery },
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("serviceName", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockFn.mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle expected case", async () => {
|
||||||
|
// Arrange
|
||||||
|
mockFn.mockResolvedValue(testData);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = await service.method(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
expect(mockFn).toHaveBeenCalledWith(expectedArgs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tech Stack
|
||||||
|
|
||||||
|
- **Runtime:** Bun 1.0+
|
||||||
|
- **Bot:** Discord.js 14.x
|
||||||
|
- **Web:** React 19 + Bun HTTP Server
|
||||||
|
- **Database:** PostgreSQL 16+ with Drizzle ORM
|
||||||
|
- **UI:** Tailwind CSS v4 + ShadCN/Radix
|
||||||
|
- **Validation:** Zod
|
||||||
|
- **Testing:** Bun Test
|
||||||
|
- **Container:** Docker
|
||||||
|
|
||||||
|
## Key Files Reference
|
||||||
|
|
||||||
|
| Purpose | File |
|
||||||
|
| ------------- | ---------------------- |
|
||||||
|
| Bot entry | `bot/index.ts` |
|
||||||
|
| DB schema | `shared/db/schema.ts` |
|
||||||
|
| Error classes | `shared/lib/errors.ts` |
|
||||||
|
| Config loader | `shared/lib/config.ts` |
|
||||||
|
| Environment | `shared/lib/env.ts` |
|
||||||
|
| Embed helpers | `bot/lib/embeds.ts` |
|
||||||
|
| Command utils | `shared/lib/utils.ts` |
|
||||||
52
Dockerfile
@@ -1,17 +1,55 @@
|
|||||||
|
# ============================================
|
||||||
|
# Base stage - shared configuration
|
||||||
|
# ============================================
|
||||||
FROM oven/bun:latest AS base
|
FROM oven/bun:latest AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install system dependencies
|
# Install system dependencies with cleanup in same layer
|
||||||
RUN apt-get update && apt-get install -y git
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends git && \
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
# Install dependencies
|
# ============================================
|
||||||
|
# Dependencies stage - installs all deps
|
||||||
|
# ============================================
|
||||||
|
FROM base AS deps
|
||||||
|
|
||||||
|
# Copy only package files first (better layer caching)
|
||||||
COPY package.json bun.lock ./
|
COPY package.json bun.lock ./
|
||||||
RUN bun install --frozen-lockfile
|
COPY web/package.json web/bun.lock ./web/
|
||||||
|
|
||||||
# Copy source code
|
# Install all dependencies in one layer
|
||||||
COPY . .
|
RUN bun install --frozen-lockfile && \
|
||||||
|
cd web && bun install --frozen-lockfile
|
||||||
|
|
||||||
# Expose port
|
# ============================================
|
||||||
|
# Development stage - for local dev with volume mounts
|
||||||
|
# ============================================
|
||||||
|
FROM base AS development
|
||||||
|
|
||||||
|
# Copy dependencies from deps stage
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY --from=deps /app/web/node_modules ./web/node_modules
|
||||||
|
|
||||||
|
# Expose ports
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Default command
|
||||||
|
CMD ["bun", "run", "dev"]
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Production stage - full app with source code
|
||||||
|
# ============================================
|
||||||
|
FROM base AS production
|
||||||
|
|
||||||
|
# Copy dependencies from deps stage
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY --from=deps /app/web/node_modules ./web/node_modules
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Expose ports
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Default command
|
# Default command
|
||||||
|
|||||||
57
Dockerfile.prod
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# =============================================================================
|
||||||
|
# Stage 1: Dependencies & Build
|
||||||
|
# =============================================================================
|
||||||
|
FROM oven/bun:latest AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install system dependencies needed for build
|
||||||
|
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install root project dependencies
|
||||||
|
COPY package.json bun.lock ./
|
||||||
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
|
# Install web project dependencies
|
||||||
|
COPY web/package.json web/bun.lock ./web/
|
||||||
|
RUN cd web && bun install --frozen-lockfile
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build web assets for production
|
||||||
|
RUN cd web && bun run build
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Stage 2: Production Runtime
|
||||||
|
# =============================================================================
|
||||||
|
FROM oven/bun:latest AS production
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Create non-root user for security (bun user already exists with 1000:1000)
|
||||||
|
# No need to create user/group
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Copy only what's needed for production
|
||||||
|
COPY --from=builder --chown=bun:bun /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder --chown=bun:bun /app/web/node_modules ./web/node_modules
|
||||||
|
COPY --from=builder --chown=bun:bun /app/web/dist ./web/dist
|
||||||
|
COPY --from=builder --chown=bun:bun /app/web/src ./web/src
|
||||||
|
COPY --from=builder --chown=bun:bun /app/bot ./bot
|
||||||
|
COPY --from=builder --chown=bun:bun /app/shared ./shared
|
||||||
|
COPY --from=builder --chown=bun:bun /app/package.json .
|
||||||
|
COPY --from=builder --chown=bun:bun /app/drizzle.config.ts .
|
||||||
|
COPY --from=builder --chown=bun:bun /app/tsconfig.json .
|
||||||
|
|
||||||
|
# Switch to non-root user
|
||||||
|
USER bun
|
||||||
|
|
||||||
|
# Expose web dashboard port
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Health check
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||||
|
CMD bun -e "fetch('http://localhost:3000/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"
|
||||||
|
|
||||||
|
# Run in production mode
|
||||||
|
CMD ["bun", "run", "bot/index.ts"]
|
||||||
67
README.md
@@ -7,24 +7,44 @@
|
|||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
Aurora is a powerful Discord bot designed to facilitate RPG-like elements within a Discord server. It features a robust economy, class system, inventory management, quests, and more, all built on top of a high-performance stack using Bun and Drizzle ORM.
|
Aurora is a powerful Discord bot designed to facilitate RPG-like elements within a Discord server. It features a robust economy, class system, inventory management, quests, and more, all built on top of a high-performance stack using Bun and Drizzle ORM.
|
||||||
|
|
||||||
|
**New in v1.0:** Aurora now includes a fully integrated **Web Dashboard** for managing the bot, viewing statistics, and configuring settings, running alongside the bot in a single process.
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|
||||||
|
### Discord Bot
|
||||||
* **Class System**: Users can join different classes.
|
* **Class System**: Users can join different classes.
|
||||||
* **Economy**: Complete economy system with balance, transactions, and daily rewards.
|
* **Economy**: Complete economy system with balance, transactions, and daily rewards.
|
||||||
* **Inventory & Items**: sophisticated item system with rarities, types (Material, Consumable, etc.), and inventory management.
|
* **Inventory & Items**: Sophisticated item system with rarities, types (Material, Consumable, etc.), and inventory management.
|
||||||
* **Leveling**: XP-based leveling system to track user activity and progress.
|
* **Leveling**: XP-based leveling system to track user activity and progress.
|
||||||
* **Quests**: Quest system with requirements and rewards.
|
* **Quests**: Quest system with requirements and rewards.
|
||||||
* **Trading**: Secure trading system between users.
|
* **Trading**: Secure trading system between users.
|
||||||
* **Lootdrops**: Random loot drops in channels to engage users.
|
* **Lootdrops**: Random loot drops in channels to engage users.
|
||||||
* **Admin Tools**: Administrative commands for server management.
|
* **Admin Tools**: Administrative commands for server management.
|
||||||
|
|
||||||
|
### Web Dashboard
|
||||||
|
* **Live Analytics**: View real-time activity charts (commands, transactions).
|
||||||
|
* **Configuration Management**: Update bot settings without restarting.
|
||||||
|
* **Database Inspection**: Integrated Drizzle Studio access.
|
||||||
|
* **State Monitoring**: View internal bot state (Lootdrops, etc.).
|
||||||
|
|
||||||
|
## 🏗️ Architecture
|
||||||
|
|
||||||
|
Aurora uses a **Single Process Monolith** architecture to maximize performance and simplify resource sharing.
|
||||||
|
|
||||||
|
* **Unified Runtime**: Both the Discord Client and the Web Dashboard run within the same Bun process.
|
||||||
|
* **Shared State**: This allows the Dashboard to access live bot memory (caches, gateways) directly without complex inter-process communication (IPC).
|
||||||
|
* **Simplified Deployment**: You only need to deploy a single Docker container.
|
||||||
|
|
||||||
## 🛠️ Tech Stack
|
## 🛠️ Tech Stack
|
||||||
|
|
||||||
* **Runtime**: [Bun](https://bun.sh/)
|
* **Runtime**: [Bun](https://bun.sh/)
|
||||||
* **Framework**: [Discord.js](https://discord.js.org/)
|
* **Bot Framework**: [Discord.js](https://discord.js.org/)
|
||||||
|
* **Web Framework**: [React 19](https://react.dev/) + [Vite](https://vitejs.dev/) (served via Bun)
|
||||||
|
* **Styling**: [Tailwind CSS v4](https://tailwindcss.com/) + [Radix UI](https://www.radix-ui.com/)
|
||||||
* **Database**: [PostgreSQL](https://www.postgresql.org/)
|
* **Database**: [PostgreSQL](https://www.postgresql.org/)
|
||||||
* **ORM**: [Drizzle ORM](https://orm.drizzle.team/)
|
* **ORM**: [Drizzle ORM](https://orm.drizzle.team/)
|
||||||
* **Validation**: [Zod](https://zod.dev/)
|
* **Validation**: [Zod](https://zod.dev/)
|
||||||
@@ -74,12 +94,14 @@ Aurora is a powerful Discord bot designed to facilitate RPG-like elements within
|
|||||||
bun run db:push
|
bun run db:push
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running the Bot
|
### Running the Bot & Dashboard
|
||||||
|
|
||||||
**Development Mode** (with hot reload):
|
**Development Mode** (with hot reload):
|
||||||
```bash
|
```bash
|
||||||
bun run dev
|
bun run dev
|
||||||
```
|
```
|
||||||
|
* Bot: Online in Discord
|
||||||
|
* Dashboard: http://localhost:3000
|
||||||
|
|
||||||
**Production Mode**:
|
**Production Mode**:
|
||||||
Build and run with Docker (recommended):
|
Build and run with Docker (recommended):
|
||||||
@@ -87,27 +109,46 @@ Build and run with Docker (recommended):
|
|||||||
docker compose up -d app
|
docker compose up -d app
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 🔐 Accessing Production Services (SSH Tunnel)
|
||||||
|
|
||||||
|
For security, the Production Database and Dashboard are **not exposed** to the public internet by default. They are only accessible via localhost on the server.
|
||||||
|
|
||||||
|
To access them from your local machine, use the included SSH tunnel script.
|
||||||
|
|
||||||
|
1. Add your VPS details to your local `.env` file:
|
||||||
|
```env
|
||||||
|
VPS_USER=root
|
||||||
|
VPS_HOST=123.45.67.89
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run the remote connection script:
|
||||||
|
```bash
|
||||||
|
bun run remote
|
||||||
|
```
|
||||||
|
|
||||||
|
This will establish secure tunnels for:
|
||||||
|
* **Dashboard**: http://localhost:3000
|
||||||
|
* **Drizzle Studio**: http://localhost:4983
|
||||||
|
|
||||||
## 📜 Scripts
|
## 📜 Scripts
|
||||||
|
|
||||||
* `bun run dev`: Start the bot in watch mode.
|
* `bun run dev`: Start the bot and dashboard in watch mode.
|
||||||
|
* `bun run remote`: Open SSH tunnel to production services.
|
||||||
* `bun run generate`: Generate Drizzle migrations.
|
* `bun run generate`: Generate Drizzle migrations.
|
||||||
* `bun run migrate`: Apply migrations (via Docker).
|
* `bun run migrate`: Apply migrations (via Docker).
|
||||||
* `bun run db:push`: Push, schema to DB (via Docker).
|
|
||||||
* `bun run db:studio`: Open Drizzle Studio to inspect the database.
|
* `bun run db:studio`: Open Drizzle Studio to inspect the database.
|
||||||
* `bun test`: Run tests.
|
* `bun test`: Run tests.
|
||||||
|
|
||||||
## 📂 Project Structure
|
## 📂 Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
├── src
|
├── bot # Discord Bot logic & entry point
|
||||||
│ ├── commands # Slash commands
|
├── web # React Web Dashboard (Frontend + Server)
|
||||||
│ ├── events # Discord event handlers
|
├── shared # Shared code (Database, Config, Types)
|
||||||
│ ├── modules # Feature modules (Economy, Inventory, etc.)
|
|
||||||
│ ├── db # Database schema and connection
|
|
||||||
│ └── lib # Shared utilities
|
|
||||||
├── drizzle # Drizzle migration files
|
├── drizzle # Drizzle migration files
|
||||||
├── config # Configuration files
|
├── scripts # Utility scripts
|
||||||
└── scripts # Utility scripts
|
├── docker-compose.yml
|
||||||
|
└── package.json
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🤝 Contributing
|
## 🤝 Contributing
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { getCaseEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getCaseEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const moderationCase = createCommand({
|
export const moderationCase = createCommand({
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { getCasesListEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getCasesListEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const cases = createCommand({
|
export const cases = createCommand({
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { getClearSuccessEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getClearSuccessEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const clearwarning = createCommand({
|
export const clearwarning = createCommand({
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ModalSubmitInteraction } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ModalSubmitInteraction } from "discord.js";
|
||||||
import { config, saveConfig } from "@lib/config";
|
import { config, saveConfig } from "@shared/lib/config";
|
||||||
import type { GameConfigType } from "@lib/config";
|
import type { GameConfigType } from "@shared/lib/config";
|
||||||
import { createSuccessEmbed, createErrorEmbed } from "@lib/embeds";
|
import { createSuccessEmbed, createErrorEmbed } from "@lib/embeds";
|
||||||
|
|
||||||
export const configCommand = createCommand({
|
export const configCommand = createCommand({
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, AttachmentBuilder } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, AttachmentBuilder } from "discord.js";
|
||||||
import { config, saveConfig } from "@/lib/config";
|
import { config, saveConfig } from "@shared/lib/config";
|
||||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import { items } from "@/db/schema";
|
import { items } from "@db/schema";
|
||||||
import { createSuccessEmbed, createErrorEmbed } from "@lib/embeds";
|
import { createSuccessEmbed, createErrorEmbed } from "@lib/embeds";
|
||||||
|
|
||||||
export const createColor = createCommand({
|
export const createColor = createCommand({
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { renderWizard } from "@/modules/admin/item_wizard";
|
import { renderWizard } from "@/modules/admin/item_wizard";
|
||||||
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { createBaseEmbed } from "@lib/embeds";
|
import { createBaseEmbed } from "@lib/embeds";
|
||||||
import { configManager } from "@/lib/configManager";
|
import { config, reloadConfig, toggleCommand } from "@shared/lib/config";
|
||||||
import { config, reloadConfig } from "@/lib/config";
|
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
|
|
||||||
export const features = createCommand({
|
export const features = createCommand({
|
||||||
@@ -79,11 +78,11 @@ export const features = createCommand({
|
|||||||
|
|
||||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
configManager.toggleCommand(commandName, enabled);
|
toggleCommand(commandName, enabled);
|
||||||
|
|
||||||
await interaction.editReply({ content: `✅ Command **${commandName}** has been ${enabled ? "enabled" : "disabled"}. Reloading configuration...` });
|
await interaction.editReply({ content: `✅ Command **${commandName}** has been ${enabled ? "enabled" : "disabled"}. Reloading configuration...` });
|
||||||
|
|
||||||
// Reload config from disk (which was updated by configManager)
|
// Reload config from disk (which was updated by toggleCommand)
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
await AuroraClient.loadCommands(true);
|
await AuroraClient.loadCommands(true);
|
||||||
@@ -5,7 +5,7 @@ import { AuroraClient } from "@/lib/BotClient";
|
|||||||
|
|
||||||
// Mock DrizzleClient
|
// Mock DrizzleClient
|
||||||
const executeMock = mock(() => Promise.resolve());
|
const executeMock = mock(() => Promise.resolve());
|
||||||
mock.module("@/lib/DrizzleClient", () => ({
|
mock.module("@shared/db/DrizzleClient", () => ({
|
||||||
DrizzleClient: {
|
DrizzleClient: {
|
||||||
execute: executeMock
|
execute: executeMock
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, Colors } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, Colors } from "discord.js";
|
||||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { createBaseEmbed } from "@lib/embeds";
|
import { createBaseEmbed } from "@lib/embeds";
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import {
|
import {
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
@@ -8,12 +8,12 @@ import {
|
|||||||
PermissionFlagsBits,
|
PermissionFlagsBits,
|
||||||
MessageFlags
|
MessageFlags
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { createSuccessEmbed, createErrorEmbed, createBaseEmbed } from "@lib/embeds";
|
import { createSuccessEmbed, createErrorEmbed, createBaseEmbed } from "@lib/embeds";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
import { items } from "@/db/schema";
|
import { items } from "@db/schema";
|
||||||
import { ilike, isNotNull, and } from "drizzle-orm";
|
import { ilike, isNotNull, and } from "drizzle-orm";
|
||||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import { getShopListingMessage } from "@/modules/economy/shop.view";
|
import { getShopListingMessage } from "@/modules/economy/shop.view";
|
||||||
|
|
||||||
export const listing = createCommand({
|
export const listing = createCommand({
|
||||||
@@ -65,10 +65,10 @@ export const listing = createCommand({
|
|||||||
await interaction.editReply({ content: `✅ Listing for **${item.name}** posted in ${targetChannel}.` });
|
await interaction.editReply({ content: `✅ Listing for **${item.name}** posted in ${targetChannel}.` });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error instanceof UserError) {
|
if (error instanceof UserError) {
|
||||||
await interaction.reply({ embeds: [createErrorEmbed(error.message)], ephemeral: true });
|
await interaction.editReply({ embeds: [createErrorEmbed(error.message)] });
|
||||||
} else {
|
} else {
|
||||||
console.error("Error creating listing:", error);
|
console.error("Error creating listing:", error);
|
||||||
await interaction.reply({ embeds: [createErrorEmbed("An unexpected error occurred.")], ephemeral: true });
|
await interaction.editReply({ embeds: [createErrorEmbed("An unexpected error occurred.")] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { CaseType } from "@/lib/constants";
|
import { CaseType } from "@shared/lib/constants";
|
||||||
import { getNoteSuccessEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getNoteSuccessEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const note = createCommand({
|
export const note = createCommand({
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { getCasesListEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getCasesListEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const notes = createCommand({
|
export const notes = createCommand({
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags, ComponentType } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags, ComponentType } from "discord.js";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { PruneService } from "@/modules/moderation/prune.service";
|
import { PruneService } from "@shared/modules/moderation/prune.service";
|
||||||
import {
|
import {
|
||||||
getConfirmationMessage,
|
getConfirmationMessage,
|
||||||
getProgressEmbed,
|
getProgressEmbed,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createCommand } from "@lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, TextChannel } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, TextChannel } from "discord.js";
|
||||||
import { terminalService } from "@/modules/terminal/terminal.service";
|
import { terminalService } from "@shared/modules/terminal/terminal.service";
|
||||||
import { createBaseEmbed, createErrorEmbed } from "@/lib/embeds";
|
import { createBaseEmbed, createErrorEmbed } from "@/lib/embeds";
|
||||||
|
|
||||||
export const terminal = createCommand({
|
export const terminal = createCommand({
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import {
|
import {
|
||||||
getWarnSuccessEmbed,
|
getWarnSuccessEmbed,
|
||||||
getModerationErrorEmbed,
|
getModerationErrorEmbed,
|
||||||
getUserWarningEmbed
|
getUserWarningEmbed
|
||||||
} from "@/modules/moderation/moderation.view";
|
} from "@/modules/moderation/moderation.view";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
|
|
||||||
export const warn = createCommand({
|
export const warn = createCommand({
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { ModerationService } from "@/modules/moderation/moderation.service";
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
||||||
import { getWarningsEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
import { getWarningsEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
||||||
|
|
||||||
export const warnings = createCommand({
|
export const warnings = createCommand({
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
||||||
import { createErrorEmbed } from "@/lib/embeds";
|
import { createErrorEmbed } from "@/lib/embeds";
|
||||||
import { sendWebhookMessage } from "@/lib/webhookUtils";
|
import { sendWebhookMessage } from "@/lib/webhookUtils";
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { createBaseEmbed } from "@lib/embeds";
|
import { createBaseEmbed } from "@lib/embeds";
|
||||||
|
|
||||||
export const balance = createCommand({
|
export const balance = createCommand({
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
|
|
||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { economyService } from "@/modules/economy/economy.service";
|
import { economyService } from "@shared/modules/economy/economy.service";
|
||||||
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
|
||||||
export const daily = createCommand({
|
export const daily = createCommand({
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("daily")
|
.setName("daily")
|
||||||
.setDescription("Claim your daily reward"),
|
.setDescription("Claim your daily reward"),
|
||||||
execute: async (interaction) => {
|
execute: async (interaction) => {
|
||||||
|
await interaction.deferReply();
|
||||||
try {
|
try {
|
||||||
const result = await economyService.claimDaily(interaction.user.id);
|
const result = await economyService.claimDaily(interaction.user.id);
|
||||||
|
|
||||||
@@ -21,14 +22,14 @@ export const daily = createCommand({
|
|||||||
)
|
)
|
||||||
.setColor("Gold");
|
.setColor("Gold");
|
||||||
|
|
||||||
await interaction.reply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error instanceof UserError) {
|
if (error instanceof UserError) {
|
||||||
await interaction.reply({ embeds: [createErrorEmbed(error.message)], ephemeral: true });
|
await interaction.editReply({ embeds: [createErrorEmbed(error.message)] });
|
||||||
} else {
|
} else {
|
||||||
console.error("Error claiming daily:", error);
|
console.error("Error claiming daily:", error);
|
||||||
await interaction.reply({ embeds: [createErrorEmbed("An unexpected error occurred.")], ephemeral: true });
|
await interaction.editReply({ embeds: [createErrorEmbed("An unexpected error occurred.")] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
75
bot/commands/economy/exam.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { createCommand } from "@shared/lib/utils";
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
||||||
|
import { examService, ExamStatus } from "@shared/modules/economy/exam.service";
|
||||||
|
|
||||||
|
const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
||||||
|
|
||||||
|
export const exam = createCommand({
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("exam")
|
||||||
|
.setDescription("Take your weekly exam to earn rewards based on your XP progress."),
|
||||||
|
execute: async (interaction) => {
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// First, try to take the exam or check status
|
||||||
|
const result = await examService.takeExam(interaction.user.id);
|
||||||
|
|
||||||
|
if (result.status === ExamStatus.NOT_REGISTERED) {
|
||||||
|
// Register the user
|
||||||
|
const regResult = await examService.registerForExam(interaction.user.id, interaction.user.username);
|
||||||
|
const nextRegTimestamp = Math.floor(regResult.nextExamAt!.getTime() / 1000);
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createSuccessEmbed(
|
||||||
|
`You have registered for the exam! Your exam day is **${DAYS[regResult.examDay!]}** (Server Time).\n` +
|
||||||
|
`Come back on <t:${nextRegTimestamp}:D> (<t:${nextRegTimestamp}:R>) to take your first exam!`,
|
||||||
|
"Exam Registration Successful"
|
||||||
|
)]
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextExamTimestamp = Math.floor(result.nextExamAt!.getTime() / 1000);
|
||||||
|
|
||||||
|
if (result.status === ExamStatus.COOLDOWN) {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createErrorEmbed(
|
||||||
|
`You have already taken your exam for this week (or are waiting for your first week to pass).\n` +
|
||||||
|
`Next exam available: <t:${nextExamTimestamp}:D> (<t:${nextExamTimestamp}:R>)`
|
||||||
|
)]
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === ExamStatus.MISSED) {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createErrorEmbed(
|
||||||
|
`You missed your exam day! Your exam day is **${DAYS[result.examDay!]}** (Server Time).\n` +
|
||||||
|
`You verify your attendance but score a **0**.\n` +
|
||||||
|
`Your next exam opportunity is: <t:${nextExamTimestamp}:D> (<t:${nextExamTimestamp}:R>)`,
|
||||||
|
"Exam Failed"
|
||||||
|
)]
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it reached here with AVAILABLE, it means they passed
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createSuccessEmbed(
|
||||||
|
`**XP Gained:** ${result.xpDiff?.toString()}\n` +
|
||||||
|
`**Multiplier:** x${result.multiplier?.toFixed(2)}\n` +
|
||||||
|
`**Reward:** ${result.reward?.toString()} Currency\n\n` +
|
||||||
|
`See you next week: <t:${nextExamTimestamp}:D>`,
|
||||||
|
"Exam Passed!"
|
||||||
|
)]
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error in exam command:", error);
|
||||||
|
await interaction.editReply({ embeds: [createErrorEmbed(error.message || "An unexpected error occurred.")] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, MessageFlags } from "discord.js";
|
||||||
import { economyService } from "@/modules/economy/economy.service";
|
import { economyService } from "@shared/modules/economy/economy.service";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
|
||||||
export const pay = createCommand({
|
export const pay = createCommand({
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, ChannelType, ThreadAutoArchiveDuration, MessageFlags } from "discord.js";
|
import { SlashCommandBuilder, ChannelType, ThreadAutoArchiveDuration, MessageFlags } from "discord.js";
|
||||||
import { tradeService } from "@/modules/trade/trade.service";
|
import { tradeService } from "@shared/modules/trade/trade.service";
|
||||||
import { getTradeDashboard } from "@/modules/trade/trade.view";
|
import { getTradeDashboard } from "@/modules/trade/trade.view";
|
||||||
import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
|
import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
|
||||||
|
|
||||||
117
bot/commands/economy/trivia.ts
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
import { createCommand } from "@shared/lib/utils";
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { triviaService } from "@shared/modules/trivia/trivia.service";
|
||||||
|
import { getTriviaQuestionView } from "@/modules/trivia/trivia.view";
|
||||||
|
import { createErrorEmbed } from "@lib/embeds";
|
||||||
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
import { config } from "@shared/lib/config";
|
||||||
|
import { TriviaCategory } from "@shared/lib/constants";
|
||||||
|
|
||||||
|
export const trivia = createCommand({
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("trivia")
|
||||||
|
.setDescription("Play trivia to win currency! Answer correctly within the time limit.")
|
||||||
|
.addStringOption(option =>
|
||||||
|
option.setName('category')
|
||||||
|
.setDescription('Select a specific category')
|
||||||
|
.setRequired(false)
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'General Knowledge', value: String(TriviaCategory.GENERAL_KNOWLEDGE) },
|
||||||
|
{ name: 'Books', value: String(TriviaCategory.BOOKS) },
|
||||||
|
{ name: 'Film', value: String(TriviaCategory.FILM) },
|
||||||
|
{ name: 'Music', value: String(TriviaCategory.MUSIC) },
|
||||||
|
{ name: 'Video Games', value: String(TriviaCategory.VIDEO_GAMES) },
|
||||||
|
{ name: 'Science & Nature', value: String(TriviaCategory.SCIENCE_NATURE) },
|
||||||
|
{ name: 'Computers', value: String(TriviaCategory.COMPUTERS) },
|
||||||
|
{ name: 'Mathematics', value: String(TriviaCategory.MATHEMATICS) },
|
||||||
|
{ name: 'Mythology', value: String(TriviaCategory.MYTHOLOGY) },
|
||||||
|
{ name: 'Sports', value: String(TriviaCategory.SPORTS) },
|
||||||
|
{ name: 'Geography', value: String(TriviaCategory.GEOGRAPHY) },
|
||||||
|
{ name: 'History', value: String(TriviaCategory.HISTORY) },
|
||||||
|
{ name: 'Politics', value: String(TriviaCategory.POLITICS) },
|
||||||
|
{ name: 'Art', value: String(TriviaCategory.ART) },
|
||||||
|
{ name: 'Animals', value: String(TriviaCategory.ANIMALS) },
|
||||||
|
{ name: 'Anime & Manga', value: String(TriviaCategory.ANIME_MANGA) },
|
||||||
|
)
|
||||||
|
),
|
||||||
|
execute: async (interaction) => {
|
||||||
|
try {
|
||||||
|
const categoryId = interaction.options.getString('category');
|
||||||
|
|
||||||
|
// Check if user can play BEFORE deferring
|
||||||
|
const canPlay = await triviaService.canPlayTrivia(interaction.user.id);
|
||||||
|
|
||||||
|
if (!canPlay.canPlay) {
|
||||||
|
// Cooldown error - ephemeral
|
||||||
|
const timestamp = Math.floor(canPlay.nextAvailable!.getTime() / 1000);
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [createErrorEmbed(
|
||||||
|
`You're on cooldown! Try again <t:${timestamp}:R>.`
|
||||||
|
)],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// User can play - defer publicly for trivia question
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
// Start trivia session (deducts entry fee)
|
||||||
|
const session = await triviaService.startTrivia(
|
||||||
|
interaction.user.id,
|
||||||
|
interaction.user.username,
|
||||||
|
categoryId ? parseInt(categoryId) : undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
// Generate Components v2 message
|
||||||
|
const { components, flags } = getTriviaQuestionView(session, interaction.user.username);
|
||||||
|
|
||||||
|
// Reply with Components v2 question
|
||||||
|
await interaction.editReply({
|
||||||
|
components,
|
||||||
|
flags
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set up automatic timeout cleanup
|
||||||
|
setTimeout(async () => {
|
||||||
|
const stillActive = triviaService.getSession(session.sessionId);
|
||||||
|
if (stillActive) {
|
||||||
|
// User didn't answer - clean up session with no reward
|
||||||
|
try {
|
||||||
|
await triviaService.submitAnswer(session.sessionId, interaction.user.id, false);
|
||||||
|
} catch (error) {
|
||||||
|
// Session already cleaned up, ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, config.trivia.timeoutSeconds * 1000 + 5000); // 5 seconds grace period
|
||||||
|
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof UserError) {
|
||||||
|
// Check if we've already deferred
|
||||||
|
if (interaction.deferred) {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createErrorEmbed(error.message)]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [createErrorEmbed(error.message)],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error("Error in trivia command:", error);
|
||||||
|
// Check if we've already deferred
|
||||||
|
if (interaction.deferred) {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [createErrorEmbed("An unexpected error occurred. Please try again later.")]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [createErrorEmbed("An unexpected error occurred. Please try again later.")],
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { createErrorEmbed } from "@/lib/embeds";
|
import { createErrorEmbed } from "@/lib/embeds";
|
||||||
import { getFeedbackTypeMenu } from "@/modules/feedback/feedback.view";
|
import { getFeedbackTypeMenu } from "@/modules/feedback/feedback.view";
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { createWarningEmbed } from "@lib/embeds";
|
import { createWarningEmbed } from "@lib/embeds";
|
||||||
import { getInventoryEmbed } from "@/modules/inventory/inventory.view";
|
import { getInventoryEmbed } from "@/modules/inventory/inventory.view";
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { createErrorEmbed } from "@lib/embeds";
|
import { createErrorEmbed } from "@lib/embeds";
|
||||||
import { getItemUseResultEmbed } from "@/modules/inventory/inventory.view";
|
import { getItemUseResultEmbed } from "@/modules/inventory/inventory.view";
|
||||||
import type { ItemUsageData } from "@/lib/types";
|
import type { ItemUsageData } from "@shared/lib/types";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
|
|
||||||
export const use = createCommand({
|
export const use = createCommand({
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import { users, items, inventory } from "@/db/schema";
|
import { users, items, inventory } from "@db/schema";
|
||||||
import { desc, sql, eq } from "drizzle-orm";
|
import { desc, sql, eq } from "drizzle-orm";
|
||||||
import { createWarningEmbed } from "@lib/embeds";
|
import { createWarningEmbed } from "@lib/embeds";
|
||||||
import { getLeaderboardEmbed } from "@/modules/leveling/leveling.view";
|
import { getLeaderboardEmbed } from "@/modules/leveling/leveling.view";
|
||||||
83
bot/commands/quest/quests.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { createCommand } from "@shared/lib/utils";
|
||||||
|
import { SlashCommandBuilder, MessageFlags } from "discord.js";
|
||||||
|
import { questService } from "@shared/modules/quest/quest.service";
|
||||||
|
import { createSuccessEmbed } from "@lib/embeds";
|
||||||
|
import {
|
||||||
|
getQuestListComponents,
|
||||||
|
getAvailableQuestsComponents,
|
||||||
|
getQuestActionRows
|
||||||
|
} from "@/modules/quest/quest.view";
|
||||||
|
|
||||||
|
export const quests = createCommand({
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("quests")
|
||||||
|
.setDescription("View your active and available quests"),
|
||||||
|
execute: async (interaction) => {
|
||||||
|
const response = await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
const userId = interaction.user.id;
|
||||||
|
|
||||||
|
const updateView = async (viewType: 'active' | 'available') => {
|
||||||
|
const userQuests = await questService.getUserQuests(userId);
|
||||||
|
const availableQuests = await questService.getAvailableQuests(userId);
|
||||||
|
|
||||||
|
const containers = viewType === 'active'
|
||||||
|
? getQuestListComponents(userQuests)
|
||||||
|
: getAvailableQuestsComponents(availableQuests);
|
||||||
|
|
||||||
|
const actionRows = getQuestActionRows(viewType);
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
content: null,
|
||||||
|
embeds: null as any,
|
||||||
|
components: [...containers, ...actionRows] as any,
|
||||||
|
flags: MessageFlags.IsComponentsV2,
|
||||||
|
allowedMentions: { parse: [] }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial view
|
||||||
|
await updateView('active');
|
||||||
|
|
||||||
|
const collector = response.createMessageComponentCollector({
|
||||||
|
time: 120000, // 2 minutes
|
||||||
|
componentType: undefined // Allow buttons
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('collect', async (i) => {
|
||||||
|
if (i.user.id !== interaction.user.id) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (i.customId === "quest_view_active") {
|
||||||
|
await i.deferUpdate();
|
||||||
|
await updateView('active');
|
||||||
|
} else if (i.customId === "quest_view_available") {
|
||||||
|
await i.deferUpdate();
|
||||||
|
await updateView('available');
|
||||||
|
} else if (i.customId.startsWith("quest_accept:")) {
|
||||||
|
const questIdStr = i.customId.split(":")[1];
|
||||||
|
if (!questIdStr) return;
|
||||||
|
const questId = parseInt(questIdStr);
|
||||||
|
await questService.assignQuest(userId, questId);
|
||||||
|
|
||||||
|
await i.reply({
|
||||||
|
embeds: [createSuccessEmbed(`You have accepted a new quest!`, "Quest Accepted")],
|
||||||
|
flags: MessageFlags.Ephemeral
|
||||||
|
});
|
||||||
|
|
||||||
|
await updateView('active');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Quest interaction error:", error);
|
||||||
|
await i.followUp({
|
||||||
|
content: "Something went wrong while processing your quest interaction.",
|
||||||
|
flags: MessageFlags.Ephemeral
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('end', () => {
|
||||||
|
interaction.editReply({ components: [] }).catch(() => {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createCommand } from "@/lib/utils";
|
import { createCommand } from "@shared/lib/utils";
|
||||||
import { SlashCommandBuilder, AttachmentBuilder } from "discord.js";
|
import { SlashCommandBuilder, AttachmentBuilder } from "discord.js";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { generateStudentIdCard } from "@/graphics/studentID";
|
import { generateStudentIdCard } from "@/graphics/studentID";
|
||||||
import { createWarningEmbed } from "@/lib/embeds";
|
import { createWarningEmbed } from "@/lib/embeds";
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Events } from "discord.js";
|
import { Events } from "discord.js";
|
||||||
import type { Event } from "@lib/types";
|
import type { Event } from "@shared/lib/types";
|
||||||
import { config } from "@lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { userService } from "@modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
|
|
||||||
// Visitor role
|
// Visitor role
|
||||||
const event: Event<Events.GuildMemberAdd> = {
|
const event: Event<Events.GuildMemberAdd> = {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Events } from "discord.js";
|
import { Events } from "discord.js";
|
||||||
import { ComponentInteractionHandler, AutocompleteHandler, CommandHandler } from "@/lib/handlers";
|
import { ComponentInteractionHandler, AutocompleteHandler, CommandHandler } from "@/lib/handlers";
|
||||||
import type { Event } from "@lib/types";
|
import type { Event } from "@shared/lib/types";
|
||||||
|
|
||||||
const event: Event<Events.InteractionCreate> = {
|
const event: Event<Events.InteractionCreate> = {
|
||||||
name: Events.InteractionCreate,
|
name: Events.InteractionCreate,
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Events } from "discord.js";
|
import { Events } from "discord.js";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { levelingService } from "@/modules/leveling/leveling.service";
|
import { levelingService } from "@shared/modules/leveling/leveling.service";
|
||||||
import type { Event } from "@lib/types";
|
import type { Event } from "@shared/lib/types";
|
||||||
|
|
||||||
const event: Event<Events.MessageCreate> = {
|
const event: Event<Events.MessageCreate> = {
|
||||||
name: Events.MessageCreate,
|
name: Events.MessageCreate,
|
||||||
@@ -15,7 +15,7 @@ const event: Event<Events.MessageCreate> = {
|
|||||||
levelingService.processChatXp(message.author.id);
|
levelingService.processChatXp(message.author.id);
|
||||||
|
|
||||||
// Activity Tracking for Lootdrops
|
// Activity Tracking for Lootdrops
|
||||||
import("@/modules/economy/lootdrop.service").then(m => m.lootdropService.processMessage(message));
|
import("@shared/modules/economy/lootdrop.service").then(m => m.lootdropService.processMessage(message));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Events } from "discord.js";
|
import { Events } from "discord.js";
|
||||||
import { schedulerService } from "@/modules/system/scheduler";
|
import { schedulerService } from "@/modules/system/scheduler";
|
||||||
import type { Event } from "@lib/types";
|
import type { Event } from "@shared/lib/types";
|
||||||
|
|
||||||
const event: Event<Events.ClientReady> = {
|
const event: Event<Events.ClientReady> = {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
@@ -9,9 +9,7 @@ const event: Event<Events.ClientReady> = {
|
|||||||
console.log(`Ready! Logged in as ${c.user.tag}`);
|
console.log(`Ready! Logged in as ${c.user.tag}`);
|
||||||
schedulerService.start();
|
schedulerService.start();
|
||||||
|
|
||||||
// Handle post-update tasks
|
|
||||||
const { UpdateService } = await import("@/modules/admin/update.service");
|
|
||||||
await UpdateService.handlePostRestart(c);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2,12 +2,12 @@ import { GlobalFonts, createCanvas, loadImage } from '@napi-rs/canvas';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
// Register Fonts (same as studentID.ts)
|
// Register Fonts (same as studentID.ts)
|
||||||
const fontDir = path.join(process.cwd(), 'src', 'assets', 'fonts');
|
const fontDir = path.join(process.cwd(), 'bot', 'assets', 'fonts');
|
||||||
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexSansCondensed-SemiBold.ttf'), 'IBMPlexSansCondensed-SemiBold');
|
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexSansCondensed-SemiBold.ttf'), 'IBMPlexSansCondensed-SemiBold');
|
||||||
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexMono-Bold.ttf'), 'IBMPlexMono-Bold');
|
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexMono-Bold.ttf'), 'IBMPlexMono-Bold');
|
||||||
|
|
||||||
export async function generateLootdropCard(amount: number, currency: string): Promise<Buffer> {
|
export async function generateLootdropCard(amount: number, currency: string): Promise<Buffer> {
|
||||||
const templatePath = path.join(process.cwd(), 'src', 'assets', 'graphics', 'lootdrop', 'template.png');
|
const templatePath = path.join(process.cwd(), 'bot', 'assets', 'graphics', 'lootdrop', 'template.png');
|
||||||
const template = await loadImage(templatePath);
|
const template = await loadImage(templatePath);
|
||||||
|
|
||||||
const canvas = createCanvas(template.width, template.height);
|
const canvas = createCanvas(template.width, template.height);
|
||||||
@@ -50,7 +50,7 @@ export async function generateLootdropCard(amount: number, currency: string): Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function generateClaimedLootdropCard(amount: number, currency: string, username: string, avatarUrl: string): Promise<Buffer> {
|
export async function generateClaimedLootdropCard(amount: number, currency: string, username: string, avatarUrl: string): Promise<Buffer> {
|
||||||
const templatePath = path.join(process.cwd(), 'src', 'assets', 'graphics', 'lootdrop', 'template.png');
|
const templatePath = path.join(process.cwd(), 'bot', 'assets', 'graphics', 'lootdrop', 'template.png');
|
||||||
const template = await loadImage(templatePath);
|
const template = await loadImage(templatePath);
|
||||||
|
|
||||||
const canvas = createCanvas(template.width, template.height);
|
const canvas = createCanvas(template.width, template.height);
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { GlobalFonts, createCanvas, loadImage } from '@napi-rs/canvas';
|
import { GlobalFonts, createCanvas, loadImage } from '@napi-rs/canvas';
|
||||||
import { levelingService } from '@/modules/leveling/leveling.service';
|
import { levelingService } from '@shared/modules/leveling/leveling.service';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
// Register Fonts
|
// Register Fonts
|
||||||
const fontDir = path.join(process.cwd(), 'src', 'assets', 'fonts');
|
const fontDir = path.join(process.cwd(), 'bot', 'assets', 'fonts');
|
||||||
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexSansCondensed-SemiBold.ttf'), 'IBMPlexSansCondensed-SemiBold');
|
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexSansCondensed-SemiBold.ttf'), 'IBMPlexSansCondensed-SemiBold');
|
||||||
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexMono-Bold.ttf'), 'IBMPlexMono-Bold');
|
GlobalFonts.registerFromPath(path.join(fontDir, 'IBMPlexMono-Bold.ttf'), 'IBMPlexMono-Bold');
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ interface StudentCardData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function generateStudentIdCard(data: StudentCardData): Promise<Buffer> {
|
export async function generateStudentIdCard(data: StudentCardData): Promise<Buffer> {
|
||||||
const templatePath = path.join(process.cwd(), 'src', 'assets', 'graphics', 'studentID', 'template.png');
|
const templatePath = path.join(process.cwd(), 'bot', 'assets', 'graphics', 'studentID', 'template.png');
|
||||||
const classTemplatePath = path.join(process.cwd(), 'src', 'assets', 'graphics', 'studentID', `Constellation-${data.className}.png`);
|
const classTemplatePath = path.join(process.cwd(), 'bot', 'assets', 'graphics', 'studentID', `Constellation-${data.className}.png`);
|
||||||
|
|
||||||
const template = await loadImage(templatePath);
|
const template = await loadImage(templatePath);
|
||||||
const classTemplate = await loadImage(classTemplatePath);
|
const classTemplate = await loadImage(classTemplatePath);
|
||||||
49
bot/index.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
|
import { env } from "@shared/lib/env";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
|
import { startWebServerFromRoot } from "../web/src/server";
|
||||||
|
|
||||||
|
// Load commands & events
|
||||||
|
await AuroraClient.loadCommands();
|
||||||
|
await AuroraClient.loadEvents();
|
||||||
|
await AuroraClient.deployCommands();
|
||||||
|
await AuroraClient.setupSystemEvents();
|
||||||
|
|
||||||
|
console.log("🌐 Starting web server...");
|
||||||
|
|
||||||
|
let shuttingDown = false;
|
||||||
|
|
||||||
|
const webProjectPath = join(import.meta.dir, "../web");
|
||||||
|
const webPort = Number(process.env.WEB_PORT) || 3000;
|
||||||
|
const webHost = process.env.HOST || "0.0.0.0";
|
||||||
|
|
||||||
|
// Start web server in the same process
|
||||||
|
const webServer = await startWebServerFromRoot(webProjectPath, {
|
||||||
|
port: webPort,
|
||||||
|
hostname: webHost,
|
||||||
|
});
|
||||||
|
|
||||||
|
// login with the token from .env
|
||||||
|
if (!env.DISCORD_BOT_TOKEN) {
|
||||||
|
throw new Error("❌ DISCORD_BOT_TOKEN is not set in environment variables.");
|
||||||
|
}
|
||||||
|
AuroraClient.login(env.DISCORD_BOT_TOKEN);
|
||||||
|
|
||||||
|
// Handle graceful shutdown
|
||||||
|
const shutdownHandler = async () => {
|
||||||
|
if (shuttingDown) return;
|
||||||
|
shuttingDown = true;
|
||||||
|
console.log("🛑 Shutdown signal received. Stopping services...");
|
||||||
|
|
||||||
|
// Stop web server
|
||||||
|
await webServer.stop();
|
||||||
|
|
||||||
|
// Stop bot
|
||||||
|
AuroraClient.shutdown();
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on("SIGINT", shutdownHandler);
|
||||||
|
process.on("SIGTERM", shutdownHandler);
|
||||||
111
bot/lib/BotClient.test.ts
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { describe, expect, test, mock, beforeEach, spyOn } from "bun:test";
|
||||||
|
import { systemEvents, EVENTS } from "@shared/lib/events";
|
||||||
|
|
||||||
|
// Mock Discord.js Client and related classes
|
||||||
|
mock.module("discord.js", () => ({
|
||||||
|
Client: class {
|
||||||
|
constructor() { }
|
||||||
|
on() { }
|
||||||
|
once() { }
|
||||||
|
login() { }
|
||||||
|
destroy() { }
|
||||||
|
removeAllListeners() { }
|
||||||
|
},
|
||||||
|
Collection: Map,
|
||||||
|
GatewayIntentBits: { Guilds: 1, MessageContent: 1, GuildMessages: 1, GuildMembers: 1 },
|
||||||
|
REST: class {
|
||||||
|
setToken() { return this; }
|
||||||
|
put() { return Promise.resolve([]); }
|
||||||
|
},
|
||||||
|
Routes: {
|
||||||
|
applicationGuildCommands: () => 'guild_route',
|
||||||
|
applicationCommands: () => 'global_route'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock loaders to avoid filesystem access during client init
|
||||||
|
mock.module("../lib/loaders/CommandLoader", () => ({
|
||||||
|
CommandLoader: class {
|
||||||
|
constructor() { }
|
||||||
|
loadFromDirectory() { return Promise.resolve({ loaded: 0, skipped: 0, errors: [] }); }
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
mock.module("../lib/loaders/EventLoader", () => ({
|
||||||
|
EventLoader: class {
|
||||||
|
constructor() { }
|
||||||
|
loadFromDirectory() { return Promise.resolve({ loaded: 0, skipped: 0, errors: [] }); }
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock dashboard service to prevent network/db calls during event handling
|
||||||
|
mock.module("@shared/modules/economy/lootdrop.service", () => ({
|
||||||
|
lootdropService: { clearCaches: mock(async () => { }) }
|
||||||
|
}));
|
||||||
|
mock.module("@shared/modules/trade/trade.service", () => ({
|
||||||
|
tradeService: { clearSessions: mock(() => { }) }
|
||||||
|
}));
|
||||||
|
mock.module("@/modules/admin/item_wizard", () => ({
|
||||||
|
clearDraftSessions: mock(() => { })
|
||||||
|
}));
|
||||||
|
mock.module("@shared/modules/dashboard/dashboard.service", () => ({
|
||||||
|
dashboardService: {
|
||||||
|
recordEvent: mock(() => Promise.resolve())
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("AuroraClient System Events", () => {
|
||||||
|
let AuroraClient: any;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
systemEvents.removeAllListeners();
|
||||||
|
const module = await import("./BotClient");
|
||||||
|
AuroraClient = module.AuroraClient;
|
||||||
|
AuroraClient.maintenanceMode = false;
|
||||||
|
// MUST call explicitly now
|
||||||
|
await AuroraClient.setupSystemEvents();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Case: Maintenance Mode Toggle
|
||||||
|
* Requirement: Client state should update when event is received
|
||||||
|
*/
|
||||||
|
test("should toggle maintenanceMode when MAINTENANCE_MODE event is received", async () => {
|
||||||
|
systemEvents.emit(EVENTS.ACTIONS.MAINTENANCE_MODE, { enabled: true, reason: "Testing" });
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 30));
|
||||||
|
expect(AuroraClient.maintenanceMode).toBe(true);
|
||||||
|
|
||||||
|
systemEvents.emit(EVENTS.ACTIONS.MAINTENANCE_MODE, { enabled: false });
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 30));
|
||||||
|
expect(AuroraClient.maintenanceMode).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Case: Command Reload
|
||||||
|
* Requirement: loadCommands and deployCommands should be called
|
||||||
|
*/
|
||||||
|
test("should reload commands when RELOAD_COMMANDS event is received", async () => {
|
||||||
|
const loadSpy = spyOn(AuroraClient, "loadCommands").mockImplementation(() => Promise.resolve());
|
||||||
|
const deploySpy = spyOn(AuroraClient, "deployCommands").mockImplementation(() => Promise.resolve());
|
||||||
|
|
||||||
|
systemEvents.emit(EVENTS.ACTIONS.RELOAD_COMMANDS);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
|
||||||
|
expect(loadSpy).toHaveBeenCalled();
|
||||||
|
expect(deploySpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Case: Cache Clearance
|
||||||
|
* Requirement: Service clear methods should be triggered
|
||||||
|
*/
|
||||||
|
test("should trigger service cache clearance when CLEAR_CACHE is received", async () => {
|
||||||
|
const { lootdropService } = await import("@shared/modules/economy/lootdrop.service");
|
||||||
|
const { tradeService } = await import("@shared/modules/trade/trade.service");
|
||||||
|
|
||||||
|
systemEvents.emit(EVENTS.ACTIONS.CLEAR_CACHE);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
|
||||||
|
expect(lootdropService.clearCaches).toHaveBeenCalled();
|
||||||
|
expect(tradeService.clearSessions).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
200
bot/lib/BotClient.ts
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import { Client as DiscordClient, Collection, GatewayIntentBits, REST, Routes, MessageFlags } from "discord.js";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import type { Command } from "@shared/lib/types";
|
||||||
|
import { env } from "@shared/lib/env";
|
||||||
|
import { CommandLoader } from "@lib/loaders/CommandLoader";
|
||||||
|
import { EventLoader } from "@lib/loaders/EventLoader";
|
||||||
|
|
||||||
|
export class Client extends DiscordClient {
|
||||||
|
|
||||||
|
commands: Collection<string, Command>;
|
||||||
|
knownCommands: Map<string, string>;
|
||||||
|
lastCommandTimestamp: number | null = null;
|
||||||
|
maintenanceMode: boolean = false;
|
||||||
|
private commandLoader: CommandLoader;
|
||||||
|
private eventLoader: EventLoader;
|
||||||
|
|
||||||
|
constructor({ intents }: { intents: number[] }) {
|
||||||
|
super({ intents });
|
||||||
|
this.commands = new Collection<string, Command>();
|
||||||
|
this.knownCommands = new Map<string, string>();
|
||||||
|
this.commandLoader = new CommandLoader(this);
|
||||||
|
this.eventLoader = new EventLoader(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setupSystemEvents() {
|
||||||
|
const { systemEvents, EVENTS } = await import("@shared/lib/events");
|
||||||
|
|
||||||
|
systemEvents.on(EVENTS.ACTIONS.RELOAD_COMMANDS, async () => {
|
||||||
|
console.log("🔄 System Action: Reloading commands...");
|
||||||
|
try {
|
||||||
|
await this.loadCommands(true);
|
||||||
|
await this.deployCommands();
|
||||||
|
|
||||||
|
const { dashboardService } = await import("@shared/modules/dashboard/dashboard.service");
|
||||||
|
await dashboardService.recordEvent({
|
||||||
|
type: "success",
|
||||||
|
message: "Bot: Commands reloaded and redeployed",
|
||||||
|
icon: "✅"
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to reload commands:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
systemEvents.on(EVENTS.ACTIONS.CLEAR_CACHE, async () => {
|
||||||
|
console.log("<22> System Action: Clearing all internal caches...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. Lootdrop Service
|
||||||
|
const { lootdropService } = await import("@shared/modules/economy/lootdrop.service");
|
||||||
|
await lootdropService.clearCaches();
|
||||||
|
|
||||||
|
// 2. Trade Service
|
||||||
|
const { tradeService } = await import("@shared/modules/trade/trade.service");
|
||||||
|
tradeService.clearSessions();
|
||||||
|
|
||||||
|
// 3. Item Wizard
|
||||||
|
const { clearDraftSessions } = await import("@/modules/admin/item_wizard");
|
||||||
|
clearDraftSessions();
|
||||||
|
|
||||||
|
const { dashboardService } = await import("@shared/modules/dashboard/dashboard.service");
|
||||||
|
await dashboardService.recordEvent({
|
||||||
|
type: "success",
|
||||||
|
message: "Bot: All internal caches and sessions cleared",
|
||||||
|
icon: "🧼"
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to clear caches:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
systemEvents.on(EVENTS.ACTIONS.MAINTENANCE_MODE, async (data: { enabled: boolean, reason?: string }) => {
|
||||||
|
const { enabled, reason } = data;
|
||||||
|
console.log(`🛠️ System Action: Maintenance mode ${enabled ? "ON" : "OFF"}${reason ? ` (${reason})` : ""}`);
|
||||||
|
this.maintenanceMode = enabled;
|
||||||
|
});
|
||||||
|
|
||||||
|
systemEvents.on(EVENTS.QUEST.COMPLETED, async (data: { userId: string, quest: any, rewards: any }) => {
|
||||||
|
const { userId, quest, rewards } = data;
|
||||||
|
try {
|
||||||
|
const user = await this.users.fetch(userId);
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
const { getQuestCompletionComponents } = await import("@/modules/quest/quest.view");
|
||||||
|
const components = getQuestCompletionComponents(quest, rewards);
|
||||||
|
|
||||||
|
// Try to send to the user's DM
|
||||||
|
await user.send({
|
||||||
|
components: components as any,
|
||||||
|
flags: [MessageFlags.IsComponentsV2]
|
||||||
|
}).catch(async () => {
|
||||||
|
console.warn(`Could not DM user ${userId} quest completion message. User might have DMs disabled.`);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send quest completion notification:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadCommands(reload: boolean = false) {
|
||||||
|
if (reload) {
|
||||||
|
this.commands.clear();
|
||||||
|
this.knownCommands.clear();
|
||||||
|
console.log("♻️ Reloading commands...");
|
||||||
|
}
|
||||||
|
|
||||||
|
const commandsPath = join(import.meta.dir, '../commands');
|
||||||
|
const result = await this.commandLoader.loadFromDirectory(commandsPath, reload);
|
||||||
|
|
||||||
|
console.log(`📦 Command loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadEvents(reload: boolean = false) {
|
||||||
|
if (reload) {
|
||||||
|
this.removeAllListeners();
|
||||||
|
console.log("♻️ Reloading events...");
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsPath = join(import.meta.dir, '../events');
|
||||||
|
const result = await this.eventLoader.loadFromDirectory(eventsPath, reload);
|
||||||
|
|
||||||
|
console.log(`📦 Event loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async deployCommands() {
|
||||||
|
// We use env.DISCORD_BOT_TOKEN directly so this can run without client.login()
|
||||||
|
const token = env.DISCORD_BOT_TOKEN;
|
||||||
|
if (!token) {
|
||||||
|
console.error("DISCORD_BOT_TOKEN is not set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rest = new REST().setToken(token);
|
||||||
|
const commandsData = this.commands.map(c => c.data.toJSON());
|
||||||
|
const guildId = env.DISCORD_GUILD_ID;
|
||||||
|
const clientId = env.DISCORD_CLIENT_ID;
|
||||||
|
|
||||||
|
if (!clientId) {
|
||||||
|
console.error("DISCORD_CLIENT_ID is not set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Started refreshing ${commandsData.length} application (/) commands.`);
|
||||||
|
|
||||||
|
let data;
|
||||||
|
if (guildId) {
|
||||||
|
console.log(`Registering commands to guild: ${guildId}`);
|
||||||
|
data = await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: commandsData },
|
||||||
|
);
|
||||||
|
// Clear global commands to avoid duplicates
|
||||||
|
await rest.put(Routes.applicationCommands(clientId), { body: [] });
|
||||||
|
} else {
|
||||||
|
console.log('Registering commands globally');
|
||||||
|
data = await rest.put(
|
||||||
|
Routes.applicationCommands(clientId),
|
||||||
|
{ body: commandsData },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Successfully reloaded ${(data as any).length} application (/) commands.`);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.code === 50001) {
|
||||||
|
console.warn("Missing Access: The bot is not in the guild or lacks 'applications.commands' scope.");
|
||||||
|
console.warn(" If you are testing locally, make sure you invited the bot with scope 'bot applications.commands'.");
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async shutdown() {
|
||||||
|
const { setShuttingDown, waitForTransactions } = await import("./shutdown");
|
||||||
|
const { closeDatabase } = await import("@shared/db/DrizzleClient");
|
||||||
|
|
||||||
|
console.log("🛑 Shutdown signal received. Starting graceful shutdown...");
|
||||||
|
setShuttingDown(true);
|
||||||
|
|
||||||
|
// Wait for transactions to complete
|
||||||
|
console.log("⏳ Waiting for active transactions to complete...");
|
||||||
|
await waitForTransactions(10000);
|
||||||
|
|
||||||
|
// Destroy Discord client
|
||||||
|
console.log("🔌 Disconnecting from Discord...");
|
||||||
|
this.destroy();
|
||||||
|
|
||||||
|
// Close database
|
||||||
|
console.log("🗄️ Closing database connection...");
|
||||||
|
await closeDatabase();
|
||||||
|
|
||||||
|
console.log("👋 Graceful shutdown complete. Exiting.");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AuroraClient = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.DirectMessages] });
|
||||||
74
bot/lib/clientStats.test.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import { describe, test, expect, beforeEach, mock, afterEach } from "bun:test";
|
||||||
|
import { getClientStats, clearStatsCache } from "./clientStats";
|
||||||
|
|
||||||
|
// Mock AuroraClient
|
||||||
|
mock.module("./BotClient", () => ({
|
||||||
|
AuroraClient: {
|
||||||
|
guilds: {
|
||||||
|
cache: {
|
||||||
|
size: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ws: {
|
||||||
|
ping: 42,
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
cache: {
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
commands: {
|
||||||
|
size: 20,
|
||||||
|
},
|
||||||
|
lastCommandTimestamp: 1641481200000,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("clientStats", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
clearStatsCache();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return client stats", () => {
|
||||||
|
const stats = getClientStats();
|
||||||
|
|
||||||
|
expect(stats.guilds).toBe(5);
|
||||||
|
expect(stats.ping).toBe(42);
|
||||||
|
expect(stats.cachedUsers).toBe(100);
|
||||||
|
expect(stats.commandsRegistered).toBe(20);
|
||||||
|
expect(typeof stats.uptime).toBe("number"); // Can't mock process.uptime easily
|
||||||
|
expect(stats.lastCommandTimestamp).toBe(1641481200000);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should cache stats for 30 seconds", () => {
|
||||||
|
const stats1 = getClientStats();
|
||||||
|
const stats2 = getClientStats();
|
||||||
|
|
||||||
|
// Should return same object (cached)
|
||||||
|
expect(stats1).toBe(stats2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should refresh cache after TTL expires", async () => {
|
||||||
|
const stats1 = getClientStats();
|
||||||
|
|
||||||
|
// Wait for cache to expire (simulate by clearing and waiting)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 35));
|
||||||
|
clearStatsCache();
|
||||||
|
|
||||||
|
const stats2 = getClientStats();
|
||||||
|
|
||||||
|
// Should be different objects (new fetch)
|
||||||
|
expect(stats1).not.toBe(stats2);
|
||||||
|
// But values should be the same (mocked client)
|
||||||
|
expect(stats1.guilds).toBe(stats2.guilds);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clearStatsCache should invalidate cache", () => {
|
||||||
|
const stats1 = getClientStats();
|
||||||
|
clearStatsCache();
|
||||||
|
const stats2 = getClientStats();
|
||||||
|
|
||||||
|
// Should be different objects
|
||||||
|
expect(stats1).not.toBe(stats2);
|
||||||
|
});
|
||||||
|
});
|
||||||
50
bot/lib/clientStats.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { AuroraClient } from "./BotClient";
|
||||||
|
import type { ClientStats } from "@shared/modules/dashboard/dashboard.types";
|
||||||
|
|
||||||
|
// Cache for client stats (30 second TTL)
|
||||||
|
let cachedStats: ClientStats | null = null;
|
||||||
|
let lastFetchTime: number = 0;
|
||||||
|
const CACHE_TTL_MS = 30 * 1000; // 30 seconds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Discord client statistics with caching
|
||||||
|
* Respects rate limits by caching for 30 seconds
|
||||||
|
*/
|
||||||
|
export function getClientStats(): ClientStats {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
// Return cached stats if still valid
|
||||||
|
if (cachedStats && (now - lastFetchTime) < CACHE_TTL_MS) {
|
||||||
|
return cachedStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch fresh stats
|
||||||
|
const stats: ClientStats = {
|
||||||
|
bot: {
|
||||||
|
name: AuroraClient.user?.username || "Aurora",
|
||||||
|
avatarUrl: AuroraClient.user?.displayAvatarURL() || null,
|
||||||
|
status: AuroraClient.user?.presence.activities[0]?.state || AuroraClient.user?.presence.activities[0]?.name || null,
|
||||||
|
},
|
||||||
|
guilds: AuroraClient.guilds.cache.size,
|
||||||
|
ping: AuroraClient.ws.ping,
|
||||||
|
cachedUsers: AuroraClient.users.cache.size,
|
||||||
|
commandsRegistered: AuroraClient.commands.size,
|
||||||
|
commandsKnown: AuroraClient.knownCommands.size,
|
||||||
|
uptime: process.uptime(),
|
||||||
|
lastCommandTimestamp: AuroraClient.lastCommandTimestamp,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
cachedStats = stats;
|
||||||
|
lastFetchTime = now;
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the stats cache (useful for testing)
|
||||||
|
*/
|
||||||
|
export function clearStatsCache(): void {
|
||||||
|
cachedStats = null;
|
||||||
|
lastFetchTime = 0;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DrizzleClient } from "./DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import type { Transaction } from "./types";
|
import type { Transaction } from "@shared/lib/types";
|
||||||
import { isShuttingDown, incrementTransactions, decrementTransactions } from "./shutdown";
|
import { isShuttingDown, incrementTransactions, decrementTransactions } from "./shutdown";
|
||||||
|
|
||||||
export const withTransaction = async <T>(
|
export const withTransaction = async <T>(
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
import { Colors, type ColorResolvable, EmbedBuilder } from "discord.js";
|
import { Colors, type ColorResolvable, EmbedBuilder } from "discord.js";
|
||||||
|
import { BRANDING } from "@shared/lib/constants";
|
||||||
|
import pkg from "../../package.json";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies standard branding to an embed.
|
||||||
|
*/
|
||||||
|
function applyBranding(embed: EmbedBuilder): EmbedBuilder {
|
||||||
|
return embed.setFooter({
|
||||||
|
text: `${BRANDING.FOOTER_TEXT} v${pkg.version}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a standardized error embed.
|
* Creates a standardized error embed.
|
||||||
@@ -7,11 +18,13 @@ import { Colors, type ColorResolvable, EmbedBuilder } from "discord.js";
|
|||||||
* @returns An EmbedBuilder instance configured as an error.
|
* @returns An EmbedBuilder instance configured as an error.
|
||||||
*/
|
*/
|
||||||
export function createErrorEmbed(message: string, title: string = "Error"): EmbedBuilder {
|
export function createErrorEmbed(message: string, title: string = "Error"): EmbedBuilder {
|
||||||
return new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`❌ ${title}`)
|
.setTitle(`❌ ${title}`)
|
||||||
.setDescription(message)
|
.setDescription(message)
|
||||||
.setColor(Colors.Red)
|
.setColor(Colors.Red)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
return applyBranding(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,11 +34,13 @@ export function createErrorEmbed(message: string, title: string = "Error"): Embe
|
|||||||
* @returns An EmbedBuilder instance configured as a warning.
|
* @returns An EmbedBuilder instance configured as a warning.
|
||||||
*/
|
*/
|
||||||
export function createWarningEmbed(message: string, title: string = "Warning"): EmbedBuilder {
|
export function createWarningEmbed(message: string, title: string = "Warning"): EmbedBuilder {
|
||||||
return new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`⚠️ ${title}`)
|
.setTitle(`⚠️ ${title}`)
|
||||||
.setDescription(message)
|
.setDescription(message)
|
||||||
.setColor(Colors.Yellow)
|
.setColor(Colors.Yellow)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
return applyBranding(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,11 +50,13 @@ export function createWarningEmbed(message: string, title: string = "Warning"):
|
|||||||
* @returns An EmbedBuilder instance configured as a success.
|
* @returns An EmbedBuilder instance configured as a success.
|
||||||
*/
|
*/
|
||||||
export function createSuccessEmbed(message: string, title: string = "Success"): EmbedBuilder {
|
export function createSuccessEmbed(message: string, title: string = "Success"): EmbedBuilder {
|
||||||
return new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`✅ ${title}`)
|
.setTitle(`✅ ${title}`)
|
||||||
.setDescription(message)
|
.setDescription(message)
|
||||||
.setColor(Colors.Green)
|
.setColor(Colors.Green)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
return applyBranding(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,11 +66,13 @@ export function createSuccessEmbed(message: string, title: string = "Success"):
|
|||||||
* @returns An EmbedBuilder instance configured as info.
|
* @returns An EmbedBuilder instance configured as info.
|
||||||
*/
|
*/
|
||||||
export function createInfoEmbed(message: string, title: string = "Info"): EmbedBuilder {
|
export function createInfoEmbed(message: string, title: string = "Info"): EmbedBuilder {
|
||||||
return new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`ℹ️ ${title}`)
|
.setTitle(`ℹ️ ${title}`)
|
||||||
.setDescription(message)
|
.setDescription(message)
|
||||||
.setColor(Colors.Blue)
|
.setColor(Colors.Blue)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
return applyBranding(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,11 +84,12 @@ export function createInfoEmbed(message: string, title: string = "Info"): EmbedB
|
|||||||
*/
|
*/
|
||||||
export function createBaseEmbed(title?: string, description?: string, color?: ColorResolvable): EmbedBuilder {
|
export function createBaseEmbed(title?: string, description?: string, color?: ColorResolvable): EmbedBuilder {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTimestamp();
|
.setTimestamp()
|
||||||
|
.setColor(color ?? BRANDING.COLOR);
|
||||||
|
|
||||||
if (title) embed.setTitle(title);
|
if (title) embed.setTitle(title);
|
||||||
if (description) embed.setDescription(description);
|
if (description) embed.setDescription(description);
|
||||||
if (color) embed.setColor(color);
|
|
||||||
|
|
||||||
return embed;
|
return applyBranding(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { AutocompleteInteraction } from "discord.js";
|
import { AutocompleteInteraction } from "discord.js";
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
import { logger } from "@lib/logger";
|
import { logger } from "@shared/lib/logger";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles autocomplete interactions for slash commands
|
* Handles autocomplete interactions for slash commands
|
||||||
@@ -16,7 +17,7 @@ export class AutocompleteHandler {
|
|||||||
try {
|
try {
|
||||||
await command.autocomplete(interaction);
|
await command.autocomplete(interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error handling autocomplete for ${interaction.commandName}:`, error);
|
logger.error("bot", `Error handling autocomplete for ${interaction.commandName}`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import { AuroraClient } from "@/lib/BotClient";
|
|||||||
import { ChatInputCommandInteraction } from "discord.js";
|
import { ChatInputCommandInteraction } from "discord.js";
|
||||||
|
|
||||||
// Mock UserService
|
// Mock UserService
|
||||||
mock.module("@/modules/user/user.service", () => ({
|
mock.module("@shared/modules/user/user.service", () => ({
|
||||||
userService: {
|
userService: {
|
||||||
getOrCreateUser: mock(() => Promise.resolve())
|
getOrCreateUser: mock(() => Promise.resolve())
|
||||||
}
|
}
|
||||||
@@ -56,4 +56,28 @@ describe("CommandHandler", () => {
|
|||||||
expect(executeError).toHaveBeenCalled();
|
expect(executeError).toHaveBeenCalled();
|
||||||
expect(AuroraClient.lastCommandTimestamp).toBeNull();
|
expect(AuroraClient.lastCommandTimestamp).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should block execution when maintenance mode is active", async () => {
|
||||||
|
AuroraClient.maintenanceMode = true;
|
||||||
|
const executeSpy = mock(() => Promise.resolve());
|
||||||
|
AuroraClient.commands.set("maint-test", {
|
||||||
|
data: { name: "maint-test" } as any,
|
||||||
|
execute: executeSpy
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
const interaction = {
|
||||||
|
commandName: "maint-test",
|
||||||
|
user: { id: "123", username: "testuser" },
|
||||||
|
reply: mock(() => Promise.resolve())
|
||||||
|
} as unknown as ChatInputCommandInteraction;
|
||||||
|
|
||||||
|
await CommandHandler.handle(interaction);
|
||||||
|
|
||||||
|
expect(executeSpy).not.toHaveBeenCalled();
|
||||||
|
expect(interaction.reply).toHaveBeenCalledWith(expect.objectContaining({
|
||||||
|
flags: expect.anything()
|
||||||
|
}));
|
||||||
|
|
||||||
|
AuroraClient.maintenanceMode = false; // Reset for other tests
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { ChatInputCommandInteraction, MessageFlags } from "discord.js";
|
import { ChatInputCommandInteraction, MessageFlags } from "discord.js";
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { createErrorEmbed } from "@lib/embeds";
|
import { createErrorEmbed } from "@lib/embeds";
|
||||||
import { logger } from "@lib/logger";
|
import { logger } from "@shared/lib/logger";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles slash command execution
|
* Handles slash command execution
|
||||||
@@ -13,7 +14,14 @@ export class CommandHandler {
|
|||||||
const command = AuroraClient.commands.get(interaction.commandName);
|
const command = AuroraClient.commands.get(interaction.commandName);
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
logger.error(`No command matching ${interaction.commandName} was found.`);
|
logger.error("bot", `No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check maintenance mode
|
||||||
|
if (AuroraClient.maintenanceMode) {
|
||||||
|
const errorEmbed = createErrorEmbed('The bot is currently undergoing maintenance. Please try again later.');
|
||||||
|
await interaction.reply({ embeds: [errorEmbed], flags: MessageFlags.Ephemeral });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,14 +29,14 @@ export class CommandHandler {
|
|||||||
try {
|
try {
|
||||||
await userService.getOrCreateUser(interaction.user.id, interaction.user.username);
|
await userService.getOrCreateUser(interaction.user.id, interaction.user.username);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Failed to ensure user exists:", error);
|
logger.error("bot", "Failed to ensure user exists", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
AuroraClient.lastCommandTimestamp = Date.now();
|
AuroraClient.lastCommandTimestamp = Date.now();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(String(error));
|
logger.error("bot", `Error executing command ${interaction.commandName}`, error);
|
||||||
const errorEmbed = createErrorEmbed('There was an error while executing this command!');
|
const errorEmbed = createErrorEmbed('There was an error while executing this command!');
|
||||||
|
|
||||||
if (interaction.replied || interaction.deferred) {
|
if (interaction.replied || interaction.deferred) {
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ButtonInteraction, StringSelectMenuInteraction, ModalSubmitInteraction, MessageFlags } from "discord.js";
|
import { ButtonInteraction, StringSelectMenuInteraction, ModalSubmitInteraction, MessageFlags } from "discord.js";
|
||||||
import { logger } from "@lib/logger";
|
|
||||||
import { UserError } from "@lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
import { createErrorEmbed } from "@lib/embeds";
|
import { createErrorEmbed } from "@lib/embeds";
|
||||||
|
import { logger } from "@shared/lib/logger";
|
||||||
|
|
||||||
type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction;
|
type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ export class ComponentInteractionHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error(`Handler method ${route.method} not found in module`);
|
logger.error("bot", `Handler method ${route.method} not found in module`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ export class ComponentInteractionHandler {
|
|||||||
|
|
||||||
// Log system errors (non-user errors) for debugging
|
// Log system errors (non-user errors) for debugging
|
||||||
if (!isUserError) {
|
if (!isUserError) {
|
||||||
logger.error(`Error in ${handlerName}:`, error);
|
logger.error("bot", `Error in ${handlerName}`, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorEmbed = createErrorEmbed(errorMessage);
|
const errorEmbed = createErrorEmbed(errorMessage);
|
||||||
@@ -72,7 +73,7 @@ export class ComponentInteractionHandler {
|
|||||||
}
|
}
|
||||||
} catch (replyError) {
|
} catch (replyError) {
|
||||||
// If we can't send a reply, log it
|
// If we can't send a reply, log it
|
||||||
logger.error(`Failed to send error response in ${handlerName}:`, replyError);
|
logger.error("bot", `Failed to send error response in ${handlerName}`, replyError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,11 @@ export const interactionRoutes: InteractionRoute[] = [
|
|||||||
handler: () => import("@/modules/economy/lootdrop.interaction"),
|
handler: () => import("@/modules/economy/lootdrop.interaction"),
|
||||||
method: 'handleLootdropInteraction'
|
method: 'handleLootdropInteraction'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
predicate: (i) => i.isButton() && i.customId.startsWith("trivia_"),
|
||||||
|
handler: () => import("@/modules/trivia/trivia.interaction"),
|
||||||
|
method: 'handleTriviaInteraction'
|
||||||
|
},
|
||||||
|
|
||||||
// --- ADMIN MODULE ---
|
// --- ADMIN MODULE ---
|
||||||
{
|
{
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { readdir } from "node:fs/promises";
|
import { readdir } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { Command } from "@lib/types";
|
import type { Command } from "@shared/lib/types";
|
||||||
import { config } from "@lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import type { LoadResult, LoadError } from "./types";
|
import type { LoadResult, LoadError } from "./types";
|
||||||
import type { Client } from "../BotClient";
|
import type { Client } from "../BotClient";
|
||||||
import { logger } from "@lib/logger";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles loading commands from the file system
|
* Handles loading commands from the file system
|
||||||
@@ -45,7 +45,7 @@ export class CommandLoader {
|
|||||||
await this.loadCommandFile(filePath, reload, result);
|
await this.loadCommandFile(filePath, reload, result);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error reading directory ${dir}:`, error);
|
console.error(`Error reading directory ${dir}:`, error);
|
||||||
result.errors.push({ file: dir, error });
|
result.errors.push({ file: dir, error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ export class CommandLoader {
|
|||||||
const commands = Object.values(commandModule);
|
const commands = Object.values(commandModule);
|
||||||
|
|
||||||
if (commands.length === 0) {
|
if (commands.length === 0) {
|
||||||
logger.warn(`No commands found in ${filePath}`);
|
console.warn(`No commands found in ${filePath}`);
|
||||||
result.skipped++;
|
result.skipped++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -71,24 +71,27 @@ export class CommandLoader {
|
|||||||
if (this.isValidCommand(command)) {
|
if (this.isValidCommand(command)) {
|
||||||
command.category = category;
|
command.category = category;
|
||||||
|
|
||||||
|
// Track all known commands regardless of enabled status
|
||||||
|
this.client.knownCommands.set(command.data.name, category);
|
||||||
|
|
||||||
const isEnabled = config.commands[command.data.name] !== false;
|
const isEnabled = config.commands[command.data.name] !== false;
|
||||||
|
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
logger.info(`🚫 Skipping disabled command: ${command.data.name}`);
|
console.log(`🚫 Skipping disabled command: ${command.data.name}`);
|
||||||
result.skipped++;
|
result.skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.commands.set(command.data.name, command);
|
this.client.commands.set(command.data.name, command);
|
||||||
logger.success(`Loaded command: ${command.data.name}`);
|
console.log(`Loaded command: ${command.data.name}`);
|
||||||
result.loaded++;
|
result.loaded++;
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`Skipping invalid command in ${filePath}`);
|
console.warn(`Skipping invalid command in ${filePath}`);
|
||||||
result.skipped++;
|
result.skipped++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to load command from ${filePath}:`, error);
|
console.error(`Failed to load command from ${filePath}:`, error);
|
||||||
result.errors.push({ file: filePath, error });
|
result.errors.push({ file: filePath, error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { readdir } from "node:fs/promises";
|
import { readdir } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { Event } from "@lib/types";
|
import type { Event } from "@shared/lib/types";
|
||||||
import type { LoadResult } from "./types";
|
import type { LoadResult } from "./types";
|
||||||
import type { Client } from "../BotClient";
|
import type { Client } from "../BotClient";
|
||||||
import { logger } from "@lib/logger";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles loading events from the file system
|
* Handles loading events from the file system
|
||||||
@@ -44,7 +44,7 @@ export class EventLoader {
|
|||||||
await this.loadEventFile(filePath, reload, result);
|
await this.loadEventFile(filePath, reload, result);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error reading directory ${dir}:`, error);
|
console.error(`Error reading directory ${dir}:`, error);
|
||||||
result.errors.push({ file: dir, error });
|
result.errors.push({ file: dir, error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,14 +64,14 @@ export class EventLoader {
|
|||||||
} else {
|
} else {
|
||||||
this.client.on(event.name, (...args) => event.execute(...args));
|
this.client.on(event.name, (...args) => event.execute(...args));
|
||||||
}
|
}
|
||||||
logger.success(`Loaded event: ${event.name}`);
|
console.log(`Loaded event: ${event.name}`);
|
||||||
result.loaded++;
|
result.loaded++;
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`Skipping invalid event in ${filePath}`);
|
console.warn(`Skipping invalid event in ${filePath}`);
|
||||||
result.skipped++;
|
result.skipped++;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to load event from ${filePath}:`, error);
|
console.error(`Failed to load event from ${filePath}:`, error);
|
||||||
result.errors.push({ file: filePath, error });
|
result.errors.push({ file: filePath, error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { logger } from "@lib/logger";
|
|
||||||
|
|
||||||
let shuttingDown = false;
|
let shuttingDown = false;
|
||||||
let activeTransactions = 0;
|
let activeTransactions = 0;
|
||||||
@@ -22,7 +22,7 @@ export const waitForTransactions = async (timeoutMs: number = 10000) => {
|
|||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
while (activeTransactions > 0) {
|
while (activeTransactions > 0) {
|
||||||
if (Date.now() - start > timeoutMs) {
|
if (Date.now() - start > timeoutMs) {
|
||||||
logger.warn(`Shutdown timed out waiting for ${activeTransactions} transactions after ${timeoutMs}ms`);
|
console.warn(`Shutdown timed out waiting for ${activeTransactions} transactions after ${timeoutMs}ms`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
@@ -6,13 +6,13 @@ import { ButtonInteraction, ModalSubmitInteraction, StringSelectMenuInteraction
|
|||||||
const valuesMock = mock((_args: any) => Promise.resolve());
|
const valuesMock = mock((_args: any) => Promise.resolve());
|
||||||
const insertMock = mock(() => ({ values: valuesMock }));
|
const insertMock = mock(() => ({ values: valuesMock }));
|
||||||
|
|
||||||
mock.module("@/lib/DrizzleClient", () => ({
|
mock.module("@shared/db/DrizzleClient", () => ({
|
||||||
DrizzleClient: {
|
DrizzleClient: {
|
||||||
insert: insertMock
|
insert: insertMock
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mock.module("@/db/schema", () => ({
|
mock.module("@db/schema", () => ({
|
||||||
items: "items_schema"
|
items: "items_schema"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { type Interaction } from "discord.js";
|
import { type Interaction } from "discord.js";
|
||||||
import { items } from "@/db/schema";
|
import { items } from "@db/schema";
|
||||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||||
import type { ItemUsageData, ItemEffect } from "@/lib/types";
|
import type { ItemUsageData, ItemEffect } from "@shared/lib/types";
|
||||||
import { getItemWizardEmbed, getItemTypeSelection, getEffectTypeSelection, getDetailsModal, getEconomyModal, getVisualsModal, getEffectConfigModal } from "./item_wizard.view";
|
import { getItemWizardEmbed, getItemTypeSelection, getEffectTypeSelection, getDetailsModal, getEconomyModal, getVisualsModal, getEffectConfigModal } from "./item_wizard.view";
|
||||||
import type { DraftItem } from "./item_wizard.types";
|
import type { DraftItem } from "./item_wizard.types";
|
||||||
import { ItemType, EffectType } from "@/lib/constants";
|
import { ItemType, EffectType } from "@shared/lib/constants";
|
||||||
|
|
||||||
// --- Types ---
|
// --- Types ---
|
||||||
|
|
||||||
@@ -241,3 +241,8 @@ export const handleItemWizardInteraction = async (interaction: Interaction) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const clearDraftSessions = () => {
|
||||||
|
draftSession.clear();
|
||||||
|
console.log("[ItemWizard] All draft item creation sessions cleared.");
|
||||||
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { ItemUsageData } from "@/lib/types";
|
import type { ItemUsageData } from "@shared/lib/types";
|
||||||
|
|
||||||
export interface DraftItem {
|
export interface DraftItem {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { createBaseEmbed } from "@lib/embeds";
|
import { createBaseEmbed } from "@lib/embeds";
|
||||||
import type { DraftItem } from "./item_wizard.types";
|
import type { DraftItem } from "./item_wizard.types";
|
||||||
import { ItemType } from "@/lib/constants";
|
import { ItemType } from "@shared/lib/constants";
|
||||||
|
|
||||||
const getItemTypeOptions = () => [
|
const getItemTypeOptions = () => [
|
||||||
{ label: "Material", value: ItemType.MATERIAL, description: "Used for crafting or trading" },
|
{ label: "Material", value: ItemType.MATERIAL, description: "Used for crafting or trading" },
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ButtonInteraction } from "discord.js";
|
import { ButtonInteraction } from "discord.js";
|
||||||
import { lootdropService } from "./lootdrop.service";
|
import { lootdropService } from "@shared/modules/economy/lootdrop.service";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
import { getLootdropClaimedMessage } from "./lootdrop.view";
|
import { getLootdropClaimedMessage } from "./lootdrop.view";
|
||||||
|
|
||||||
export async function handleLootdropInteraction(interaction: ButtonInteraction) {
|
export async function handleLootdropInteraction(interaction: ButtonInteraction) {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ButtonInteraction, MessageFlags } from "discord.js";
|
import { ButtonInteraction, MessageFlags } from "discord.js";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { userService } from "@/modules/user/user.service";
|
import { userService } from "@shared/modules/user/user.service";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
|
||||||
export async function handleShopInteraction(interaction: ButtonInteraction) {
|
export async function handleShopInteraction(interaction: ButtonInteraction) {
|
||||||
if (!interaction.customId.startsWith("shop_buy_")) return;
|
if (!interaction.customId.startsWith("shop_buy_")) return;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { Interaction } from "discord.js";
|
import type { Interaction } from "discord.js";
|
||||||
import { TextChannel, MessageFlags } from "discord.js";
|
import { TextChannel, MessageFlags } from "discord.js";
|
||||||
import { config } from "@/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { AuroraClient } from "@/lib/BotClient";
|
import { AuroraClient } from "@/lib/BotClient";
|
||||||
import { buildFeedbackMessage, getFeedbackModal } from "./feedback.view";
|
import { buildFeedbackMessage, getFeedbackModal } from "./feedback.view";
|
||||||
import { FEEDBACK_CUSTOM_IDS, type FeedbackType, type FeedbackData } from "./feedback.types";
|
import { FEEDBACK_CUSTOM_IDS, type FeedbackType, type FeedbackData } from "./feedback.types";
|
||||||
import { UserError } from "@/lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
|
|
||||||
export const handleFeedbackInteraction = async (interaction: Interaction) => {
|
export const handleFeedbackInteraction = async (interaction: Interaction) => {
|
||||||
// Handle select menu for choosing feedback type
|
// Handle select menu for choosing feedback type
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { levelingService } from "@/modules/leveling/leveling.service";
|
import { levelingService } from "@shared/modules/leveling/leveling.service";
|
||||||
import { economyService } from "@/modules/economy/economy.service";
|
import { economyService } from "@shared/modules/economy/economy.service";
|
||||||
import { userTimers } from "@/db/schema";
|
import { userTimers } from "@db/schema";
|
||||||
import type { EffectHandler } from "./types";
|
import type { EffectHandler } from "./types";
|
||||||
import type { LootTableItem } from "@/lib/types";
|
import type { LootTableItem } from "@shared/lib/types";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { inventory, items } from "@/db/schema";
|
import { inventory, items } from "@db/schema";
|
||||||
import { TimerType, TransactionType, LootType } from "@/lib/constants";
|
import { TimerType, TransactionType, LootType } from "@shared/lib/constants";
|
||||||
|
|
||||||
|
|
||||||
// Helper to extract duration in seconds
|
// Helper to extract duration in seconds
|
||||||
@@ -120,7 +120,7 @@ export const handleLootbox: EffectHandler = async (userId, effect, txFn) => {
|
|||||||
// Try to fetch item name for the message
|
// Try to fetch item name for the message
|
||||||
try {
|
try {
|
||||||
const item = await txFn.query.items.findFirst({
|
const item = await txFn.query.items.findFirst({
|
||||||
where: (items, { eq }) => eq(items.id, winner.itemId!)
|
where: (items: any, { eq }: any) => eq(items.id, winner.itemId!)
|
||||||
});
|
});
|
||||||
if (item) {
|
if (item) {
|
||||||
return winner.message || `You found ${quantity > 1 ? quantity + 'x ' : ''}**${item.name}**!`;
|
return winner.message || `You found ${quantity > 1 ? quantity + 'x ' : ''}**${item.name}**!`;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
import type { Transaction } from "@/lib/types";
|
import type { Transaction } from "@shared/lib/types";
|
||||||
|
|
||||||
export type EffectHandler = (userId: string, effect: any, txFn: Transaction) => Promise<string>;
|
export type EffectHandler = (userId: string, effect: any, txFn: Transaction) => Promise<string>;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { EmbedBuilder } from "discord.js";
|
import { EmbedBuilder } from "discord.js";
|
||||||
import type { ItemUsageData } from "@/lib/types";
|
import type { ItemUsageData } from "@shared/lib/types";
|
||||||
import { EffectType } from "@/lib/constants";
|
import { EffectType } from "@shared/lib/constants";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inventory entry with item details
|
* Inventory entry with item details
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CaseType } from "@/lib/constants";
|
import { CaseType } from "@shared/lib/constants";
|
||||||
|
|
||||||
export { CaseType };
|
export { CaseType };
|
||||||
|
|
||||||
218
bot/modules/quest/quest.view.ts
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
import {
|
||||||
|
ActionRowBuilder,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
|
ContainerBuilder,
|
||||||
|
TextDisplayBuilder,
|
||||||
|
SeparatorBuilder,
|
||||||
|
SeparatorSpacingSize,
|
||||||
|
MessageFlags
|
||||||
|
} from "discord.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quest entry with quest details and progress
|
||||||
|
*/
|
||||||
|
interface QuestEntry {
|
||||||
|
progress: number | null;
|
||||||
|
completedAt: Date | null;
|
||||||
|
quest: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
triggerEvent: string;
|
||||||
|
requirements: any;
|
||||||
|
rewards: any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available quest interface
|
||||||
|
*/
|
||||||
|
interface AvailableQuest {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
rewards: any;
|
||||||
|
requirements: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Color palette for containers
|
||||||
|
const COLORS = {
|
||||||
|
ACTIVE: 0x3498db, // Blue - in progress
|
||||||
|
AVAILABLE: 0x2ecc71, // Green - available
|
||||||
|
COMPLETED: 0xf1c40f // Gold - completed
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats quest rewards object into a human-readable string
|
||||||
|
*/
|
||||||
|
function formatQuestRewards(rewards: { xp?: number, balance?: number }): string {
|
||||||
|
const rewardStr: string[] = [];
|
||||||
|
if (rewards?.xp) rewardStr.push(`${rewards.xp} XP`);
|
||||||
|
if (rewards?.balance) rewardStr.push(`${rewards.balance} 🪙`);
|
||||||
|
return rewardStr.join(" • ") || "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a simple progress bar
|
||||||
|
*/
|
||||||
|
function renderProgressBar(current: number, total: number, size: number = 10): string {
|
||||||
|
const percentage = Math.min(current / total, 1);
|
||||||
|
const progress = Math.round(size * percentage);
|
||||||
|
const empty = size - progress;
|
||||||
|
|
||||||
|
const progressText = "▰".repeat(progress);
|
||||||
|
const emptyText = "▱".repeat(empty);
|
||||||
|
|
||||||
|
return `${progressText}${emptyText} ${Math.round(percentage * 100)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Components v2 containers for the quest list (active quests only)
|
||||||
|
*/
|
||||||
|
export function getQuestListComponents(userQuests: QuestEntry[]): ContainerBuilder[] {
|
||||||
|
// Filter to only show in-progress quests (not completed)
|
||||||
|
const activeQuests = userQuests.filter(entry => entry.completedAt === null);
|
||||||
|
|
||||||
|
const container = new ContainerBuilder()
|
||||||
|
.setAccentColor(COLORS.ACTIVE)
|
||||||
|
.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent("# 📜 Quest Log"),
|
||||||
|
new TextDisplayBuilder().setContent("-# Your active quests")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (activeQuests.length === 0) {
|
||||||
|
container.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small));
|
||||||
|
container.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent("*You have no active quests. Check available quests!*")
|
||||||
|
);
|
||||||
|
return [container];
|
||||||
|
}
|
||||||
|
|
||||||
|
activeQuests.forEach((entry) => {
|
||||||
|
container.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small));
|
||||||
|
|
||||||
|
const rewards = entry.quest.rewards as { xp?: number, balance?: number };
|
||||||
|
const rewardsText = formatQuestRewards(rewards);
|
||||||
|
|
||||||
|
const requirements = entry.quest.requirements as { target?: number };
|
||||||
|
const target = requirements?.target || 1;
|
||||||
|
const progress = entry.progress || 0;
|
||||||
|
const progressBar = renderProgressBar(progress, target);
|
||||||
|
|
||||||
|
container.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent(`**${entry.quest.name}**`),
|
||||||
|
new TextDisplayBuilder().setContent(entry.quest.description || "*No description*"),
|
||||||
|
new TextDisplayBuilder().setContent(`📊 ${progressBar} \`${progress}/${target}\` • 🎁 ${rewardsText}`)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return [container];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Components v2 containers for available quests with inline accept buttons
|
||||||
|
*/
|
||||||
|
export function getAvailableQuestsComponents(availableQuests: AvailableQuest[]): ContainerBuilder[] {
|
||||||
|
const container = new ContainerBuilder()
|
||||||
|
.setAccentColor(COLORS.AVAILABLE)
|
||||||
|
.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent("# 🗺️ Available Quests"),
|
||||||
|
new TextDisplayBuilder().setContent("-# Quests you can accept")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (availableQuests.length === 0) {
|
||||||
|
container.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small));
|
||||||
|
container.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent("*No new quests available at the moment.*")
|
||||||
|
);
|
||||||
|
return [container];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit to 10 quests (5 action rows max with 2 added for navigation)
|
||||||
|
const questsToShow = availableQuests.slice(0, 10);
|
||||||
|
|
||||||
|
questsToShow.forEach((quest) => {
|
||||||
|
container.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small));
|
||||||
|
|
||||||
|
const rewards = quest.rewards as { xp?: number, balance?: number };
|
||||||
|
const rewardsText = formatQuestRewards(rewards);
|
||||||
|
|
||||||
|
const requirements = quest.requirements as { target?: number };
|
||||||
|
const target = requirements?.target || 1;
|
||||||
|
|
||||||
|
container.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent(`**${quest.name}**`),
|
||||||
|
new TextDisplayBuilder().setContent(quest.description || "*No description*"),
|
||||||
|
new TextDisplayBuilder().setContent(`🎯 Goal: \`${target}\` • 🎁 ${rewardsText}`)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add accept button inline within the container
|
||||||
|
container.addActionRowComponents(
|
||||||
|
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`quest_accept:${quest.id}`)
|
||||||
|
.setLabel("Accept Quest")
|
||||||
|
.setStyle(ButtonStyle.Success)
|
||||||
|
.setEmoji("✅")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return [container];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns action rows for navigation only
|
||||||
|
*/
|
||||||
|
export function getQuestActionRows(viewType: 'active' | 'available'): ActionRowBuilder<ButtonBuilder>[] {
|
||||||
|
// Navigation row
|
||||||
|
const navRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("quest_view_active")
|
||||||
|
.setLabel("📜 Active")
|
||||||
|
.setStyle(viewType === 'active' ? ButtonStyle.Primary : ButtonStyle.Secondary)
|
||||||
|
.setDisabled(viewType === 'active'),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("quest_view_available")
|
||||||
|
.setLabel("🗺️ Available")
|
||||||
|
.setStyle(viewType === 'available' ? ButtonStyle.Primary : ButtonStyle.Secondary)
|
||||||
|
.setDisabled(viewType === 'available')
|
||||||
|
);
|
||||||
|
|
||||||
|
return [navRow];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Components v2 celebratory message for quest completion
|
||||||
|
*/
|
||||||
|
export function getQuestCompletionComponents(quest: any, rewards: { xp: bigint, balance: bigint }): ContainerBuilder[] {
|
||||||
|
const rewardsText = formatQuestRewards({
|
||||||
|
xp: Number(rewards.xp),
|
||||||
|
balance: Number(rewards.balance)
|
||||||
|
});
|
||||||
|
|
||||||
|
const container = new ContainerBuilder()
|
||||||
|
.setAccentColor(COLORS.COMPLETED)
|
||||||
|
.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent("# 🎉 Quest Completed!"),
|
||||||
|
new TextDisplayBuilder().setContent(`Congratulations! You've completed **${quest.name}**`)
|
||||||
|
)
|
||||||
|
.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small))
|
||||||
|
.addTextDisplayComponents(
|
||||||
|
new TextDisplayBuilder().setContent(`📝 ${quest.description || "No description provided."}`),
|
||||||
|
new TextDisplayBuilder().setContent(`🎁 **Rewards Earned:** ${rewardsText}`)
|
||||||
|
);
|
||||||
|
|
||||||
|
return [container];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets MessageFlags and allowedMentions for Components v2 messages
|
||||||
|
*/
|
||||||
|
export function getComponentsV2MessageFlags() {
|
||||||
|
return {
|
||||||
|
flags: MessageFlags.IsComponentsV2,
|
||||||
|
allowedMentions: { parse: [] as const }
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { temporaryRoleService } from "./temp-role.service";
|
import { temporaryRoleService } from "@shared/modules/system/temp-role.service";
|
||||||
|
|
||||||
export const schedulerService = {
|
export const schedulerService = {
|
||||||
start: () => {
|
start: () => {
|
||||||
@@ -10,7 +10,7 @@ export const schedulerService = {
|
|||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
|
|
||||||
// 2. Terminal Update Loop (every 60s)
|
// 2. Terminal Update Loop (every 60s)
|
||||||
const { terminalService } = require("@/modules/terminal/terminal.service");
|
const { terminalService } = require("@shared/modules/terminal/terminal.service");
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
terminalService.update();
|
terminalService.update();
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
@@ -7,10 +7,10 @@ import {
|
|||||||
TextChannel,
|
TextChannel,
|
||||||
EmbedBuilder
|
EmbedBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { tradeService } from "./trade.service";
|
import { tradeService } from "@shared/modules/trade/trade.service";
|
||||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
import { inventoryService } from "@shared/modules/inventory/inventory.service";
|
||||||
import { createErrorEmbed, createWarningEmbed, createSuccessEmbed, createInfoEmbed } from "@lib/embeds";
|
import { createErrorEmbed, createWarningEmbed, createSuccessEmbed, createInfoEmbed } from "@lib/embeds";
|
||||||
import { UserError } from "@lib/errors";
|
import { UserError } from "@shared/lib/errors";
|
||||||
import { getTradeDashboard, getTradeMoneyModal, getItemSelectMenu, getTradeCompletedEmbed } from "./trade.view";
|
import { getTradeDashboard, getTradeMoneyModal, getItemSelectMenu, getTradeCompletedEmbed } from "./trade.view";
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ async function handleAddItemClick(interaction: ButtonInteraction, threadId: stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slice top 25 for select menu
|
// Slice top 25 for select menu
|
||||||
const options = inventory.slice(0, 25).map(entry => ({
|
const options = inventory.slice(0, 25).map((entry: any) => ({
|
||||||
label: `${entry.item.name} (${entry.quantity})`,
|
label: `${entry.item.name} (${entry.quantity})`,
|
||||||
value: entry.item.id.toString(),
|
value: entry.item.id.toString(),
|
||||||
description: `Rarity: ${entry.item.rarity} `
|
description: `Rarity: ${entry.item.rarity} `
|
||||||