feat: implement selfbot workspace submodule

- Add `discord.js-selfbot-v13` as a git submodule in `vendor/`
- Update `pnpm-workspace.yaml` to include the new submodule path
- Modify `.gitmodules` to track the submodule repository
- Change `discord.js-selfbot-v13` dependency in `package.json` to use `workspace:*`
- Create implementation and design documents for the submodule integration
This commit is contained in:
MythEclipse
2026-05-15 05:45:19 +07:00
parent bbd3a88471
commit bbd65d369e
8 changed files with 5072 additions and 144 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "vendor/discord.js-selfbot-v13"]
path = vendor/discord.js-selfbot-v13
url = ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git

200
README.md
View File

@@ -1,15 +1,18 @@
# 🎙️ Discord Voice Recorder Bot # Discord Moderation Watcher Bot
Bot Discord yang **otomatis join ke voice channel** saat startup dan **merekam suara** semua pengguna yang bicara. File audio disimpan secara lokal dalam format `.ogg`. Bot monitoring Discord yang merekam voice channel, menangkap pesan teks, menyimpan attachment, menjalankan analisis opsional, dan menyediakan dashboard web real-time.
Dibangun dengan **Bun** + **discord.js** + **@discordjs/voice**. Stack utama: Node.js, pnpm, TypeScript, `discord.js-selfbot-v13`, `@discordjs/voice`, Express, WebSocket, Drizzle ORM, SQLite/PostgreSQL, React, Vite, Vitest, dan Biome.
--- ## Prasyarat
## 📋 Prasyarat - Node.js versi modern yang kompatibel dengan TypeScript dan Vite.
- pnpm 10.x. Repo ini dipin ke `pnpm@10.25.0`.
- FFmpeg tersedia di `PATH` untuk proses muxing audio.
- Native audio dependencies dapat dibuild di mesin lokal (`@discordjs/opus`, `better-sqlite3`, `sodium-native`).
Install FFmpeg:
- [Bun](https://bun.sh) >= 1.0
- FFmpeg (untuk encoding audio)
```bash ```bash
# Ubuntu/Debian # Ubuntu/Debian
sudo apt install ffmpeg sudo apt install ffmpeg
@@ -17,87 +20,152 @@ Dibangun dengan **Bun** + **discord.js** + **@discordjs/voice**.
# Arch # Arch
sudo pacman -S ffmpeg sudo pacman -S ffmpeg
``` ```
- Discord Bot dengan permission:
- `Connect` (join voice channel)
- `Use Voice Activity`
- `Read Messages/View Channels`
- Privileged Intents: **Server Members Intent** (aktifkan di Developer Portal)
--- ## Setup
## ⚙️ Setup
### 1. Clone & Install
```bash
cd /path/to/bot
bun install
```
### 2. Konfigurasi `.env`
```bash ```bash
pnpm install
cp .env.example .env cp .env.example .env
``` ```
Edit `.env`: Edit `.env` sesuai server yang dimonitor:
```env ```env
DISCORD_TOKEN=your_bot_token_here DISCORD_TOKEN=your_token_here
VOICE_CHANNEL_ID=your_voice_channel_id_here MONITOR_GUILD_ID=your_guild_id_here
GUILD_ID=your_guild_id_here
RECORDINGS_DIR=./recordings RECORDINGS_DIR=./recordings
WEBSERVER_PORT=3000
DATABASE_TYPE=sqlite
``` ```
**Cara mendapatkan ID:** Catatan: project ini memakai selfbot library, bukan bot token Discord standar. Pastikan penggunaan sesuai risiko dan aturan platform yang berlaku.
- Aktifkan **Developer Mode** di Discord (Settings → Advanced → Developer Mode)
- Klik kanan pada voice channel → **Copy Channel ID** → paste ke `VOICE_CHANNEL_ID`
- Klik kanan pada server/guild → **Copy Server ID** → paste ke `GUILD_ID`
- Token bot dari [Discord Developer Portal](https://discord.com/developers/applications) → Bot → Reset Token
### 3. Invite Bot ke Server ## Menjalankan
Di Developer Portal → OAuth2 → URL Generator:
- Scopes: `bot`
- Bot Permissions: `Connect`, `Use Voice Activity`, `View Channels`
Copy URL, buka di browser, pilih server.
---
## 🚀 Menjalankan Bot
```bash ```bash
# Development (auto-restart saat file berubah) # Bot/server utama dengan auto-restart
bun run dev pnpm run dev
# Production # Production-style start
bun run start pnpm run start
# Dashboard frontend dev server
pnpm run dev:web
``` ```
Bot akan langsung join ke voice channel yang ditentukan dalam `.env`. Dashboard build production disajikan dari `public/app` setelah menjalankan:
---
## 📁 Struktur File Rekaman
```bash
pnpm run build:web
``` ```
## Command Development
```bash
# Type checking
pnpm run typecheck
# Lint
pnpm run lint
# Format
pnpm run format
# Test
pnpm run test
# Build frontend + TypeScript
pnpm run build
```
## Database
Default database adalah SQLite di `.muxer-queue.db`. PostgreSQL dapat dipakai dengan `DATABASE_TYPE=postgres` dan konfigurasi `DATABASE_URL` atau variabel `POSTGRES_*`.
```bash
# Generate migration Drizzle
pnpm run db:generate
# Jalankan migration via drizzle-kit
pnpm run db:migrate
# Jalankan migration programmatic
pnpm run db:migrate:programmatic
# Buka Drizzle Studio
pnpm run db:studio
```
## Fitur
- Voice recording ke segment `.ogg` per user.
- Metadata JSON per segment audio.
- Text message capture untuk pesan baru, edit, dan delete.
- Attachment capture dan upload ke endpoint Picser.
- SQLite/PostgreSQL via Drizzle ORM.
- REST API dan WebSocket untuk dashboard.
- Dashboard React untuk pesan, gambar, voice, dan moderation review.
- Metrics Prometheus di endpoint server.
- Retry dengan backoff untuk operasi eksternal.
- AI moderation analysis opsional via konfigurasi `AI_*`.
## Struktur Rekaman
```text
recordings/ recordings/
├── 123456789-1709900000000.ogg # <user-id>-<timestamp>.ogg <user-id>/
├── 987654321-1709900001234.ogg <user-id>-<session-start>-0.ogg
└── ... <user-id>-<session-start>-0.json
<user-id>-<session-start>-1.ogg
<user-id>-<session-start>-1.json
``` ```
Setiap kali user bicara dan berhenti (>1 detik diam), satu file `.ogg` baru dibuat. Segment duration dikontrol oleh `RECORDING_SEGMENT_MS`.
--- ## Struktur Proyek
## 📁 Struktur Proyek
```text
src/
index.ts Entry point Discord client dan server
recorder.ts Voice recording pipeline
recorder/ Audio stream, decoder, segment metadata
moderation/ Message capture, storage, uploads, AI review
database/ Drizzle setup, schema, migrations
routes/ Express route modules
webserver.ts Express + WebSocket server
retry.ts Retry helper berbasis p-retry
audio/ffmpegProcess.ts Direct ffmpeg process wrapper
frontend/ React dashboard source
public/app/ Dashboard build output
tests/ Vitest tests
drizzle/migrations/ Database migrations
``` ```
bot/
├── src/ ## Konfigurasi Penting
│ ├── index.ts # Entry point — login & auto-join
│ └── recorder.ts # Core recording logic Lihat `.env.example` untuk daftar lengkap. Variabel utama:
├── recordings/ # File audio tersimpan (otomatis dibuat)
├── .env # Konfigurasi (buat dari .env.example) - `DISCORD_TOKEN` — token akun/client yang dipakai selfbot.
├── .env.example - `MONITOR_GUILD_ID` — guild yang dimonitor untuk moderation capture.
├── package.json - `RECORDINGS_DIR` — direktori output audio.
└── tsconfig.json - `WEBSERVER_PORT` — port HTTP/WebSocket.
- `DATABASE_TYPE``sqlite` atau `postgres`.
- `PICSER_UPLOAD_URL` — endpoint upload attachment.
- `AI_ANALYSIS_ENABLED` — aktifkan/nonaktifkan analisis AI.
- `AI_LLM_API_KEY`, `AI_LLM_BASE_URL`, `AI_LLM_MODEL` — konfigurasi provider LLM.
## Verifikasi Setelah Perubahan
Sebelum menjalankan lama atau deploy, jalankan:
```bash
pnpm install
pnpm run typecheck
pnpm run lint
pnpm run test
pnpm run build
``` ```
## Catatan Library Modernization
Project memakai Zod untuk validasi runtime, Drizzle untuk database, dan wrapper `node:child_process` langsung untuk FFmpeg. Library lama `class-transformer`, `class-validator`, dan `fluent-ffmpeg` sudah tidak dipakai.

View File

@@ -0,0 +1,239 @@
# Selfbot Workspace Submodule Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Replace the npm `discord.js-selfbot-v13` dependency with a custom git submodule consumed through pnpm workspace resolution.
**Architecture:** The vendored selfbot library lives at `vendor/discord.js-selfbot-v13` as a git submodule. The root package depends on it with `workspace:*`, and `pnpm-workspace.yaml` includes both the root package and the vendored package while preserving the existing `onlyBuiltDependencies` settings.
**Tech Stack:** Git submodules, pnpm workspaces, TypeScript, existing Node.js package scripts.
---
## File Structure
- Create: `.gitmodules` if missing; otherwise modify it to include `vendor/discord.js-selfbot-v13`.
- Create: `vendor/discord.js-selfbot-v13` via `git submodule add`; do not create files in this directory manually.
- Modify: `pnpm-workspace.yaml` to add `packages` while preserving `onlyBuiltDependencies`.
- Modify: `package.json` dependency `discord.js-selfbot-v13` from `^3.7.1` to `workspace:*`.
- Modify: `pnpm-lock.yaml` by running pnpm, not by hand.
### Task 1: Add the selfbot repository as a submodule
**Files:**
- Create/Modify: `.gitmodules`
- Create: `vendor/discord.js-selfbot-v13`
- [ ] **Step 1: Confirm there is no existing submodule path**
Run:
```bash
git submodule status --recursive || true
test ! -e vendor/discord.js-selfbot-v13
```
Expected: either no existing submodule output, or output that does not include `vendor/discord.js-selfbot-v13`; the `test` command exits successfully.
- [ ] **Step 2: Add the upstream repository as a submodule**
Run:
```bash
git submodule add https://github.com/aiko-chan-ai/discord.js-selfbot-v13.git vendor/discord.js-selfbot-v13
```
Expected: git clones the repository into `vendor/discord.js-selfbot-v13` and creates or updates `.gitmodules`.
- [ ] **Step 3: Change the submodule remote to the internal SSH repository**
Run:
```bash
git -C vendor/discord.js-selfbot-v13 remote set-url origin ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git
git config -f .gitmodules submodule.vendor/discord.js-selfbot-v13.url ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git
git submodule sync vendor/discord.js-selfbot-v13
```
Expected: both the submodule checkout and `.gitmodules` use `ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git`.
- [ ] **Step 4: Verify submodule metadata**
Run:
```bash
git -C vendor/discord.js-selfbot-v13 remote get-url origin
git config -f .gitmodules --get submodule.vendor/discord.js-selfbot-v13.path
git config -f .gitmodules --get submodule.vendor/discord.js-selfbot-v13.url
```
Expected output:
```text
ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git
vendor/discord.js-selfbot-v13
ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git
```
### Task 2: Configure pnpm workspace resolution
**Files:**
- Modify: `pnpm-workspace.yaml`
- Modify: `package.json`
- [ ] **Step 1: Update pnpm workspace file**
Edit `pnpm-workspace.yaml` to exactly:
```yaml
packages:
- .
- vendor/discord.js-selfbot-v13
onlyBuiltDependencies:
- '@discordjs/opus'
- better-sqlite3
- esbuild
```
Expected: the existing `onlyBuiltDependencies` entries remain unchanged, and workspace packages now include root plus the vendored selfbot package.
- [ ] **Step 2: Update root dependency**
Edit `package.json` so the dependencies block contains:
```json
"discord.js-selfbot-v13": "workspace:*"
```
Expected: only the `discord.js-selfbot-v13` version source changes; the rest of `package.json` remains unchanged.
- [ ] **Step 3: Verify the submodule package name**
Run:
```bash
node -e "const p=require('./vendor/discord.js-selfbot-v13/package.json'); if (p.name !== 'discord.js-selfbot-v13') { throw new Error('unexpected package name: '+p.name) } console.log(p.name)"
```
Expected output:
```text
discord.js-selfbot-v13
```
### Task 3: Refresh dependency lockfile and install links
**Files:**
- Modify: `pnpm-lock.yaml`
- Modify: `node_modules` locally, not committed
- [ ] **Step 1: Refresh pnpm install state**
Run:
```bash
pnpm install
```
Expected: pnpm completes successfully and updates `pnpm-lock.yaml` so `discord.js-selfbot-v13` resolves from `link:vendor/discord.js-selfbot-v13` or equivalent workspace link notation.
- [ ] **Step 2: Verify pnpm resolves the workspace package**
Run:
```bash
pnpm list discord.js-selfbot-v13 --depth 0
```
Expected: output shows `discord.js-selfbot-v13` as a linked workspace dependency rather than the npm registry version.
- [ ] **Step 3: Inspect the lockfile entry**
Run:
```bash
grep -n "discord.js-selfbot-v13" pnpm-lock.yaml | head -20
```
Expected: the root importer entry for `discord.js-selfbot-v13` references `specifier: workspace:*` and a workspace/link version.
### Task 4: Validate root project compatibility
**Files:**
- Read-only validation for TypeScript project files.
- [ ] **Step 1: Run TypeScript validation**
Run:
```bash
pnpm run typecheck
```
Expected: command exits successfully.
- [ ] **Step 2: If typecheck fails because the submodule package is unbuilt, build the submodule**
Run only if Step 1 fails with missing compiled files or missing package entrypoint errors from `vendor/discord.js-selfbot-v13`:
```bash
pnpm --filter discord.js-selfbot-v13 install
npnpm --filter discord.js-selfbot-v13 run build
pnpm run typecheck
```
Expected: submodule package builds successfully and root typecheck passes.
If the package has no `build` script, inspect `vendor/discord.js-selfbot-v13/package.json` scripts and use the package's documented compile script, then rerun `pnpm run typecheck`.
- [ ] **Step 3: Run lint if typecheck passes**
Run:
```bash
pnpm run lint
```
Expected: command exits successfully or reports only pre-existing issues unrelated to `.gitmodules`, `package.json`, `pnpm-workspace.yaml`, or `pnpm-lock.yaml`.
### Task 5: Review git diff and prepare handoff
**Files:**
- Review: `.gitmodules`
- Review: `package.json`
- Review: `pnpm-workspace.yaml`
- Review: `pnpm-lock.yaml`
- Review: `vendor/discord.js-selfbot-v13` gitlink
- [ ] **Step 1: Review changed files**
Run:
```bash
git status --short
git diff -- .gitmodules package.json pnpm-workspace.yaml pnpm-lock.yaml
git diff --submodule
```
Expected: changes are limited to the design spec, plan, submodule metadata/gitlink, pnpm workspace config, root dependency, and lockfile. Existing unrelated `README.md` modifications remain untouched.
- [ ] **Step 2: Summarize validation evidence**
Record these command outcomes in the final response:
```text
pnpm install: PASS or FAIL with error summary
pnpm run typecheck: PASS or FAIL with error summary
pnpm run lint: PASS, FAIL with error summary, or NOT RUN with reason
```
- [ ] **Step 3: Do not commit unless explicitly asked**
No commit command should run unless the user explicitly asks for a commit. If the user asks, use the repository commit workflow and stage only relevant files.
## Self-Review
- Spec coverage: the plan covers submodule creation, remote replacement, workspace config, dependency rewrite, lockfile refresh, and validation.
- Placeholder scan: no TBD/TODO placeholders remain.
- Type consistency: package path, dependency name, and remote URL are consistent across tasks.

View File

@@ -0,0 +1,24 @@
# Selfbot Workspace Submodule Design
## Goal
Replace the npm-resolved `discord.js-selfbot-v13` dependency with a custom repository checked into this project as a git submodule and consumed through pnpm workspace resolution.
## Approach
Use `vendor/discord.js-selfbot-v13` as the submodule path. Initialize it from `https://github.com/aiko-chan-ai/discord.js-selfbot-v13.git`, then change the submodule repository `origin` remote to `ssh://git@43.134.105.109:22222/exceed/discord.js-selfbot.git`.
Configure pnpm workspaces so the root project and the vendored package are both workspace packages. Change the root dependency from the npm version range to `workspace:*`, forcing pnpm to resolve `discord.js-selfbot-v13` from the submodule package.
## Files to Change
- `.gitmodules`: track the new submodule path and URL.
- `pnpm-workspace.yaml`: include the root package and `vendor/discord.js-selfbot-v13`.
- `package.json`: change `discord.js-selfbot-v13` to `workspace:*`.
- `pnpm-lock.yaml`: refresh dependency resolution after the workspace change.
## Validation
After the submodule and dependency changes, run `pnpm install` to update the workspace lockfile and links, then run `pnpm run typecheck` to confirm the app still resolves the selfbot package.
If the vendored package requires a build step before TypeScript can resolve it, use that package's own scripts and rerun root validation.

View File

@@ -27,7 +27,7 @@
"@types/pg": "^8.20.0", "@types/pg": "^8.20.0",
"@vitejs/plugin-react": "^6.0.2", "@vitejs/plugin-react": "^6.0.2",
"better-sqlite3": "^12.10.0", "better-sqlite3": "^12.10.0",
"discord.js-selfbot-v13": "^3.7.1", "discord.js-selfbot-v13": "workspace:*",
"dotenv": "^17.4.2", "dotenv": "^17.4.2",
"drizzle-orm": "^0.45.2", "drizzle-orm": "^0.45.2",
"express": "^5.2.1", "express": "^5.2.1",

4733
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,7 @@
packages:
- .
- vendor/discord.js-selfbot-v13
onlyBuiltDependencies: onlyBuiltDependencies:
- '@discordjs/opus' - '@discordjs/opus'
- better-sqlite3 - better-sqlite3