diff --git a/README.md b/README.md index 87b1ba8..babb49f 100644 --- a/README.md +++ b/README.md @@ -11,25 +11,68 @@

- Invite to Server Β· - Report a Bug Β· + Invite to Server · + Report a Bug · Request a Feature

License - Fluxer Bot - revoice.js + Node.js + ESM + moonlink.js + MySQL Maintained

--- -## 🎡 About The Project +## Table of Contents -Remix is a free and open-source music bot for Fluxer, built using [fluxerjs](https://github.com/fluxerjs/core) and powered by [revoice.js](https://github.com/ShadowLp174/revoice.js) for seamless, high-quality audio playback. We believe music features shouldn't be locked behind paywallsβ€”**all commands on Remix are 100% free and always will be.** +- [About The Project](#-about-the-project) +- [Features](#-features) +- [Getting Started (Users)](#-getting-started-users) +- [Commands](#-commands) +- [Self-Hosting](#-self-hosting-the-bot) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Database Setup](#-database-setup) + - [Dashboard Setup (Optional)](#-dashboard-setup-optional) + - [Configuration Reference](#-configuration-reference) +- [Project Architecture](#-project-architecture) +- [Localization](#-localization) +- [Scripts](#-npm-scripts) +- [Credits](#-credits--license) -## πŸš€ Getting Started +--- + +## About The Project + +Remix is a free and open-source music bot for [Fluxer](https://fluxer.app), built with [`@fluxerjs/core`](https://github.com/fluxerjs/core) and powered by [`moonlink.js`](https://github.com/ShadowLp174/moonlink.js) for seamless, high-quality audio streaming. It uses `@fluxerjs/voice` for native voice integration alongside the Moonlink Lavalink proxy. + +We believe music features shouldn't be locked behind paywalls β€” **all commands on Remix are 100% free and always will be.** + +--- + +## Features + +- **High-quality audio playback** via moonlink.js (Lavalink proxy) and `@fluxerjs/voice` +- **Multi-source search** β€” YouTube, Spotify, SoundCloud, and direct URL support +- **24/7 mode** β€” keep the bot in a voice channel permanently, with auto-recovery on restart +- **Session recovery** β€” active players and queues survive bot restarts and crash recovery +- **Interactive emoji player** β€” reaction-based control panel with play, pause, skip, volume, shuffle, and more +- **Lyrics** β€” fetch song lyrics via the Genius API +- **Radio stations** β€” built-in support for custom radio streams with keyword-based search +- **Server settings** β€” per-guild configuration for prefix, volume, locale, 24/7 channels, and more +- **Web dashboard** β€” optional browser-based control panel with Redis-backed sessions and Fluxer OAuth2 login +- **Multi-language support** β€” available in English, Arabic, German, Kurdish (Sorani), and Brazilian Portuguese +- **Configurable logging** β€” granular control over which log categories appear in the console +- **Graceful shutdown** β€” saves active session state on SIGINT/SIGTERM for seamless reboot recovery +- **Module system** β€” pluggable module architecture for extending bot functionality + +--- + +## Getting Started (Users) Want to use Remix in your server right away? @@ -39,43 +82,79 @@ Want to use Remix in your server right away? --- -## πŸ“œ Commands +## Commands -Below is a complete list of Remix's commands. The default prefix is `%`. +Below is the complete list of Remix's commands. The default prefix is `%`. -| Command | Description | Usage Example | Aliases | +### Music + +| Command | Description | Usage | Aliases | | :--- | :--- | :--- | :--- | -| `play` | Play a song from a URL/query, or a playlist. | `%play Never Gonna Give You Up` | `p` | -| `playnext` | Play a song/playlist, adding it to the *top* of the queue. | `%playnext 'query: text'` | `pn` | -| `pause` | Pause the current playback. | `%pause` | | -| `resume` | Resume the paused playback. | `%resume` | | -| `skip` | Skip the currently playing song. | `%skip` | | -| `list` | View the upcoming queue for your voice channel. | `%list` | `queue` | -| `np` | See the name and URL of the currently playing song. | `%np` | `current`, `nowplaying` | -| `loop` | Toggle looping for the current song or the whole queue. | `%loop queue` | | -| `shuffle` | Re-orders the queue randomly. | `%shuffle` | | -| `remove` | Remove a specific song from the queue by its index number. | `%remove 3` | | -| `clear` | Remove all songs from the queue. | `%clear` | `c` | -| `volume` | Change the volume of the bot. | `%volume 50` | `v` | -| `join` | Make the bot join a specific voice channel. | `%join 123456789` | | -| `leave` | Make the bot leave your current voice channel. | `%leave` | `l` | -| `player` | Create an interactive emoji player control panel. | `%player` | | -| `search` | Display search results for a given query to choose from. | `%search 'query'` | | -| `settings`| Change or view bot settings for the current server. | `%settings set` | `s` | -| `stats` | Display bot statistics, like uptime and ping. | `%stats` | `info` | -| `thumbnail`| Get the thumbnail image of the currently playing song. | `%thumbnail` | `thumb` | -| `test` | A developer testing command. | `%test 1` | | +| `play` | Play a song from a URL, search query, or playlist | `%play Never Gonna Give You Up` | `p` | +| `playnext` | Add a song/playlist to the *top* of the queue | `%playnext query: text` | `pn` | +| `pause` | Pause the current playback | `%pause` | | +| `resume` | Resume the paused playback | `%resume` | | +| `skip` | Skip the currently playing song | `%skip` | | +| `np` | Show the currently playing song | `%np` | `current`, `nowplaying` | +| `list` | View the upcoming queue | `%list` | `queue` | +| `loop` | Toggle loop mode (song or queue) | `%loop queue` | | +| `shuffle` | Randomize the queue order | `%shuffle` | | +| `remove` | Remove a specific song by its queue index | `%remove 3` | | +| `clear` | Clear the entire queue | `%clear` | `c` | +| `volume` | Change the playback volume (1–200) | `%volume 50` | `v` | +| `volumedefault` | Set the default volume for the server | `%volumedefault 80` | | +| `search` | Search for a track and pick from results | `%search query` | | +| `lyrics` | Fetch lyrics for the current or specified song | `%lyrics` | | +| `thumbnail` | Get the thumbnail of the current track | `%thumbnail` | `thumb` | +| `radio` | Play a built-in or custom radio station | `%radio` | | + +### Voice Channel + +| Command | Description | Usage | Aliases | +| :--- | :--- | :--- | :--- | +| `join` | Make the bot join a specific voice channel | `%join 123456789` | | +| `leave` | Make the bot leave the current voice channel | `%leave` | `l` | +| `forceleave` | Force the bot to leave any channel (owner only) | `%forceleave` | | + +### Player & UI + +| Command | Description | Usage | Aliases | +| :--- | :--- | :--- | :--- | +| `player` | Create an interactive emoji control panel | `%player` | | + +### Settings & Server + +| Command | Description | Usage | Aliases | +| :--- | :--- | :--- | :--- | +| `settings` | View or change server settings | `%settings set` | `s` | +| `filter` | Manage audio filters (bass, speed, nightcore, etc.) | `%filter bass 50` | | + +### Utility + +| Command | Description | Usage | Aliases | +| :--- | :--- | :--- | :--- | +| `stats` | Display bot stats (uptime, ping, node info) | `%stats` | `info` | +| `invite` | Get the bot invite link | `%invite` | | +| `support` | Get an invite to the support server | `%support` | | +| `reload` | Reload commands or settings at runtime (owner) | `%reload` | | +| `servers` | List servers the bot is in (owner) | `%servers` | | +| `eval` | Evaluate JavaScript (owner only) | `%eval 1+1` | | +| `debug` | Debugging utilities (owner only) | `%debug` | | +| `test` | Developer testing command | `%test 1` | | --- -## πŸ› οΈ Self-Hosting The Bot +## Self-Hosting The Bot -If you prefer to host Remix yourself, please note: **You must make it clear that your bot is an instance of Remix.** Please change the bot's name and give credit in the bot's profile (e.g., *"Powered by [Remix](https://github.com/remix-bot/fluxer)"*). +If you prefer to host Remix yourself, please note: **You must make it clear that your bot is an instance of Remix.** Change the bot's name and give credit in the bot's profile (e.g., *"Powered by [Remix](https://github.com/remix-bot/fluxer)"*). ### Prerequisites -- Node.js installed -- A MySQL Database -- A [NodeLink](https://github.com/PerformanC/NodeLink) instance + +- **Node.js** >= 22.0.0 (required by moonlink.js v5) +- **MySQL** 8.0+ with JSON column support +- **[NodeLink](https://github.com/PerformanC/NodeLink)** instance (Lavalink proxy for audio) +- **FFmpeg** (installed automatically via `ffmpeg-static`) +- **Redis** (optional, required for the web dashboard) ### Installation @@ -91,52 +170,237 @@ If you prefer to host Remix yourself, please note: **You must make it clear that ``` 3. **Configure the bot:** - - Rename `config.example.json` to `config.json`. - - Fill out the missing values (Bot Token, DB credentials, etc.). - - *Note: You can generate Spotify credentials [here](https://developer.spotify.com/).* - - Configure your NodeLink instance inside the `config.json` file: - ```json - "nodelink": { - "host": "localhost", - "port": 3000, - "password": "youshallnotpass" - } - ``` + ```bash + cp config_example.json config.json + ``` + Open `config.json` and fill in the required values: + - `token` β€” your Fluxer bot token + - `mysql` β€” your MySQL connection details (host, port, user, password, database) + - `prefix` β€” the command prefix (default: `%`) + - `nodelink` β€” your NodeLink instance connection details + - `spotify` β€” (optional) Spotify API credentials for Spotify track support + - `geniusToken` β€” (optional) Genius API token for lyrics support + - `owners` β€” array of Fluxer user IDs with owner-only command access -4. **Setup the Database:** *(See instructions below)* +4. **Set up the database:** *(See [Database Setup](#-database-setup) below)* 5. **Start the bot:** ```bash - node index.mjs + npm start ``` -### πŸ—„οΈ Database Setup + For development with inspector: + ```bash + npm run dev + ``` -Remix requires a MySQL database to function properly. +### Database Setup -1. Create a dedicated database for Remix to prevent data collisions with other apps. -2. Enter your MySQL connection details into `config.json`. -3. Run the following SQL query to create the necessary tables: +Remix requires a MySQL database to store per-guild settings. +1. Create a dedicated database for Remix: + ```sql + CREATE DATABASE remix; + ``` + +2. Enter your MySQL connection details into `config.json`: + ```json + "mysql": { + "host": "localhost", + "port": 3306, + "user": "remix", + "password": "your-password", + "database": "remix" + } + ``` + +3. Create the required table: ```sql CREATE TABLE `settings` ( `id` varchar(70) NOT NULL, `data` json NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; ``` -*(Note: If you used the legacy settings system and want to migrate your data, please check the README inside the `settings` folder).* + +4. *(Optional)* If migrating from the legacy settings system, run: + ```bash + npm run migrate + ``` + +### Dashboard Setup (Optional) + +Remix includes a web dashboard for controlling the bot through a browser interface. + +1. Enable the dashboard in `config.json`: + ```json + "dashboard": { + "enabled": true, + "redis": { "url": "redis://localhost:6379" }, + "fluxer": { + "id": "your-fluxer-oauth2-app-id", + "secret": "your-fluxer-oauth2-client-secret", + "redirectUri": "https://your-backend.com/auth/fluxer" + } + } + ``` + +2. Create a Fluxer OAuth2 application at [https://fluxer.app/developers/applications](https://fluxer.app/developers/applications). + +3. Create the additional database tables required by the dashboard: + ```sql + CREATE TABLE `ksiTokens` ( + `user` varchar(26) NOT NULL, + `id` varchar(50) NOT NULL, + `token` varchar(70) NOT NULL, + `createdAt` datetime NOT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + + CREATE TABLE `logins` ( + `user` text NOT NULL, + `id` varchar(50) NOT NULL, + `token` varchar(70) NOT NULL, + `verified` tinyint(1) NOT NULL, + `createdAt` datetime NOT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + ``` + +4. For HTTPS support, configure SSL in `config.json`: + ```json + "ssl": { + "private": "/etc/letsencrypt/live/your.domain/privkey.pem", + "cert": "/etc/letsencrypt/live/your.domain/fullchain.pem", + "useSSL": true, + "httpPort": 80 + } + ``` + +### Configuration Reference + +Key configuration options in `config.json`: + +| Option | Type | Default | Description | +| :--- | :--- | :--- | :--- | +| `token` | string | β€” | **Required.** Fluxer bot token | +| `prefix` | string | `%` | Default command prefix | +| `embedColor` | string | `0xe9196c` | Hex color for embed messages | +| `owners` | string[] | `[]` | User IDs with owner privileges | +| `playerAFKTimeout` | number | `60000` | Inactivity timeout in ms before bot leaves | +| `webPort` | number | `80` | Port for the web dashboard | +| `helpCatalog` | bool | `true` | Enable categorized help command | +| `helpPagination` | bool | `true` | Enable paginated help output | +| `mysql` | object | β€” | **Required.** MySQL connection settings | +| `nodelink` | object | β€” | NodeLink connection (host, port, password) | +| `spotify` | object | β€” | Spotify API credentials | +| `geniusToken` | string | β€” | Genius API token for lyrics | +| `dashboard` | object | β€” | Dashboard, Redis, and OAuth2 settings | +| `logging` | object | β€” | Per-category log toggle (see config example) | +| `timers` | object | β€” | Timing values for inactivity, recovery, etc. | +| `cache` | object | β€” | Guild and member cache limits | +| `radio` | array | `[]` | Custom radio station definitions | +| `ssl` | object | β€” | SSL certificate paths and HTTPS toggle | --- -## πŸ’¬ Contact & Support +## Project Architecture -If you have any questions, need help setting up, or just want to hang out with other Remix users, join our official Fluxer server: - -πŸ‘‰ **[Join the Remix Support Server](https://fluxer.gg/Remix)** +``` +fluxer/ +β”œβ”€β”€ index.mjs # Entry point β€” Remix class, boot sequence, error handling +β”œβ”€β”€ config_example.json # Configuration template +β”œβ”€β”€ package.json +β”œβ”€β”€ commands/ # Command modules (one file per command) +β”‚ β”œβ”€β”€ play.mjs # Play a track or playlist +β”‚ β”œβ”€β”€ player.mjs # Interactive emoji control panel +β”‚ β”œβ”€β”€ settings.mjs # Per-guild settings management +β”‚ β”œβ”€β”€ lyrics.mjs # Genius lyrics fetcher +β”‚ β”œβ”€β”€ filter.mjs # Audio filter controls +β”‚ β”œβ”€β”€ radio.mjs # Radio station management +β”‚ └── ... # All other commands +β”œβ”€β”€ src/ +β”‚ β”œβ”€β”€ CommandHandler.mjs # Command loader, prefix manager, registry +β”‚ β”œβ”€β”€ MessageHandler.mjs # Message parsing, embed builder, pagination, help +β”‚ β”œβ”€β”€ PlayerManager.mjs # Spawns and manages per-channel Player instances +β”‚ β”œβ”€β”€ Player.mjs # Core player β€” queue, playback, filters, events +β”‚ β”œβ”€β”€ MoonlinkManager.mjs # Moonlink.js (Lavalink) node session manager +β”‚ β”œβ”€β”€ Settings.mjs # RemoteSettingsManager + ServerSettings export +β”‚ β”œβ”€β”€ GatewayHandler.mjs # Raw WS events, voice-state tracking, presence rotation +β”‚ β”œβ”€β”€ RecoveryManager.mjs # Session persistence, crash recovery, 24/7 auto-join +β”‚ β”œβ”€β”€ Utils.mjs # Shared utilities +β”‚ β”œβ”€β”€ worker.mjs # Background task worker +β”‚ β”œβ”€β”€ probe.mjs # FFprobe wrapper for audio stream info +β”‚ β”œβ”€β”€ constants/ +β”‚ β”‚ β”œβ”€β”€ Logger.mjs # Structured logger with per-category control +β”‚ β”‚ β”œβ”€β”€ Locale.mjs # i18n translation engine +β”‚ β”‚ β”œβ”€β”€ providers.mjs # Audio source provider definitions +β”‚ β”‚ └── audio/ +β”‚ β”‚ β”œβ”€β”€ StreamMerger.mjs # Audio stream merging utilities +β”‚ β”‚ └── Tuna.mjs # Audio filter/effect processing +β”‚ └── dashboard/ +β”‚ β”œβ”€β”€ Dashboard.mjs # Web dashboard server (Express + WebSocket) +β”‚ └── RedisHandler.mjs # Redis session and pub/sub handler +β”œβ”€β”€ settings/ +β”‚ β”œβ”€β”€ Settings.mjs # Abstract SettingsManager base class +β”‚ β”œβ”€β”€ migrate.mjs # Legacy-to-remote settings migration script +β”‚ └── runnables.mjs # Runnable task definitions +└── storage/ + β”œβ”€β”€ defaults.json # Default per-guild settings template + β”œβ”€β”€ modules.json # Plugin module registry + β”œβ”€β”€ stats.json # Runtime statistics + └── locales/bot/ # Translation files + β”œβ”€β”€ en.json + β”œβ”€β”€ ar-SA.json + β”œβ”€β”€ de-DE.json + β”œβ”€β”€ ckb.json + └── pt-BR.json +``` --- +## Localization + +Remix supports multiple languages out of the box. The locale system loads JSON translation files from `storage/locales/bot/` and serves the appropriate language based on each guild's `locale` setting. + +Currently supported languages: + +| Code | Language | +| :--- | :--- | +| `en` | English (default) | +| `ar-SA` | Arabic | +| `de-DE` | German | +| `ckb` | Kurdish (Sorani) | +| `pt-BR` | Brazilian Portuguese | + +To add a new language, place a JSON file in `storage/locales/bot/` following the same key structure as `en.json`, then set the locale per guild with `%settings set locale `. + +--- + +## npm Scripts + +| Script | Command | Description | +| :--- | :--- | :--- | +| `npm start` | `node index.mjs` | Start the bot | +| `npm run dev` | `node --inspect index.mjs --trace-warnings` | Start with Node.js inspector | +| `npm run commands` | `node index.mjs usage` | Generate command usage documentation | +| `npm run defaultsSync` | `node index.mjs sreload` | Sync default settings to all guilds | +| `npm run migrate` | `node settings/migrate.mjs` | Run the legacy settings migration | + +--- + +## Credits & License + +**Design & Development:** +- [ShadowLp174](https://github.com/ShadowLp174) β€” Lead developer, audio engine, moonlink.js +- NoLogicAlan β€” Dashboard design +- ophx β€” Dashboard design +- Fantic β€” Contributions + +**Powered by:** +- [`@fluxerjs/core`](https://github.com/fluxerjs/core) β€” Fluxer API client +- [`@fluxerjs/voice`](https://github.com/fluxerjs/voice) β€” Native voice integration +- [`moonlink.js`](https://github.com/ShadowLp174/moonlink.js) β€” Lavalink proxy +- [NodeLink](https://github.com/PerformanC/NodeLink) β€” Audio node manager +

