fix(ui,music): handle deleted message replies and safe null duration during restore

- Fall back to channel send when replyingTo message was deleted (UNKNOWN_MESSAGE 404)
- Safely handle null duration in dashboard convertVideo and player embed during session restore
- Protect lastfm scrobbler and search mixins from null duration properties
This commit is contained in:
NoLogicAlan committed 2026-10-30 00:30:37 +03:00
1 parent 7c5fb1e468
commit a0d6f32ea8
8 files changed
+49 -12

No files matched your search

+1 -2
View File
@@ -58,8 +58,7 @@ const Serializers = {
if (!vid) return null;
const durationMs =
typeof vid.duration === "number" ? vid.duration :
typeof vid.duration === "object" && vid.duration?.seconds !== null ? vid.duration.seconds * 1000 :
0;
(vid.duration?.seconds != null ? vid.duration.seconds * 1000 : 0);
return {
title: vid.title,
url: vid.type === "radio" ? vid.author?.url : vid.url,
+1 -1
View File
@@ -268,7 +268,7 @@ const PlayerEventsMixin = {
const durationMs = (() => {
const d = song.duration;
if (!d) return null;
if (typeof d === "object" && d.seconds) return d.seconds * 1000;
if (typeof d === "object" && d?.seconds) return d.seconds * 1000;
if (typeof d === "number") return d;
return null;
})();
+1 -1
View File
@@ -69,7 +69,7 @@ const PlaybackMixin = {
if (track?.info?.length) return track.info.length;
if (track?.info?.duration != null) {
if (typeof track.info.duration === "number") return track.info.duration;
if (typeof track.info.duration === "object" && track.info.duration.seconds != null)
if (typeof track.info.duration === "object" && track.info.duration?.seconds != null)
return track.info.duration.seconds * 1000;
}
return 0;
+1 -1
View File
@@ -306,7 +306,7 @@ const SearchMixin = {
if (ms === 0 && info.duration != null) {
if (typeof info.duration === "number") {
ms = info.duration;
} else if (typeof info.duration === "object" && info.duration.seconds != null) {
} else if (typeof info.duration === "object" && info.duration?.seconds != null) {
ms = info.duration.seconds * 1000;
}
}
+4 -4
View File
@@ -243,8 +243,8 @@ export class LastFmManager {
/** @private Extract the duration in seconds from a track object, supporting number (ms), object with .seconds, ISO 8601, or plain seconds. @param {object} track - Track object. @returns {string|number} Duration in seconds, or empty string if unavailable. */
_extractDurationSec(track) {
if (!track.duration) return "";
if (typeof track.duration === "object" && track.duration.seconds) return track.duration.seconds;
if (!track?.duration) return "";
if (typeof track.duration === "object" && track.duration?.seconds) return track.duration.seconds;
if (typeof track.duration === "number") return Math.round(track.duration / 1000);
if (typeof track.duration === "string") {
const m = track.duration.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/);
@@ -260,9 +260,9 @@ export class LastFmManager {
* @returns {boolean} True if the track meets the scrobble threshold.
*/
shouldScrobble(track, playedMs) {
const durationMs = typeof track.duration === "object" && track.duration.seconds
const durationMs = track?.duration?.seconds != null
? track.duration.seconds * 1000
: typeof track.duration === "number"
: typeof track?.duration === "number"
? track.duration
: null;
+39
View File
@@ -398,6 +398,19 @@ export class MessageHandler {
try {
return new Message(await replyingTo.reply(opts, { ping: false }), this);
} catch (err) {
if (err.code === ErrorCodes.MessageNotFound || err.code === "UNKNOWN_MESSAGE" || err.statusCode === 404 || String(err?.message ?? "").includes("Message wasn't found")) {
/* Referenced message was deleted before reply arrived — fall back to channel send */
try {
const ch = replyingTo.channel ?? (typeof this.getChannel === "function" ? this.getChannel(replyingTo.channelId) : null);
if (ch && typeof ch.send === "function") {
return new Message(await ch.send(opts), this);
}
} catch (fallbackErr) {
logger.warn(`[MessageHandler] Fallback channel send failed in ${replyingTo.channelId ?? replyingTo.channel?.id}: ${fallbackErr.code ?? fallbackErr.message}`);
return null;
}
return null;
}
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
logger.warn(`[MessageHandler] Cannot reply in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
return null;
@@ -420,6 +433,19 @@ export class MessageHandler {
try {
return new Message(await replyingTo.reply(message, { ping: false }), this);
} catch (err) {
if (err.code === ErrorCodes.MessageNotFound || err.code === "UNKNOWN_MESSAGE" || err.statusCode === 404 || String(err?.message ?? "").includes("Message wasn't found")) {
/* Referenced message was deleted before reply arrived — fall back to channel send */
try {
const ch = replyingTo.channel ?? (typeof this.getChannel === "function" ? this.getChannel(replyingTo.channelId) : null);
if (ch && typeof ch.send === "function") {
return new Message(await ch.send(message), this);
}
} catch (fallbackErr) {
logger.warn(`[MessageHandler] Fallback channel send failed in ${replyingTo.channelId ?? replyingTo.channel?.id}: ${fallbackErr.code ?? fallbackErr.message}`);
return null;
}
return null;
}
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
return null;
@@ -442,6 +468,19 @@ export class MessageHandler {
try {
return new Message(await replyingTo.reply(payload, { ping: false }), this);
} catch (err) {
if (err.code === ErrorCodes.MessageNotFound || err.code === "UNKNOWN_MESSAGE" || err.statusCode === 404 || String(err?.message ?? "").includes("Message wasn't found")) {
/* Referenced message was deleted before reply arrived — fall back to channel send */
try {
const ch = replyingTo.channel ?? (typeof this.getChannel === "function" ? this.getChannel(replyingTo.channelId) : null);
if (ch && typeof ch.send === "function") {
return new Message(await ch.send(payload), this);
}
} catch (fallbackErr) {
logger.warn(`[MessageHandler] Fallback channel send failed in ${replyingTo.channelId ?? replyingTo.channel?.id}: ${fallbackErr.code ?? fallbackErr.message}`);
return null;
}
return null;
}
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
return null;
+1 -1
View File
@@ -372,7 +372,7 @@ export class Utils {
if (includeDuration && track.duration) {
const duration = typeof track.duration === "number"
? this.prettifyMS(track.duration)
: track.duration.timestamp || track.duration.seconds
: (track.duration?.timestamp || track.duration?.seconds)
? this.formatSeconds(track.duration.seconds)
: "?:??";
return `${title} - ${author} [${duration}]`;