From 08e5d363fc1c03e57a5c4fa3e97bd36c6666974c Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Thu, 22 Oct 2026 01:04:14 +0300 Subject: [PATCH] fix(player, ui, voice): resolve seek 0 validation, help paginator reset, and voice retry backoff (#22) --- commands/search.mjs | 2 ++ commands/seek.mjs | 6 ++-- src/ui/Paginators.mjs | 45 ++++++++++++++--------------- src/voice/gateway/RejoinManager.mjs | 12 +++++--- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/commands/search.mjs b/commands/search.mjs index 3b8faa2..1eabd94 100644 --- a/commands/search.mjs +++ b/commands/search.mjs @@ -143,6 +143,7 @@ export async function run(msg, data) { await clearReactions(); if (e.emoji_id === CANCEL_EMOJI) { + p.searches.delete(msg.authorId); rawMsg.edit({ embeds: [makeEmbed(this.t(msg, "responses.search.cancelled"), null, this.t(msg, "responses.search.resultsTitle", { provider: name }))] }).catch(() => {}); @@ -167,6 +168,7 @@ export async function run(msg, data) { const SESSION_MS = this.config?.timers?.searchSessionTimeout ?? 30_000; const timer = setTimeout(() => { unobserve(); + p.searches.delete(msg.authorId); clearReactions().catch(() => {}); rawMsg.edit({ embeds: [makeEmbed(this.t(msg, "responses.search.timedOut"), this.t(msg, "responses.search.sessionClosed"), this.t(msg, "responses.search.resultsTitle", { provider: name }))] diff --git a/commands/seek.mjs b/commands/seek.mjs index 0008f15..ccbd798 100644 --- a/commands/seek.mjs +++ b/commands/seek.mjs @@ -48,8 +48,10 @@ export async function run(msg, data) { return msg.reply({ embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription(this.t(msg, "responses.seek.live"))] }); } - let seekMs = Utils.parseDuration(positionInput); - if (!seekMs || seekMs < 0) { + const trimmed = String(positionInput ?? "").trim(); + const isZero = /^0+(:0+)?(:0+)?$/.test(trimmed); + const seekMs = isZero ? 0 : Utils.parseDuration(trimmed); + if (seekMs === null || isNaN(seekMs) || seekMs < 0 || (!isZero && seekMs === 0)) { return msg.reply({ embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription(this.t(msg, "responses.seek.invalidFormat"))] }); } diff --git a/src/ui/Paginators.mjs b/src/ui/Paginators.mjs index 2f1a52b..6d1b56a 100644 --- a/src/ui/Paginators.mjs +++ b/src/ui/Paginators.mjs @@ -222,25 +222,7 @@ export class RichPaginator { const next = this._next; const buildEmbed = this._buildEmbed.bind(this); - const unobserve = wrapped.onReaction(allReactions, async (e) => { - const emoji = e.emoji_id; - - if (emoji === prev || emoji === next) { - const tab = tabs[state.tab]; - const totalPages = Math.max(1, tab.pages.length); - if (totalPages <= 1) return; - state.page = emoji === prev - ? (state.page - 1 + totalPages) % totalPages - : (state.page + 1) % totalPages; - } else { - const idx = tabEmojis.indexOf(emoji); - if (idx === -1 || idx === state.tab) return; - state.tab = idx; - state.page = 0; - } - - rawMsg.edit({ embeds: [buildEmbed(state.tab, state.page)] }).catch(() => {}); - }); + let unobserve = () => {}; /** @private Clear all reactions on the paginator message. */ const clearReactions = async () => { @@ -279,11 +261,26 @@ export class RichPaginator { timer = setTimeout(closeSession, this._timeout); }; - const origHandler = wrapped.handler.observedReactions.get(rawMsg.id); - if (origHandler) { - const origCb = origHandler.cb; - origHandler.cb = (e, m) => { resetTimer(); origCb(e, m); }; - } + unobserve = wrapped.onReaction(allReactions, async (e) => { + resetTimer(); + const emoji = e.emoji_id; + + if (emoji === prev || emoji === next) { + const tab = tabs[state.tab]; + const totalPages = Math.max(1, tab.pages.length); + if (totalPages <= 1) return; + state.page = emoji === prev + ? (state.page - 1 + totalPages) % totalPages + : (state.page + 1) % totalPages; + } else { + const idx = tabEmojis.indexOf(emoji); + if (idx === -1 || idx === state.tab) return; + state.tab = idx; + state.page = 0; + } + + rawMsg.edit({ embeds: [buildEmbed(state.tab, state.page)] }).catch(() => {}); + }); return rawMsg; } diff --git a/src/voice/gateway/RejoinManager.mjs b/src/voice/gateway/RejoinManager.mjs index 4fda2a9..3c21acd 100644 --- a/src/voice/gateway/RejoinManager.mjs +++ b/src/voice/gateway/RejoinManager.mjs @@ -41,15 +41,19 @@ const RejoinManager = { return player; } catch (err) { const errMsg = err?.message ?? String(err); - const isTrackTimeout = errMsg.includes("track publication timed out") + const isTransientError = errMsg.includes("track publication timed out") + || errMsg.includes("Voice connection timeout") + || errMsg.includes("LiveKit connection timeout") || errMsg.includes("lavalink player create failed") || errMsg.includes("Failed to create audio player") - || errMsg.includes("internal error"); + || errMsg.includes("internal error") + || errMsg.includes("ETIMEDOUT") + || errMsg.includes("ECONNRESET"); - if (isTrackTimeout && attempt < maxRetries) { + if (isTransientError && attempt < maxRetries) { const backoffMs = baseDelay * Math.pow(2, attempt - 1); logger.warn( - `[${context}] Track publication failed for channel ${channelId} (attempt ${attempt}/${maxRetries}) — ` + + `[${context}] Voice connection/track failed for channel ${channelId} (attempt ${attempt}/${maxRetries}) — ` + `retrying in ${backoffMs / 1000}s: ${errMsg}` ); await new Promise(resolve => setTimeout(resolve, backoffMs));