© 2026 Remix. Code licensed under the MIT License.
The Remix name, logo, and branding are proprietary and may not be reused. -

\ No newline at end of file +

diff --git a/config_example.json b/config_example.json index a4086c6..95950a7 100644 --- a/config_example.json +++ b/config_example.json @@ -1,4 +1,5 @@ { + "Comment": "Fluxer music bot configuration. IMPORTANT: Node.js >= 22.0.0 is required (moonlink.js v5 dependency). Run 'node --version' to verify.", "token": "your bot token", "fluxer.js": { "Comment": "Configuration data for @fluxerjs/core Client options. See: https://github.com/fluxerjs/core", @@ -114,6 +115,8 @@ "playerSessionTimeout": 300000, "intentionalLeaveTTL": 10000, "recoveryStaggerMs": 2000, - "recoveryConcurrency": 2 + "recoveryConcurrency": 2, + "maxTransientRetries": 5, + "retryBaseDelay": 15000 } -} \ No newline at end of file +} diff --git a/index.mjs b/index.mjs index eb6f7e2..fb46f9f 100644 --- a/index.mjs +++ b/index.mjs @@ -220,6 +220,8 @@ export class Remix { player: this.playerContext, dashboard: this.dashboard, locale: this.locale, + spawnPlayer: this._spawnPlayer, + timers: this.T, }); this.players.observedVoiceUsers = this.observedVoiceUsers; @@ -613,3 +615,10 @@ const saveAndExit = async () => { process.once("SIGINT", saveAndExit); process.once("SIGTERM", saveAndExit); process.once("SIGUSR2", saveAndExit); + +// ── SIGPIPE handler ────────────────────────────────────────────────────────── +// On some systems, writing to a broken pipe (e.g. Redis connection) raises +// SIGPIPE which defaults to terminating the process. Ignoring it lets the +// error surface through the normal exception/rejection handlers above so +// recovery state is saved before exit. +process.on("SIGPIPE", () => {}); diff --git a/package-lock.json b/package-lock.json index efc5e22..e1b5fd5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "fluxer", + "name": "fluxer-main", "lockfileVersion": 3, "requires": true, "packages": { @@ -8,16 +8,19 @@ "@fluxerjs/core": "^1.3.0", "@fluxerjs/voice": "^1.3.0", "@livekit/rtc-node": "^0.13.24", - "express": "^4.18.2", + "bcryptjs": "^2.4.3", "ffmpeg-static": "^5.1.0", "ffprobe-static": "^3.1.0", "follow-redirects": "^1.15.2", "genius-lyrics": "^4.4.3", "moonlink.js": "^5.2.0", - "mysql": "^2.18.1", - "revoice.js": "^0.2.1694", - "util": "^0.12.5", + "mysql2": "^3.9.0", + "redis": "^5.12.1", + "revoice.js": "^0.2.1696", "ws": "^8.19.0" + }, + "engines": { + "node": ">=22.0.0" } }, "node_modules/@babel/code-frame": { @@ -839,6 +842,78 @@ "version": "0.4.0", "license": "MIT" }, + "node_modules/@redis/bloom": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-5.12.1.tgz", + "integrity": "sha512-PUUfv+ms7jgPSBVoo/DN4AkPHj4D5TZSd6SbJX7egzBplkYUcKmHRE8RKia7UtZ8bSQbLguLvxVO+asKtQfZWA==", + "license": "MIT", + "engines": { + "node": ">= 18.19.0" + }, + "peerDependencies": { + "@redis/client": "^5.12.1" + } + }, + "node_modules/@redis/client": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-5.12.1.tgz", + "integrity": "sha512-7aPGWeqA3uFm43o19umzdl16CEjK/JQGtSXVPevplTaOU3VJA/rseBC1QvYUz9lLDIMBimc4SW/zrW4S89BaCA==", + "license": "MIT", + "dependencies": { + "cluster-key-slot": "1.1.2" + }, + "engines": { + "node": ">= 18.19.0" + }, + "peerDependencies": { + "@node-rs/xxhash": "^1.1.0", + "@opentelemetry/api": ">=1 <2" + }, + "peerDependenciesMeta": { + "@node-rs/xxhash": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + } + } + }, + "node_modules/@redis/json": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-5.12.1.tgz", + "integrity": "sha512-eOze75esLve4vfqDel7aMX08CNaiLLQS2fV8mpRN9NxPe1rVR4vQyYiW/OgtGUysF6QOr9ANhfxABKNOJfXdKg==", + "license": "MIT", + "engines": { + "node": ">= 18.19.0" + }, + "peerDependencies": { + "@redis/client": "^5.12.1" + } + }, + "node_modules/@redis/search": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-5.12.1.tgz", + "integrity": "sha512-ItlxbxC9cKI6IU1TLWoczwJCRb6TdmkEpWv05UrPawqaAnWGRu3rcIqsc5vN483T2fSociuyV1UkWIL5I4//2w==", + "license": "MIT", + "engines": { + "node": ">= 18.19.0" + }, + "peerDependencies": { + "@redis/client": "^5.12.1" + } + }, + "node_modules/@redis/time-series": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-5.12.1.tgz", + "integrity": "sha512-c6JL6E3EcZJuNqKFz+KM+l9l5mpcQiKvTwgA3blt5glWJ8hjDk0yeHN3beE/MpqYIQ8UEX44ItQzgkE/gCBELQ==", + "license": "MIT", + "engines": { + "node": ">= 18.19.0" + }, + "peerDependencies": { + "@redis/client": "^5.12.1" + } + }, "node_modules/@shinyoshiaki/ebml-builder": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/@shinyoshiaki/ebml-builder/-/ebml-builder-0.0.1.tgz", @@ -942,17 +1017,6 @@ "simple-yenc": "^1.0.4" } }, - "node_modules/accepts": { - "version": "1.3.8", - "license": "MIT", - "dependencies": { - "mime-types": "~2.1.34", - "negotiator": "0.6.3" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/ace-builds": { "version": "1.43.6", "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.43.6.tgz", @@ -1031,10 +1095,6 @@ "license": "Python-2.0", "optional": true }, - "node_modules/array-flatten": { - "version": "1.1.1", - "license": "MIT" - }, "node_modules/asap": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", @@ -1079,19 +1139,6 @@ "node": ">=8.0.0" } }, - "node_modules/available-typed-arrays": { - "version": "1.0.7", - "license": "MIT", - "dependencies": { - "possible-typed-array-names": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/awaitqueue": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/awaitqueue/-/awaitqueue-2.4.0.tgz", @@ -1101,6 +1148,15 @@ "node": ">=8.0.0" } }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/axios": { "version": "0.26.1", "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", @@ -1159,6 +1215,12 @@ "node": ">=6.0.0" } }, + "node_modules/bcryptjs": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", + "integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==", + "license": "MIT" + }, "node_modules/better-docs": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/better-docs/-/better-docs-2.7.3.tgz", @@ -1191,13 +1253,6 @@ "node": ">=0.6" } }, - "node_modules/bignumber.js": { - "version": "9.0.0", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/binary-data": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/binary-data/-/binary-data-0.6.0.tgz", @@ -1217,28 +1272,6 @@ "integrity": "sha512-fGTi3gxV/23FTYdAoUtLYp6qySe2KE3teyZitipKNRuVYcBkoP/bB3guXN/XVKUe9mxCHXnc9C4ocyz8OmgN0g==", "license": "MIT" }, - "node_modules/body-parser": { - "version": "1.20.4", - "license": "MIT", - "dependencies": { - "bytes": "~3.1.2", - "content-type": "~1.0.5", - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "~1.2.0", - "http-errors": "~2.0.1", - "iconv-lite": "~0.4.24", - "on-finished": "~2.4.1", - "qs": "~6.14.0", - "raw-body": "~2.5.3", - "type-is": "~1.6.18", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, "node_modules/boolbase": { "version": "1.0.0", "license": "ISC" @@ -1339,13 +1372,6 @@ "version": "1.1.2", "license": "MIT" }, - "node_modules/bytes": { - "version": "3.1.2", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/c8": { "version": "7.14.0", "resolved": "https://registry.npmjs.org/c8/-/c8-7.14.0.tgz", @@ -1372,22 +1398,6 @@ "node": ">=10.12.0" } }, - "node_modules/call-bind": { - "version": "1.0.8", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.0", - "es-define-property": "^1.0.0", - "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", "license": "MIT", @@ -1510,6 +1520,15 @@ "wrap-ansi": "^7.0.0" } }, + "node_modules/cluster-key-slot": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", + "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1569,16 +1588,6 @@ "babylon": "^6.18.0" } }, - "node_modules/content-disposition": { - "version": "0.5.4", - "license": "MIT", - "dependencies": { - "safe-buffer": "5.2.1" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/content-type": { "version": "1.0.5", "license": "MIT", @@ -1592,17 +1601,6 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "license": "MIT" }, - "node_modules/cookie": { - "version": "0.7.2", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie-signature": { - "version": "1.0.6", - "license": "MIT" - }, "node_modules/core-js": { "version": "2.6.12", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", @@ -1713,34 +1711,13 @@ "node": ">=0.10.0" } }, - "node_modules/define-data-property": { - "version": "1.1.4", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "gopd": "^1.0.1" - }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/depd": { - "version": "2.0.0", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/destroy": { - "version": "1.2.0", - "license": "MIT", - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" + "node": ">=0.10" } }, "node_modules/diff-match-patch": { @@ -1826,10 +1803,6 @@ "node": ">= 0.4" } }, - "node_modules/ee-first": { - "version": "1.1.1", - "license": "MIT" - }, "node_modules/electron-to-chromium": { "version": "1.5.328", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.328.tgz", @@ -1857,13 +1830,6 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "license": "MIT" }, - "node_modules/encodeurl": { - "version": "2.0.0", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/end-of-stream": { "version": "1.4.5", "license": "MIT", @@ -1921,10 +1887,6 @@ "node": ">=6" } }, - "node_modules/escape-html": { - "version": "1.0.3", - "license": "MIT" - }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -1961,13 +1923,6 @@ "node": ">=0.10.0" } }, - "node_modules/etag": { - "version": "1.8.1", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/event-target-shim": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-6.0.2.tgz", @@ -1989,50 +1944,6 @@ "node": ">=0.8.x" } }, - "node_modules/express": { - "version": "4.22.1", - "license": "MIT", - "dependencies": { - "accepts": "~1.3.8", - "array-flatten": "1.1.1", - "body-parser": "~1.20.3", - "content-disposition": "~0.5.4", - "content-type": "~1.0.4", - "cookie": "~0.7.1", - "cookie-signature": "~1.0.6", - "debug": "2.6.9", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.3.1", - "fresh": "~0.5.2", - "http-errors": "~2.0.0", - "merge-descriptors": "1.0.3", - "methods": "~1.1.2", - "on-finished": "~2.4.1", - "parseurl": "~1.3.3", - "path-to-regexp": "~0.1.12", - "proxy-addr": "~2.0.7", - "qs": "~6.14.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.2.1", - "send": "~0.19.0", - "serve-static": "~1.16.2", - "setprototypeof": "1.2.0", - "statuses": "~2.0.1", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.10.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, "node_modules/fake-mediastreamtrack": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/fake-mediastreamtrack/-/fake-mediastreamtrack-1.2.0.tgz", @@ -2127,22 +2038,6 @@ "url": "https://github.com/sindresorhus/file-type?sponsor=1" } }, - "node_modules/finalhandler": { - "version": "1.3.2", - "license": "MIT", - "dependencies": { - "debug": "2.6.9", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "on-finished": "~2.4.1", - "parseurl": "~1.3.3", - "statuses": "~2.0.2", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -2191,19 +2086,6 @@ } } }, - "node_modules/for-each": { - "version": "0.3.5", - "license": "MIT", - "dependencies": { - "is-callable": "^1.2.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/foreground-child": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", @@ -2217,20 +2099,6 @@ "node": ">=8.0.0" } }, - "node_modules/forwarded": { - "version": "0.2.0", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fresh": { - "version": "0.5.2", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2253,13 +2121,6 @@ "is-property": "^1.0.2" } }, - "node_modules/generator-function": { - "version": "2.0.1", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, "node_modules/genius-lyrics": { "version": "4.4.7", "license": "MIT", @@ -2415,16 +2276,6 @@ "node": ">=8" } }, - "node_modules/has-property-descriptors": { - "version": "1.0.2", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-symbols": { "version": "1.1.0", "license": "MIT", @@ -2502,24 +2353,6 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "license": "MIT" }, - "node_modules/http-errors": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "depd": "~2.0.0", - "inherits": "~2.0.4", - "setprototypeof": "~1.2.0", - "statuses": "~2.0.2", - "toidentifier": "~1.0.1" - }, - "engines": { - "node": ">= 0.8" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, "node_modules/http-response-object": { "version": "3.0.2", "license": "MIT", @@ -2527,16 +2360,6 @@ "@types/node": "^10.0.3" } }, - "node_modules/iconv-lite": { - "version": "0.4.24", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -2584,43 +2407,12 @@ "integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ==", "license": "MIT" }, - "node_modules/ipaddr.js": { - "version": "1.9.1", - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/is-arguments": { - "version": "1.2.0", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "has-tostringtag": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "license": "MIT" }, - "node_modules/is-callable": { - "version": "1.2.7", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-core-module": { "version": "2.16.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", @@ -2655,23 +2447,6 @@ "node": ">=8" } }, - "node_modules/is-generator-function": { - "version": "1.1.2", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.4", - "generator-function": "^2.0.0", - "get-proto": "^1.0.1", - "has-tostringtag": "^1.0.2", - "safe-regex-test": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -2712,23 +2487,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-typed-array": { - "version": "1.1.15", - "license": "MIT", - "dependencies": { - "which-typed-array": "^1.1.16" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/isarray": { - "version": "1.0.0", - "license": "MIT" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -2953,6 +2711,12 @@ "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "license": "MIT" }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, "node_modules/longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -2983,6 +2747,21 @@ "yallist": "^3.0.2" } }, + "node_modules/lru.min": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.4.tgz", + "integrity": "sha512-DqC6n3QQ77zdFpCMASA1a3Jlb64Hv2N2DciFGkO/4L9+q/IpIAuRlKOvCXabtRW6cQf8usbmM6BE/TOPysCdIA==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/make-dir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", @@ -3028,54 +2807,6 @@ "node": ">= 0.4" } }, - "node_modules/media-typer": { - "version": "0.3.0", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/merge-descriptors": { - "version": "1.0.3", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/methods": { - "version": "1.1.2", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime": { - "version": "1.6.0", - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/min-indent": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", @@ -3242,41 +2973,54 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, - "node_modules/mysql": { - "version": "2.18.1", + "node_modules/mysql2": { + "version": "3.22.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.22.3.tgz", + "integrity": "sha512-uWWxvZSRvRhtBdh2CdcuK83YcOfPdmEeEYB069bAmPnV93QApDGVPuvCQOLjlh7tYHEWdgQPrn6kosDxHBVLkA==", "license": "MIT", "dependencies": { - "bignumber.js": "9.0.0", - "readable-stream": "2.3.7", - "safe-buffer": "5.1.2", - "sqlstring": "2.3.1" + "aws-ssl-profiles": "^1.1.2", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.7.2", + "long": "^5.3.2", + "lru.min": "^1.1.4", + "named-placeholders": "^1.1.6", + "sql-escaper": "^1.3.3" }, "engines": { - "node": ">= 0.6" + "node": ">= 8.0" + }, + "peerDependencies": { + "@types/node": ">= 8" } }, - "node_modules/mysql/node_modules/readable-stream": { - "version": "2.3.7", + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", "license": "MIT", "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, - "node_modules/mysql/node_modules/safe-buffer": { - "version": "5.1.2", - "license": "MIT" - }, - "node_modules/mysql/node_modules/string_decoder": { - "version": "1.1.1", + "node_modules/named-placeholders": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.6.tgz", + "integrity": "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w==", "license": "MIT", "dependencies": { - "safe-buffer": "~5.1.0" + "lru.min": "^1.1.0" + }, + "engines": { + "node": ">=8.0.0" } }, "node_modules/nano-time": { @@ -3288,13 +3032,6 @@ "big-integer": "^1.6.16" } }, - "node_modules/negotiator": { - "version": "0.6.3", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", @@ -3389,16 +3126,6 @@ "node": ">=0.10.0" } }, - "node_modules/object-inspect": { - "version": "1.13.4", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/on-exit-leak-free": { "version": "2.1.2", "license": "MIT", @@ -3406,16 +3133,6 @@ "node": ">=14.0.0" } }, - "node_modules/on-finished": { - "version": "2.4.1", - "license": "MIT", - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/once": { "version": "1.4.0", "license": "ISC", @@ -3520,13 +3237,6 @@ "node_modules/parse-cache-control": { "version": "1.0.1" }, - "node_modules/parseurl": { - "version": "1.3.3", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3560,10 +3270,6 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "license": "MIT" }, - "node_modules/path-to-regexp": { - "version": "0.1.12", - "license": "MIT" - }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -3630,13 +3336,6 @@ "version": "7.1.0", "license": "MIT" }, - "node_modules/possible-typed-array-names": { - "version": "1.1.0", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, "node_modules/prettier": { "version": "2.8.8", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", @@ -3686,10 +3385,6 @@ "node": ">= 0.6" } }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "license": "MIT" - }, "node_modules/process-warning": { "version": "5.0.0", "funding": [ @@ -3731,17 +3426,6 @@ "react-is": "^16.13.1" } }, - "node_modules/proxy-addr": { - "version": "2.0.7", - "license": "MIT", - "dependencies": { - "forwarded": "0.2.0", - "ipaddr.js": "1.9.1" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -3900,19 +3584,6 @@ "node": ">=16.0.0" } }, - "node_modules/qs": { - "version": "6.14.2", - "license": "BSD-3-Clause", - "dependencies": { - "side-channel": "^1.1.0" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -3948,26 +3619,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/range-parser": { - "version": "1.2.1", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/raw-body": { - "version": "2.5.3", - "license": "MIT", - "dependencies": { - "bytes": "~3.1.2", - "http-errors": "~2.0.1", - "iconv-lite": "~0.4.24", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/react": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", @@ -4098,6 +3749,22 @@ "node": ">=4" } }, + "node_modules/redis": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/redis/-/redis-5.12.1.tgz", + "integrity": "sha512-LDsoVvb/CpoV9EN3FXvgvSHNJWuCIzl9MiO3ppOevuGLpSGJhwfQjpEwfFJcQvNSddHADDdZaWx0HnmMxRXG7g==", + "license": "MIT", + "dependencies": { + "@redis/bloom": "5.12.1", + "@redis/client": "5.12.1", + "@redis/json": "5.12.1", + "@redis/search": "5.12.1", + "@redis/time-series": "5.12.1" + }, + "engines": { + "node": ">= 18.19.0" + } + }, "node_modules/reflect-metadata": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", @@ -4149,9 +3816,9 @@ } }, "node_modules/revoice.js": { - "version": "0.2.1694", - "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.2.1694.tgz", - "integrity": "sha512-m/Hs37Jvm4UuVBOq11XjeGewqI1X/vsFSyIGtBD5B/11P178WPLFfNror/hdS1NhS4YpSNjpr0O5Z7dECXmc/Q==", + "version": "0.2.1696", + "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.2.1696.tgz", + "integrity": "sha512-wE4FIV6D4JIkul0p9DGfXL6iBMrj3jhhzT6ytqzmMoUnIUP9Cu5AmEQOwcIW/L8zBqr3yS1aNtkNz79xkggWQg==", "license": "MIT", "dependencies": { "@livekit/rtc-node": "^0.13.20", @@ -4230,21 +3897,6 @@ ], "license": "MIT" }, - "node_modules/safe-regex-test": { - "version": "1.1.0", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "is-regex": "^1.2.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/safe-stable-stringify": { "version": "2.5.0", "license": "MIT", @@ -4299,64 +3951,6 @@ "semver": "bin/semver.js" } }, - "node_modules/send": { - "version": "0.19.2", - "license": "MIT", - "dependencies": { - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "fresh": "~0.5.2", - "http-errors": "~2.0.1", - "mime": "1.6.0", - "ms": "2.1.3", - "on-finished": "~2.4.1", - "range-parser": "~1.2.1", - "statuses": "~2.0.2" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/send/node_modules/ms": { - "version": "2.1.3", - "license": "MIT" - }, - "node_modules/serve-static": { - "version": "1.16.3", - "license": "MIT", - "dependencies": { - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", - "send": "~0.19.1" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/set-function-length": { - "version": "1.2.2", - "license": "MIT", - "dependencies": { - "define-data-property": "^1.1.4", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "license": "ISC" - }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -4378,70 +3972,6 @@ "node": ">=8" } }, - "node_modules/side-channel": { - "version": "1.1.0", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.3", - "side-channel-list": "^1.0.0", - "side-channel-map": "^1.0.1", - "side-channel-weakmap": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-list": { - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-map": { - "version": "1.0.1", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-weakmap": { - "version": "1.0.2", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3", - "side-channel-map": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -4479,18 +4009,19 @@ "node": ">= 10.x" } }, - "node_modules/sqlstring": { - "version": "2.3.1", + "node_modules/sql-escaper": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/sql-escaper/-/sql-escaper-1.3.3.tgz", + "integrity": "sha512-BsTCV265VpTp8tm1wyIm1xqQCS+Q9NHx2Sr+WcnUrgLrQ6yiDIvHYJV5gHxsj1lMBy2zm5twLaZao8Jd+S8JJw==", "license": "MIT", "engines": { - "node": ">= 0.6" - } - }, - "node_modules/statuses": { - "version": "2.0.2", - "license": "MIT", - "engines": { - "node": ">= 0.8" + "bun": ">=1.0.0", + "deno": ">=2.0.0", + "node": ">=12.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/mysqljs/sql-escaper?sponsor=1" } }, "node_modules/stream-parser": { @@ -4644,13 +4175,6 @@ "node": ">=0.10.0" } }, - "node_modules/toidentifier": { - "version": "1.0.1", - "license": "MIT", - "engines": { - "node": ">=0.6" - } - }, "node_modules/token-stream": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz", @@ -4729,17 +4253,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/type-is": { - "version": "1.6.18", - "license": "MIT", - "dependencies": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/typedarray": { "version": "0.0.6", "license": "MIT" @@ -4881,13 +4394,6 @@ "node": ">=14.0" } }, - "node_modules/unpipe": { - "version": "1.0.0", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/update-browserslist-db": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.2.3.tgz", @@ -4918,28 +4424,10 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/util": { - "version": "0.12.5", - "license": "MIT", - "dependencies": { - "inherits": "^2.0.3", - "is-arguments": "^1.0.4", - "is-generator-function": "^1.0.7", - "is-typed-array": "^1.1.3", - "which-typed-array": "^1.1.2" - } - }, "node_modules/util-deprecate": { "version": "1.0.2", "license": "MIT" }, - "node_modules/utils-merge": { - "version": "1.0.1", - "license": "MIT", - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/uuid": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", @@ -4967,13 +4455,6 @@ "node": ">=10.12.0" } }, - "node_modules/vary": { - "version": "1.1.2", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/void-elements": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", @@ -5188,25 +4669,6 @@ "which": "bin/which" } }, - "node_modules/which-typed-array": { - "version": "1.1.20", - "license": "MIT", - "dependencies": { - "available-typed-arrays": "^1.0.7", - "call-bind": "^1.0.8", - "call-bound": "^1.0.4", - "for-each": "^0.3.5", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-tostringtag": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/win-guid": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/win-guid/-/win-guid-0.2.1.tgz", diff --git a/src/GatewayHandler.mjs b/src/GatewayHandler.mjs index 97a46f8..b8e59ea 100644 --- a/src/GatewayHandler.mjs +++ b/src/GatewayHandler.mjs @@ -548,14 +548,9 @@ export class GatewayHandler { // Bot moved channels β€” auto-save 247 setting if (channelId && guildId && oldChannelId && oldChannelId !== channelId) { try { - if (multiVoiceGuild) { - logger.voice247( - `[247] Skipping bot move gateway auto-save ${oldChannelId} β†’ ${channelId} ` + - `(guild ${guildId} has ${activeGuildPlayers.length} active players)` - ); - return; - } - + // For multi-voice guilds, only re-key if we can unambiguously match + // the player by oldChannelId. Previously this skipped entirely for + // multi-voice guilds, which broke recovery for all channels. const cleanId = String(channelId).replace(/\D/g, ""); const cleanOld = String(oldChannelId).replace(/\D/g, ""); @@ -573,9 +568,16 @@ export class GatewayHandler { let rekeyed = false; if (existingPlayer && cleanId !== cleanOld) { if (guildIsAmbiguous) { + // Multi-voice guild: can't safely re-key the playerMap (another player + // might already use cleanId), but still update the moved player's + // home channel so 24/7 recovery targets the right channel. + existingPlayer._channelId = cleanId; + existingPlayer._home247Channel = cleanId; + if (targetGuildId) existingPlayer._guildId = targetGuildId; + rekeyed = false; // keep false β€” don't touch playerMap keys logger.voice247( - `[247] Skipping bot move auto-rekey ${cleanOld} β†’ ${cleanId} ` + - `(guild ${guildId} has ${guildPlayers.length} active players)` + `[247] Updated player channel ${cleanOld} β†’ ${cleanId} ` + + `(guild ${guildId} has ${guildPlayers.length} active players, skipped re-key)` ); } else if (playerGuildId && targetGuildId && playerGuildId !== targetGuildId) { logger.warn( @@ -595,7 +597,7 @@ export class GatewayHandler { const set = remix.settingsMgr.getServer(guildId); const raw = set.get("stay_247"); - if (rekeyed && raw && raw !== "none") { + if ((rekeyed || existingPlayer) && raw && raw !== "none") { const channels = Array.isArray(raw) ? new Set(raw.map(id => String(id).replace(/\D/g, "")).filter(Boolean)) : new Set([String(raw).replace(/\D/g, "")]); @@ -603,6 +605,7 @@ export class GatewayHandler { channels.delete(cleanOld); channels.add(cleanId); set.set("stay_247", [...channels]); + logger.voice247(`[247] Updated stay_247: ${cleanOld} β†’ ${cleanId}`); } } } catch (e) { @@ -613,14 +616,6 @@ export class GatewayHandler { // Bot disconnected unexpectedly β€” rejoin if 247 active if (!channelId && oldChannelId && guildId) { try { - if (multiVoiceGuild) { - logger.voice247( - `[247] Skipping bot disconnect gateway recovery for ${oldChannelId} ` + - `(guild ${guildId} has ${activeGuildPlayers.length} active players)` - ); - return; - } - const cleanOld = String(oldChannelId).replace(/\D/g, ""); if (remix.intentionalLeaves.has(cleanOld)) { logger.voice247(`[247] Skipping rejoin for ${cleanOld} β€” intentional leave.`); @@ -634,6 +629,8 @@ export class GatewayHandler { if (channels.has(cleanOld)) { const mode = set.get("stay_247_mode") ?? "auto"; if (mode === "on" || mode === "auto") { + // For multi-voice guilds, match the specific player by channel ID + // instead of skipping recovery entirely (was: if multiVoiceGuild return) const player = remix.players.playerMap.get(cleanOld); if (player && !player.leaving) { logger.voice247("[247] Fluxer gateway disconnected us. Forcing player recovery..."); diff --git a/src/Player.mjs b/src/Player.mjs index c327180..92d16d3 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -504,7 +504,8 @@ export default class Player extends EventEmitter { this.emit("autoleave"); return; } - const backoffMs = Math.min(2000 * this._recoveryAttempts, 30_000); + // Exponential backoff: 2s, 4s, 8s, 16s, 32s (was linear: 2s, 4s, 6s, 8s, 10s) + const backoffMs = Math.min(2000 * Math.pow(2, this._recoveryAttempts - 1), 30_000); logger.mediaplayer(`[Player] Recovery attempt ${this._recoveryAttempts}/${MAX_RECOVERY} for ${this._guildId} (backoff ${backoffMs}ms)`); await Utils.sleep(backoffMs); @@ -514,6 +515,28 @@ export default class Player extends EventEmitter { return; } + // Wait for _isJoining to clear β€” if another operation (e.g. spawnPlayer or + // a concurrent _recoverConnection from a different event path) is currently + // calling join(), we must not race against it. Poll every 500ms for up to + // 15s, then give up on this attempt and schedule a retry. + let waited = 0; + while (this._isJoining && waited < 15_000) { + logger.mediaplayer(`[Player] Waiting for _isJoining to clear before recovery attempt...`); + await Utils.sleep(500); + waited += 500; + } + if (this._isJoining) { + logger.warn("[Player] _isJoining still busy after 15s β€” deferring recovery attempt."); + this._isRecovering = false; + this._recoveryPending = false; + // Schedule a retry via setTimeout so we don't stack synchronous calls + this._recoveryTimer = setTimeout(() => { + this._recoveryTimer = null; + this._recoverConnection().catch(() => {}); + }, 2000); + return; + } + logger.mediaplayer(`[Player] Attempting to recover voice connection for ${this._guildId}`); try { @@ -1114,57 +1137,100 @@ export default class Player extends EventEmitter { const room = connection.room; if (room) { - logger.mediaplayer("[Player] Waiting for LiveKit room to connect..."); + logger.mediaplayer(`[Player] Room obtained (state: ${room.state}), settling...`); + // ── connectionStateChanged is unreliable on this LiveKit build ─────── + // The native lk-rtc layer connects and logs "connected to room", but + // the JS wrapper often NEVER fires "connectionStateChanged" with + // "connected" and room.state does not reflect the live state. + // Waiting for that event causes a guaranteed 15 s timeout. + // + // Strategy: listen for the event as a best-effort fast path (resolves + // instantly if it works), but also poll room.state every 500 ms. + // If NEITHER detects "connected" within a short window, check whether + // the room is in an obviously-dead state. If not, assume connected + // and let _ensureMediaPlayer (publishToRoom) be the real gate β€” it + // will throw if the room is genuinely unusable. let connected = false; + let settled = false; - if (room.state === "connected" || room.state === 1) { - logger.mediaplayer("[Player] Room already connected"); - connected = true; - } else { - try { - await new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - room.off("connectionStateChanged", onStateChange); - reject(new Error("LiveKit connection timeout")); - }, 15_000); + try { + await new Promise((resolve, reject) => { + const cleanup = () => { + clearTimeout(timeout); + clearInterval(poll); + try { room.off("connectionStateChanged", onStateChange); } catch (_) {} + }; - const onStateChange = (state) => { - logger.mediaplayer(`[Player] LiveKit state changed: ${state}`); - // only resolve on "connected" β€” never on "connecting". - // "connecting" is a transient state and the engine may collapse - // before publishToRoom can run, causing the "engine is closed" error. - if (state === "connected" || state === 1) { - clearTimeout(timeout); - room.off("connectionStateChanged", onStateChange); - connected = true; - resolve(); - } else if (state === "disconnected" || state === 0 || state === "failed") { - clearTimeout(timeout); - room.off("connectionStateChanged", onStateChange); - reject(new Error(`LiveKit failed: ${state}`)); - } - }; + const timeout = setTimeout(() => { + // Timeout β€” not necessarily a failure. The room may be connected + // at the native level with no JS event/state propagation. + logger.mediaplayer("[Player] connectionStateChanged not detected, checking state..."); + cleanup(); + const s = room.state; + if (s === "disconnected" || s === 0 || s === "failed") { + reject(new Error(`LiveKit failed: ${s}`)); + } else { + // Indeterminate state (undefined, "connecting", etc.) + // β€” optimistically proceed; MediaPlayer will validate. + connected = true; + settled = true; + resolve(); + } + }, 3_000); // 3 s instead of 15 s β€” avoid blocking recovery - room.on("connectionStateChanged", onStateChange); - }); - } catch (err) { - logger.error("[Player] LiveKit connection failed:", err.message); - throw err; - } + const onStateChange = (state) => { + if (settled) return; + logger.mediaplayer(`[Player] LiveKit state changed: ${state}`); + if (state === "connected" || state === 1) { + connected = true; + cleanup(); + resolve(); + } else if (state === "disconnected" || state === 0 || state === "failed") { + cleanup(); + reject(new Error(`LiveKit failed: ${state}`)); + } + }; + + room.on("connectionStateChanged", onStateChange); + + // Poll room.state every 500 ms as a fallback for builds where + // the event never fires but the getter eventually updates. + const poll = setInterval(() => { + if (settled) return; + const s = room.state; + if (s === "connected" || s === 1) { + connected = true; + cleanup(); + resolve(); + } else if (s === "disconnected" || s === 0 || s === "failed") { + cleanup(); + reject(new Error(`LiveKit failed: ${s}`)); + } + }, 500); + + // Immediate check after listener is registered. + const currentState = room.state; + if (currentState === "connected" || currentState === 1) { + connected = true; + cleanup(); + logger.mediaplayer("[Player] Room already connected (immediate check)"); + resolve(); + } else if (currentState === "disconnected" || currentState === 0 || currentState === "failed") { + cleanup(); + reject(new Error(`LiveKit failed: ${currentState}`)); + } + }); + } catch (err) { + logger.error("[Player] LiveKit connection failed:", err.message); + throw err; } - await Utils.sleep(300); - - // re-check liveness using the `connected` flag set by the event - // handler rather than re-reading room.state β€” on some LiveKit builds the - // state getter returns undefined outside of the event callback even when - // the room is healthy (the property is not persistently stored). - if (!connected) { + if (connected) { + logger.mediaplayer("[Player] Room ready, proceeding to MediaPlayer"); + } else { throw new Error("LiveKit room did not reach connected state"); } - - logger.mediaplayer("[Player] Proceeding to create MediaPlayer (room confirmed alive)"); } else { // connection.room is null β€” this happens when joinVoiceChannel returns // a stale/recycled connection object before the LiveKit room is assigned, diff --git a/src/PlayerManager.mjs b/src/PlayerManager.mjs index 2d580c1..d8727d2 100644 --- a/src/PlayerManager.mjs +++ b/src/PlayerManager.mjs @@ -86,6 +86,8 @@ export class PlayerManager { this.playerConfig = config.player; this.dashboard = config.dashboard ?? null; this.locale = config.locale ?? null; + this.spawnPlayer = config.spawnPlayer ?? null; // RecoveryManager.spawnPlayer β€” for 24/7 rejoin on autoleave + this.timers = config.timers ?? {}; } /** @@ -596,25 +598,48 @@ export class PlayerManager { const homeChannelId = cleanId(player._home247Channel) || activeChannelId; const ch = player.textChannel; const guildId = cleanId(player._guildId ?? ch?.guildId ?? ch?.guild?.id ?? getMessageGuildId({ channel: ch })); - const is247 = (() => { - try { - const raw = this.settings.getServer(guildId)?.get("stay_247"); - return raw && raw !== "none"; - } catch (_) { return false; } + + // Check 24/7 settings for this channel + const raw247 = (() => { + try { return this.settings.getServer(guildId)?.get("stay_247"); } catch (_) { return null; } })(); - const prefix = (() => { - try { - return this.settings.getServer(guildId)?.get("prefix") ?? "%"; - } catch (_) { return "%"; } + const mode247 = (() => { + try { return this.settings.getServer(guildId)?.get("stay_247_mode") ?? "off"; } catch (_) { return "off"; } })(); - const desc = is247 - ? this.locale?.translate(guildId, "responses.join.autoLeaveInactive", { channel: `<#${activeChannelId}>` }) ?? `Left channel <#${activeChannelId}> because of inactivity.` - : this.locale?.translate(guildId, "responses.join.autoLeaveInactive247", { channel: `<#${activeChannelId}>`, prefix }) ?? `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``; - ch?.send(mkEmbed(desc)); + const isIn247List = (() => { + if (!raw247 || raw247 === "none") return false; + const channels = Array.isArray(raw247) + ? raw247.map(id => String(id).replace(/\D/g, "")).filter(Boolean) + : [String(raw247).replace(/\D/g, "")].filter(Boolean); + return channels.includes(homeChannelId) || channels.includes(activeChannelId); + })(); + + // Remove player from map and destroy this.playerMap.delete(activeChannelId); if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId); if (homeChannelId !== activeChannelId) this.playerMap.delete(homeChannelId); player.destroy(); + + if (isIn247List && (mode247 === "on" || mode247 === "auto")) { + // 24/7 is active β€” rejoin after a short delay (same as RecoveryManager.spawnPlayer autoleave) + const delay = this.timers?.rejoin247Delay ?? 3000; + if (this.spawnPlayer) { + logger.recovery(`[AutoLeave] 24/7 rejoin scheduled for ${homeChannelId} in ${delay}ms`); + setTimeout(() => { + this.spawnPlayer(guildId, homeChannelId, 0, null, "initplayer-autoleave").catch(e => + logger.warn("[AutoLeave] 24/7 rejoin failed for", homeChannelId, e.message) + ); + }, delay); + } + } else { + // Not 24/7 β€” send inactivity message + const prefix = (() => { + try { return this.settings.getServer(guildId)?.get("prefix") ?? "%"; } catch (_) { return "%"; } + })(); + const desc = this.locale?.translate(guildId, "responses.join.autoLeaveInactive247", { channel: `<#${activeChannelId}>`, prefix }) + ?? `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``; + ch?.send(mkEmbed(desc)); + } }); player.on("leave", () => {}); diff --git a/src/RecoveryManager.mjs b/src/RecoveryManager.mjs index 2fbf6f2..fb786ae 100644 --- a/src/RecoveryManager.mjs +++ b/src/RecoveryManager.mjs @@ -30,10 +30,14 @@ export class RecoveryManager { // ── Internal state ──────────────────────────────────────────────────────── /** @type {Set} Per-channel spawn mutex */ this.pendingSpawns = new Set(); - /** @type {Map} Scheduled delayed spawns */ + /** @type {Map} Scheduled delayed spawns */ this.scheduledSpawns = new Map(); /** @type {string} Path to the recovery JSON file */ this.recoveryPath = "./storage/recovery.json"; + /** @type {number} Maximum transient retry attempts per channel before giving up */ + this.maxTransientRetries = remix.config.timers?.maxTransientRetries ?? 5; + /** @type {number} Base delay multiplier for exponential backoff (ms) */ + this.retryBaseDelay = remix.config.timers?.retryBaseDelay ?? 15_000; // ── Ready flags ─────────────────────────────────────────────────────────── this.botReady = false; @@ -92,7 +96,9 @@ export class RecoveryManager { preferredVolume: player.preferredVolume ?? 1, savedAt: Date.now(), }); - } catch (_) {} + } catch (e) { + logger.warn(`[Recovery] Failed to serialize session for channel ${channelKey}:`, e?.message ?? e); + } } return sessions; @@ -125,7 +131,9 @@ export class RecoveryManager { guildId, channelId, home247ChannelId: this.normalizeChannelId(session?.home247ChannelId) || channelId, - queue: Array.isArray(session?.queue) ? session.queue : [], + queue: Array.isArray(session?.queue) + ? session.queue.filter(t => t && (t.encoded || t.uri || t.url)) + : [], loopQueue: !!session?.loopQueue, loopSong: !!session?.loopSong, }); @@ -134,27 +142,90 @@ export class RecoveryManager { return [...deduped.values()]; } + /** + * Clean up all state for a guild the bot is no longer a member of. + * Mirrors the GUILD_DELETE handler in GatewayHandler so that servers + * kicked while offline are fully purged on the next boot. + * + * @param {string} guildId + * @param {string} [reason="bot no longer in guild"] + */ + cleanStaleGuild(guildId, reason = "bot no longer in guild") { + const { remix } = this; + const cleanId = String(guildId).replace(/\D/g, ""); + logger.recovery(`[Recovery] Cleaning stale guild ${cleanId} (${reason}).`); + + // Destroy any active players for this guild + for (const [channelId, player] of remix.players.playerMap) { + if (!player._guildId || String(player._guildId).replace(/\D/g, "") === cleanId) { + remix.players.playerMap.delete(channelId); + try { player.leave().catch(() => {}); } catch (_) {} + try { player.destroy(); } catch (_) {} + } + } + + // Cancel any scheduled spawns for this guild + for (const [channelId, entry] of this.scheduledSpawns) { + if (String(entry.guildId).replace(/\D/g, "") === cleanId) { + clearTimeout(entry.timer); + this.scheduledSpawns.delete(channelId); + } + } + + // Clean voice-user observations + for (const [userId, info] of [...remix.observedVoiceUsers]) { + if (String(info.guildId).replace(/\D/g, "") === cleanId) remix.observedVoiceUsers.delete(userId); + } + for (const [userId, info] of [...remix.observedVoiceBots]) { + if (String(info.guildId).replace(/\D/g, "") === cleanId) remix.observedVoiceBots.delete(userId); + } + + // Remove from settings cache + remix.settingsMgr.removeServer(cleanId); + remix._announcementChannelCache?.delete?.(cleanId); + } + // ── Spawn scheduling ───────────────────────────────────────────────────────── /** * Schedule a delayed player spawn. Cancels any previous scheduled spawn for * the same channel. + * + * @param {string} guildId + * @param {string} channelId + * @param {number} [delayMs=0] + * @param {Object|null} [recoveryData=null] + * @param {string} [reason="spawn"] + * @param {number} [retryCount=0] Current retry attempt number (0 = first try). */ - scheduleSpawn(guildId, channelId, delayMs = 0, recoveryData = null, reason = "spawn") { + scheduleSpawn(guildId, channelId, delayMs = 0, recoveryData = null, reason = "spawn", retryCount = 0) { const cleanChannelId = this.normalizeChannelId(channelId); if (!cleanChannelId) return; const existing = this.scheduledSpawns.get(cleanChannelId); if (existing) clearTimeout(existing.timer); + // Capture retryCount in the closure BEFORE the entry is deleted, + // so spawnPlayer receives the correct count for exponential backoff. + const capturedRetryCount = retryCount; const timer = setTimeout(() => { this.scheduledSpawns.delete(cleanChannelId); - this.spawnPlayer(guildId, cleanChannelId, 0, recoveryData).catch(e => { + this.spawnPlayer(guildId, cleanChannelId, 0, recoveryData, capturedRetryCount).catch(e => { logger.warn(`[PlayerSpawn] Scheduled ${reason} failed for ${cleanChannelId}:`, e?.message ?? e); }); }, Math.max(0, delayMs)); - this.scheduledSpawns.set(cleanChannelId, { timer, guildId, recoveryData, reason }); + this.scheduledSpawns.set(cleanChannelId, { timer, guildId, recoveryData, reason, retryCount }); + } + + /** + * Calculate the exponential backoff delay for a given retry attempt. + * Delay doubles each attempt: base, base*2, base*4, base*8, … + * Capped at 5 minutes to avoid excessive waits. + */ + getRetryDelay(retryCount) { + const delay = this.retryBaseDelay * Math.pow(2, retryCount); + return Math.min(delay, 300_000); // cap at 5 minutes } // ── Player spawning ────────────────────────────────────────────────────────── @@ -163,7 +234,7 @@ export class RecoveryManager { * Create a new Player, join the target voice channel, and optionally restore * recovery state. */ - async spawnPlayer(guildId, channelId, delayMs = 0, recoveryData = null) { + async spawnPlayer(guildId, channelId, delayMs = 0, recoveryData = null, retryCount = 0) { const { remix } = this; if (delayMs > 0) await new Promise(r => setTimeout(r, delayMs)); @@ -171,12 +242,16 @@ export class RecoveryManager { const cleanChannelId = this.normalizeChannelId(channelId); if (!cleanChannelId) return; + // Clean up any previously scheduled spawn for this channel. const scheduled = this.scheduledSpawns.get(cleanChannelId); if (scheduled) { clearTimeout(scheduled.timer); this.scheduledSpawns.delete(cleanChannelId); } + // Use the passed-in retryCount (from scheduleSpawn's closure) rather + // than reading from the now-deleted scheduledSpawns entry. + // Only enforce 24/7 check if we are NOT recovering from a reboot if (!recoveryData) { const set = remix.settingsMgr.getServer(guildId); @@ -292,12 +367,15 @@ export class RecoveryManager { ch?.send({ embeds: [{ description: String(m), color: getGlobalColor() }] }).catch(() => {}); }); - remix.players.playerMap.set(cleanChannelId, p); - // ── Join channel ─────────────────────────────────────────────────────── + // NOTE: playerMap.set happens AFTER join() succeeds so that other code + // (alone-check, voice state handlers) never sees a non-connected player. try { await p.join(cleanChannelId); + // Only add to playerMap once the join is confirmed successful. + remix.players.playerMap.set(cleanChannelId, p); + // Record the intended 247 home channel for this player. p._home247Channel = cleanChannelId; @@ -337,24 +415,55 @@ export class RecoveryManager { try { p.destroy(); } catch (_) {} logger.warn("[PlayerSpawn] Failed to join channel", cleanChannelId, "guild", guildId, e.message); - // Retry if the failure is a transient LiveKit race + // ── Guild membership check for 401 errors ─────────────────────────── + // If the bot was kicked while offline (or between retries), the 401 will + // keep repeating. Verify the bot is still in the guild β€” if not, clean + // up all state and skip retries entirely. + if (e.message?.includes("401 Unauthorized") && !remix.client.guilds.has(guildId)) { + logger.warn( + `[PlayerSpawn] 401 on guild ${guildId} β€” bot no longer in server. ` + + `Cleaning up and skipping retries.` + ); + this.cleanStaleGuild(guildId, "401 and bot not in guild"); + return; + } + + // Retry if the failure is a transient LiveKit race (with max retries + backoff) const isTransient = e.message?.includes("engine is closed") || e.message?.includes("MediaPlayer after retry") || e.message?.includes("LiveKit connection timeout") || e.message?.includes("LiveKit failed") || - e.message?.includes("No room available"); - const shouldRetry = isTransient && !recoveryData?.queue?.length - ? (() => { - try { - const raw = remix.settingsMgr.getServer(guildId)?.get("stay_247"); - return raw && raw !== "none"; - } catch (_) { return false; } - })() - : isTransient && !!recoveryData; + e.message?.includes("No room available") || + e.message?.includes("401 Unauthorized") || + e.message?.includes("signal failure"); + + // Use the retryCount passed into spawnPlayer from scheduleSpawn's closure. + const prevRetryCount = retryCount; + + const shouldRetry = isTransient && prevRetryCount < this.maxTransientRetries + && ( + !recoveryData?.queue?.length + ? (() => { + try { + const raw = remix.settingsMgr.getServer(guildId)?.get("stay_247"); + return raw && raw !== "none"; + } catch (_) { return false; } + })() + : !!recoveryData + ); if (shouldRetry) { - const retryDelay = this.T.rejoin247Delay * 3; - logger.warn(`[PlayerSpawn] Transient join failure β€” retrying in ${retryDelay}ms`); - this.scheduleSpawn(guildId, cleanChannelId, retryDelay, recoveryData ?? null, "transient-join-retry"); + const nextRetry = prevRetryCount + 1; + const retryDelay = this.getRetryDelay(prevRetryCount); + logger.warn( + `[PlayerSpawn] Transient join failure β€” retry ${nextRetry}/${this.maxTransientRetries} ` + + `in ${retryDelay}ms (channel=${cleanChannelId})` + ); + this.scheduleSpawn(guildId, cleanChannelId, retryDelay, recoveryData ?? null, "transient-join-retry", nextRetry); + } else if (isTransient) { + logger.error( + `[PlayerSpawn] Giving up on channel ${cleanChannelId} after ${prevRetryCount} retry(es). ` + + `Last error: ${e.message}` + ); } } @@ -439,16 +548,18 @@ export class RecoveryManager { const joinList = []; // 1. Recover standard reboot sessions + let recoveryFileExisted = false; if (fs.existsSync(this.recoveryPath)) { logger.recovery("[Recovery] Found previous session data, restoring..."); + recoveryFileExisted = true; let data = null; try { data = JSON.parse(fs.readFileSync(this.recoveryPath, "utf8")); - fs.unlinkSync(this.recoveryPath); } catch (e) { logger.error("[Recovery] Failed to read/parse recovery file:", e); - try { fs.unlinkSync(this.recoveryPath); } catch (_) {} } + // NOTE: File is deleted AFTER all spawns complete (see below). + // This prevents data loss if the process crashes mid-recovery. const sessions = this.normalizeRecoverySessions(data); for (const session of sessions) { joinList.push({ @@ -479,16 +590,29 @@ export class RecoveryManager { } } - if (joinList.length === 0) return; + // ── Filter out guilds the bot is no longer a member of ──────────────── + const filteredList = []; + for (const item of joinList) { + if (!remix.client.guilds.has(item.guildId)) { + logger.recovery( + `[Recovery] Skipping guild ${item.guildId} channel ${item.channelId} β€” bot is no longer in the server.` + ); + this.cleanStaleGuild(item.guildId); + } else { + filteredList.push(item); + } + } + + if (filteredList.length === 0) return; const startTime = Date.now(); logger.recovery( - `[Recovery] Joining ${joinList.length} session(s) ` + + `[Recovery] Joining ${filteredList.length} session(s) ` + `(concurrency: ${this.T.recoveryConcurrency}, stagger: ${this.T.recoveryStaggerMs}ms)...` ); const errors = await this.runWithConcurrency( - joinList, + filteredList, this.T.recoveryConcurrency, this.T.recoveryStaggerMs, async (item) => { @@ -502,15 +626,21 @@ export class RecoveryManager { ); const elapsed = ((Date.now() - startTime) / 1000).toFixed(1); - const ok = joinList.length - errors.length; + const ok = filteredList.length - errors.length; if (errors.length > 0) { for (const err of errors) { logger.error("[Recovery] Failed to join channel", err.channelId, "guild", err.guildId, err.error); } } logger.recovery( - `[Recovery] Processed ${joinList.length} session(s) in ${elapsed}s ` + + `[Recovery] Processed ${filteredList.length} session(s) in ${elapsed}s ` + `(${ok} ok, ${errors.length} failed).` ); + + // Delete recovery file AFTER all spawns have been attempted (success or fail). + // If the process crashes mid-recovery, the file still exists for next boot. + if (recoveryFileExisted) { + try { fs.unlinkSync(this.recoveryPath); } catch (_) {} + } } }