Files
Echoion/README.md
T
faumaray bdd69f0aad update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:44:48 +03:00

405 lines
18 KiB
Markdown

# Echoion Music Bot
A modern music bot for TeamSpeak 3, featuring YouTube integration, playlist support, and hot-reload capabilities.
## Features
- 🎵 **YouTube Integration** - Play music directly from YouTube URLs or search queries via a native innertube client (fastest path) with yt-dlp as the resolver/fallback
- 🎶 **Two Catalogs** - Search and play from YouTube and Yandex Music (native, full tracks with a Plus token). `!play` searches both; `!pyt`/`!pya` target one. Direct audio URLs / radio streams and other yt-dlp extractors (SoundCloud, Bandcamp, VK, …) also work
- ⚡ **Hedged Resolution** - A slow source is raced by the next candidate after 300ms; first success wins
- 🔁 **Gapless Playback & Crossfade** - The next track's decoder is pre-warmed while the current one plays; optional crossfade (`bot.crossfade`)
- 🔊 **Loudness Normalization** - Optional slow AGC evens out quiet/loud tracks (`features.normalizeLoudness`)
- 📻 **Autoplay / Radio Mode** - When the queue runs dry, `!radio` keeps the music going with related tracks from YouTube or Yandex (`features.autoplay`)
- 💾 **Track Cache** - Downloaded audio is reused across plays and restarts (`advanced.cache*`)
- ⭐ **History & Favorites** - `!history`, `!stats`, `!fav add|list|play` backed by SQLite
- 📋 **Playlist Support** - Queue management with shuffle, repeat, and skip functionality
- 🎧 **High Quality Audio** - 192kHz stereo internal pipeline
- 🔄 **Transactional Updates** - Validate a complete daemon/Core/protocol
release, checkpoint playback, re-exec, reconnect, and restore playback
- ⚙️ **Configurable** - JSON-based configuration system
- 🔊 **TeamSpeak Native** - Uses TeamSpeak's native audio system for best quality
- 🧩 **VoidTeamspeak SDK** - Native protocol support is an independently
consumable modern C++ library rather than an Echoion-internal component
- 🌐 **Public Dashboard** - Current playback plus the complete sanitized
TeamSpeak channel/client tree, with authenticated administration for admins
- 🎬 **VoidWatch Link** - Watch Together is deployed independently from the
`EchoionWatch` repository and linked through `web.watchUrl`
## Building
### Developer requirements
- C++26 compatible compiler with reflections (GCC 16+)
- CMake 4.0+
- Qt6 (only when building the desktop client)
- FFmpeg 5+ (for audio decoding and the modern channel-layout API)
- Boost (system installation preferred; the build vendors one only when absent — mixing a vendored and a system Boost in one process breaks boost.url)
- OpenSSL, libsodium, Opus, FFmpeg, and Boost development packages
### Local build
```bash
cmake -S . -B build -DBUILD_TESTS=ON
cmake --build build -j2
ctest --test-dir build --output-on-failure
```
The supported Linux release is dynamically linked. Static GCC runtime linking
is disabled by default; the release process collects the non-glibc shared
library closure into the bundle and assigns relocatable `$ORIGIN` RUNPATHs.
### Clean containerized Linux release
Docker is the only host requirement for the default release command:
```bash
scripts/release.sh --version 1.2.3
```
When validating coordinated, not-yet-published dependency changes, pass
`--void-source ../VoidLibrary --void-teamspeak-source ../VoidTeamspeak`. The
container builder mounts those source trees read-only and still builds into a
clean directory; normal published releases omit the overrides and use the
version-pinned dependencies.
It builds with a version-pinned GCC 16/FFmpeg 8.0.3 toolchain on Ubuntu 22.04,
runs the C++ and frontend test suites, installs into a clean staging tree,
bundles dynamic dependencies, validates the ELF closure with `readelf`, and
produces both `.tar.zst` and self-extracting `.run` artifacts under `dist/`.
The bot is never initialized or started during release creation. Use `--host`
only on a Debian-family build host with `dpkg-query`, `ldconfig`, and a glibc
ABI no newer than the supported 2.35 floor; incompatible host artifacts are
rejected.
The Linux x86-64 bundle targets glibc 2.35 or newer (Ubuntu 22.04+, Debian 12+,
and current Arch Linux). glibc and the ELF loader come from the target system;
libstdc++, libgcc, FFmpeg, OpenSSL, Opus, and the remaining runtime closure are
carried in `lib/`.
## Configuration
Copy `config.example.json` to your config directory:
- **Linux**: `~/.config/echoion/config.json`
- **Windows**: `%APPDATA%\echoion\config.json`
- **macOS**: `~/Library/Application Support/echoion/config.json`
Edit the configuration file with your server details:
```json
{
"teamspeak": {
"address": "your.server.com",
"port": 9987,
"nickname": "MusicBot",
"serverPassword": ""
}
}
```
## Installation
The `.run` artifact is the recommended installer. It supports system, user,
and portable layouts and never starts the bot unless `--start` is explicitly
supplied.
```bash
# User install; registers a disabled/stopped user service.
./echoion-1.2.3-linux-x86_64.run \
--mode user --non-interactive
# System install and explicit activation.
sudo ./echoion-1.2.3-linux-x86_64.run \
--mode system --register-service system --start --non-interactive
# Fully self-contained portable install, without a service.
./echoion-1.2.3-linux-x86_64.run \
--mode portable --prefix /srv/echoion-portable \
--data-layout self-contained --register-service none --non-interactive
# A portable tree may also register a stable user service.
./echoion-1.2.3-linux-x86_64.run \
--mode portable --prefix "$HOME/echoion-portable" \
--data-layout self-contained --register-service user --non-interactive
```
Portable service registration rejects temporary, world-writable, or
service-inaccessible prefixes, including group/world-writable ancestors. Run
user-service registration as the intended non-root user; root user services are
rejected. Use `--register-service system` with root when a portable tree must
run as a system service. Its complete runtime path must be root-owned and not
writable by the service account. Registration alone performs a daemon reload
and leaves the unit disabled and stopped; add `--start` to enable and start it.
Every installation uses immutable `versions/<version>/` payloads and an atomic
`current` symlink. Configuration is created once and is not overwritten by an
upgrade. The default `self-contained` layout keeps everything needed by the bot
under one prefix:
| Path | Contents |
|---|---|
| `<prefix>/versions/<version>` | immutable executable, Core, shared libraries, web assets, service templates, and manifest |
| `<prefix>/current` | atomic link to the selected immutable version |
| `<prefix>/libexec/updater/<installer-version>` | installer-managed helper plus its private dynamic library closure; never selected through `current` |
| `<prefix>/config` | configuration |
| `<prefix>/state` | identity, database, update journals, and durable state |
| `<prefix>/cache`, `<prefix>/logs`, `<prefix>/incoming` | cache, logs, and operator-supplied local update input |
Select `--data-layout standard` to use conventional external mutable paths:
`$XDG_CONFIG_HOME/echoion`, `$XDG_STATE_HOME/echoion`, and
`$XDG_CACHE_HOME/echoion` for a user service, or `/etc/echoion`,
`/var/lib/echoion`, `/var/cache/echoion`, and `/var/log/echoion` for a system
service. `--config-dir` and `--state-dir` remain available as explicit
overrides.
A self-contained portable install also creates `<prefix>/echoion`; use that
launcher instead of invoking `current/bin/echoiond` directly. It derives the
config and state paths from its own location, so a stopped, service-free tree
can be moved as one folder and run from the new path. If a portable service was
registered, uninstall or re-register its unit before moving the tree because
systemd stores an absolute executable path.
The installer does not execute `echoiond`, `Echoion.ts`, plugins, or the updater.
Its standalone manifest validator verifies every immutable file, symlink, mode,
and SHA-256 before switching `current`. Service registration renders both the
bot unit and a hardened local updater timer, but leaves them disabled and
stopped unless `--start` is supplied.
### Updates
The daemon checks signed feeds and applies independent policies for the runtime
bundle, Core, and managed plugins. Each component can select its own source URL
and channel through the `updates` object in `config.json`; bearer tokens are
read only from named environment variables. HTTPS is required for remote custom
sources. A `file://` source is accepted only below the installation's managed
`incoming` directory.
The privileged updater helper never downloads content and never launches the
bot. For a system service, the timer executes a fixed root-owned helper bundle
below `<prefix>/libexec/updater/`; both its executable and dynamic libraries are
independent of the candidate-controlled `current` link. The helper consumes fixed-schema local
requests, validates a staged runtime into a new immutable version, atomically
changes `current`, and leaves a durable health journal. The new daemon must run
successfully for 30 seconds before its commit request makes the version healthy.
Helper passes inside the durable grace period leave the candidate pending, and
a matching commit request is processed before rollback. After the deadline, an
unconfirmed candidate is restored to the previous version and recorded as
failed. `retainHealthyVersions` keeps the active version plus the configured
number of previously committed healthy versions; interrupted or failed
candidates do not consume that rollback allowance.
To remove an install, run `<prefix>/uninstall.sh`. Configuration and state are
preserved by default. Add `--purge` to remove directories that this installer
created and marked as dedicated Echoion data. Pre-existing override directories
are preserved and must be removed manually.
To preserve the permissions and UID of an existing TeamSpeak client identity,
export it from TeamSpeak's Identity Manager and import it before first start:
```bash
<prefix>/current/bin/echoiond --import-identity identity.ini \
--state-dir <state-directory>
# Choose a non-default destination or replace an existing identity explicitly:
<prefix>/current/bin/echoiond --import-identity identity.ini \
--identity-path /path/to/identity.txt --force
```
The identity file contains a private key. Keep both the TeamSpeak export and
the converted file private.
## Commands
All commands use the configured prefix (default: `!`)
| Command | Description | Example |
|---------|-------------|---------|
| `!play <query>` | Play a song or add to queue | `!play never gonna give you up` |
| `!pause` | Pause playback | `!pause` |
| `!resume` | Resume playback | `!resume` |
| `!stop` | Stop playback | `!stop` |
| `!skip` | Skip current track | `!skip` |
| `!seek <+/-secs>` | Seek within the track | `!seek +30` |
| `!queue` | Show current queue | `!queue` |
| `!clear` | Clear the queue | `!clear` |
| `!shuffle` | Toggle shuffle mode | `!shuffle` |
| `!repeat` | Toggle repeat mode | `!repeat` |
| `!volume <0-100>` | Set volume | `!volume 50` |
| `!nowplaying` | Show current track | `!nowplaying` |
| `!lyrics` | Show lyrics for the current track (alias `ly`) | `!lyrics` |
| `!search <query>` | Search YouTube + Yandex Music | `!search daft punk` |
| `!youtube <query>` | Search YouTube only (alias `yb`, `yt`) | `!yb daft punk` |
| `!yandex <query>` | Search Yandex Music only (alias `ya`) | `!ya грибы` |
| `!soundcloud <query>` | Search SoundCloud only (alias `sc`) | `!sc lofi beats` |
| `!psc <query>` | Play from SoundCloud only (URL or search) | `!psc flume` |
| `!history [n]` | Recently played tracks | `!history 15` |
| `!stats` | Playback statistics | `!stats` |
| `!fav add\|list\|play <n>` | Manage your favorites | `!fav play 2` |
| `!announce <text>` | **Admin:** message all subscribers once | `!announce New update live!` |
## Architecture
The supported runtime consists of four main components:
1. **EchoionApi** - Shared interfaces and types
2. **EchoionCore** - Core music playback logic (hot-reloadable)
3. **VoidTeamspeak** - Reusable native TeamSpeak SDK-compatible client library
4. **EchoionStandalone** - Daemon host and Core API adapter
The legacy TeamSpeak client plugin was removed. TeamSpeak protocol behavior is
implemented once in `VoidTeamspeak`; `EchoionStandalone` is Echoion's only host
adapter.
Watch Together is the independent **VoidWatch** product in the sibling
`EchoionWatch` repository. Echoion has no Watch runtime, WebSocket session,
provider resolver, or extra TeamSpeak identity; it only exposes the configured
external link and a temporary `/watch` redirect.
### Audio Flow
```
query → SourceRouter (innertube → Yandex → direct URL → yt-dlp) → PlaybackEngine
(dual AudioDecoder, gapless handoff) → Core → Standalone interface
→ VoidTeamspeak → TeamSpeak
```
Audio is decoded using FFmpeg at 192kHz stereo and emitted in 20ms chunks to
TeamSpeak's Opus voice protocol through the bot's single playback engine and
visible TeamSpeak identity.
## Development
### Development hot reload
The core library can be hot-reloaded without disconnecting from the server:
1. Build the new core: `cmake --build . --target EchoionCore`
2. Replace `Echoion.ts`; the daemon's host watcher reloads it automatically.
This developer-only watcher is enabled for writable build trees. Installed
release payloads are immutable and use installer upgrades plus service restart
instead of writing temporary libraries beside Core.
Protocol or host changes can use the daemon's opt-in transactional re-exec API.
The process must be started with `ECHOION_RELEASE_MANIFEST` set to the absolute
manifest path before a release is staged:
```bash
export ECHOION_RELEASE_MANIFEST="$HOME/echoion/releases/pending-release.json"
# Start the development daemon with its normal --config/--state-dir arguments.
scripts/stage-release.sh "$HOME/echoion/releases" 1.2.3 \
build-release/runtime-stage
```
The staging command rejects unsafe version names and existing release
directories, verifies the bundle's v2 whole-payload manifest, copies the full
runtime tree, and then renames `pending-release.json` into place. The running
daemon validates every declared file in a child process, checkpoints Core
state, disconnects cleanly, and re-execs the staged binary. The installer does
not enable this development watcher; installed upgrades are performed by the
signed updater. Running a new `.run` artifact against the same prefix remains
the offline/manual upgrade path.
### Adding Commands
To add a new command:
1. Create a new command class in `EchoionCore/src/commands/`
2. Inherit from `CommandBase`
3. Register in `CommandManager::initialize()`
Example:
```cpp
class MyCommand : public CommandBase {
public:
MyCommand() : CommandBase("mycommand", "Description") {}
Api::Result<std::string> execute(uint64_t clientId, const std::vector<std::string>& args) override {
return "Hello, World!";
}
};
```
For independently reloadable native extensions, use the trusted plugin ABI
instead of compiling commands into Core. See [Native plugins](docs/plugins.md).
## Packaging and Distribution
The supported Linux distribution path is `scripts/release.sh`. Each release
contains:
- `echoion-<version>-linux-x86_64.tar.zst` with one top-level directory;
- `echoion-<version>-linux-x86_64.run`, which accepts the installer flags above;
- the external v2 manifest and ELF dependency report;
- `SHA256SUMS` for all published artifacts.
Pass `--update-url` to emit a matching unsigned runtime feed payload, with
optional `--update-channel`, `--update-feed-id`, and `--update-sequence`
overrides:
```bash
scripts/release.sh --version 1.2.3 \
--update-url https://updates.example.org/echoion-1.2.3-linux-x86_64.tar.zst \
--update-channel stable --update-sequence 123
```
Production feeds should be wrapped in an Ed25519 envelope. The generator signs
the exact payload bytes and never places the private key in the release. It
generates runtime feeds by default; use `--component core` for a Core shared
library or `--component plugin --artifact-id ID` for a managed plugin. Core and
plugin feeds do not require a runtime release manifest:
```bash
scripts/generate-update-feed.py \
--artifact dist/echoion-1.2.3-linux-x86_64.tar.zst \
--manifest dist/echoion-1.2.3-linux-x86_64.manifest.json \
--version 1.2.3 \
--url https://updates.example.org/echoion-1.2.3-linux-x86_64.tar.zst \
--sequence 123 \
--output-payload dist/echoion-1.2.3.update-payload.json \
--output-envelope dist/echoion-1.2.3.update.json \
--key-id production-2026 --private-key /secure/echoion-update.pem
```
For example, a plugin feed can be produced independently:
```bash
scripts/generate-update-feed.py \
--component plugin --artifact-id lyrics \
--artifact dist/lyrics-2.0.0.so --version 2.0.0 \
--url https://updates.example.org/plugins/lyrics-2.0.0.so \
--output-payload dist/lyrics-2.0.0.update-payload.json
```
The archive and installer contain the same relocatable dynamic payload. They do
not depend on DEB/RPM metadata or static linking, so one build can be installed
on the supported Ubuntu, Debian, and Arch targets.
When unpacking the `.tar.zst` form directly, preserve the release modes even
under a restrictive shell umask:
```bash
tar --same-permissions --no-same-owner --zstd \
-xf echoion-1.2.3-linux-x86_64.tar.zst
```
### CMake Package Support
The project uses [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake) to export CMake targets:
```cmake
find_package(EchoionCore REQUIRED)
target_link_libraries(myapp PRIVATE Echoion::Core)
```
## License
MIT License - See LICENSE file for details
## Credits
- TeamSpeak Systems GmbH for the TeamSpeak SDK
- FFmpeg team for audio decoding
- Glaze library for JSON handling
- PackageProject.cmake for CMake packaging