This commit is contained in:
NoLogicAlan committed 2026-09-16 02:15:56 +03:00
1 parent 8a8925653c
commit 3a72e46775
12 files changed
+77 -33

No files matched your search

+1 -1
View File
@@ -499,7 +499,7 @@ const BotVoiceMixin = {
await player.playNext();
if (current && pos > 0) {
if (current && pos > 0 && dur > 0) {
await new Promise((r) => setTimeout(r, 800)); // let the bridge settle
try { await player.seekToPosition(pos); } catch (_) {}
}
-18
View File
@@ -4,24 +4,6 @@
* survive bot reboots/crashes. One row per (bot_id, guild_id) holding a JSON
* snapshot of the player: voice channel, text channel, queue tracks, current
* track, resume position, volume and loop modes.
*
* WHY MySQL AND NOT REDIS/FILES:
* - The bot already owns a MySQL pool (RemoteSettingsManager) that is flushed
* on graceful shutdown; snapshots ride the same healthy connection and are
* durable across restarts of ANY component.
* - The project's Redis handle (dashboard RedisHandler) is a pub/sub cache
* whose client is closed on shutdown — it is the wrong place for state
* that must outlive a reboot.
* - Local JSON files were audited and removed from the hot path years ago
* (storage/stats.json has no writer left); adding file writes would make
* the bot slower, not faster.
*
* Write pattern:
* - Full snapshot: debounced 3s per player, triggered by queue/playback
* events (see Player.mjs).
* - Position heartbeat: single cheap UPDATE of the position_ms column every
* 15s while a track is playing, so resume-after-crash lands within ~15s
* of where the song actually was.
*/
import { logger } from "../core/Logger.mjs";
+6
View File
@@ -79,6 +79,12 @@ const DisplayMixin = {
? `${vid.title} - ${vid.url}`
: `[${vid.title}](${vid.url})`;
}
if (vid.isLive || vid.type === "livestream") {
const link = vid.url || "";
return code
? `${vid.title} (LIVE) - ${link}`
: `🔴 [${vid.title}](${link}) — **LIVE**`;
}
const elapsed = this.getCurrentElapsedDuration();
const total = this.getDuration(vid.duration);
const link = vid.spotifyUrl || vid.url || "";
+27 -3
View File
@@ -37,9 +37,7 @@ const PlaybackMixin = {
this._lastPlayedTrack = this.queue.getCurrent() ?? songData;
this.queue.current = null;
this.emit("stopplay");
if (!this._is247Enabled()) {
this._startInactivityTimer();
}
this._scheduleRadioReconnect(songData);
return;
}
@@ -173,6 +171,7 @@ const PlaybackMixin = {
this._pausedAt = null;
this._queueEndedSent = false;
this._consecutiveErrors = 0;
this._radioReconnects = 0;
if (songData.type !== "radio" || !this._radioAnnounced) {
this.announceSong(songData);
@@ -362,6 +361,31 @@ const PlaybackMixin = {
this._skipping = false;
},
/**
* @private Re-arm the same radio station after its stream drops. Live
* streams end on network hiccups, not on purpose — retry twice (3s apart)
* before giving the channel back to the inactivity timer. A user-queued
* song or an intentional leave during the wait window cancels it.
* @this {import('./Player.mjs').Player}
* @param {object} track - The radio track object that ended.
*/
_scheduleRadioReconnect(track) {
const maxRetries = 2;
if ((this._radioReconnects ?? 0) >= maxRetries || !track?.url) {
this._radioReconnects = 0;
if (!this._is247Enabled()) this._startInactivityTimer();
return;
}
this._radioReconnects = (this._radioReconnects ?? 0) + 1;
logger.player(`[Player] Radio stream ended — reconnecting (${this._radioReconnects}/${maxRetries}) in 3s: ${track.title}`);
setTimeout(() => {
if (this._destroyed || this.leaving || !this._voiceConn) return;
if (this.queue.getCurrent() || !this.queue.isEmpty()) return;
this.queue.add(track);
this.playNext().catch(e => logger.error("[Player] Radio reconnect playNext error:", e.message));
}, 3_000).unref?.();
},
/**
* @private Clear the track-end timer.
* @this {import('./Player.mjs').Player}
+31 -11
View File
@@ -148,6 +148,7 @@ const SearchMixin = {
videoId: info.identifier ?? "",
encoded: track.encoded ?? info.encoded ?? "",
sourceName: info.sourceName ?? "unknown",
isLive: info.isLive === true,
title: Utils.cleanTitle(info.title ?? "Unknown"),
url: trackUri,
thumbnail: info.artworkUrl ?? null,
@@ -292,20 +293,36 @@ const SearchMixin = {
}
if (lcTracks.length === 0) {
if (!isUrl && source !== "ytmsearch") {
events.emit("message", "No results from primary source, trying YouTube Music...");
const fallback = await this._lavalink.search(searchQuery, { source: "ytmsearch" });
if (fallback?.tracks?.length > 0) {
const video = this._lcTrackToVideo(fallback.tracks[0], trackMeta);
if (video) {
this.addToQueue(video, top);
events.emit("message", "Successfully added [" + video.title + "](" + video.url + ") to the queue.");
if (!this.queue.getCurrent()) {
this.playNext().catch(e => logger.error("[Player] playNext error:", e.message));
if (!isUrl) {
const FALLBACKS = [
{ source: "ytmsearch", label: "YouTube Music" },
{ source: "ytsearch", label: "YouTube" },
{ source: "scsearch", label: "SoundCloud" },
].filter(f => f.source !== source);
for (const fb of FALLBACKS) {
events.emit("message", "No results yet — trying **" + fb.label + "**...");
let fbResult = null;
try {
fbResult = await this._lavalink.search(searchQuery, { source: fb.source });
} catch (_) { fbResult = null; }
if (fbResult?.tracks?.length > 0) {
const video = this._lcTrackToVideo(fbResult.tracks[0], trackMeta);
if (video) {
this.addToQueue(video, top);
events.emit("message", "Successfully added [" + video.title + "](" + video.url + ") to the queue. *(found on " + fb.label + ")*");
if (!this.queue.getCurrent()) {
this.playNext().catch(e => logger.error("[Player] playNext error:", e.message));
}
return;
}
return;
}
}
} else {
const lavasrcHost = /(?:open\.spotify\.com|spotify\.link|music\.apple\.com|tidal\.com|deezer\.com|deezer\.page\.link|music\.youtube\.com\/playlist)/i;
try { if (lavasrcHost.test(new URL(query.trim()).hostname)) {
events.emit("message", "⚠️ This link needs the **LavaSrc plugin** on the audio node, which isn't available. Try the song/playlist **name** instead — e.g. `%play <name>`.");
} } catch (_) {}
}
events.emit("message", "**No results found for '" + query + "'.**");
return;
@@ -328,6 +345,9 @@ const SearchMixin = {
if (video) {
this.addToQueue(video, top);
events.emit("message", "Successfully added [" + video.title + "](" + video.url + ") to the queue.");
if (playlistQuery) {
events.emit("message", "⚠️ Couldn't load the full playlist — added just this video.");
}
} else {
events.emit("message", "**Failed to parse track data.**");
return;