mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
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:
1 parent
7c5fb1e468
commit
a0d6f32ea8
8 files changed
+49
-12
No files matched your search
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
import { Utils } from "../../src/utils/Utils.mjs";
|
import { Utils } from "../../src/utils/Utils.mjs";
|
||||||
import { EmbedBuilder } from "@fluxerjs/core";
|
import { EmbedBuilder } from "@fluxerjs/core";
|
||||||
import { getGlobalColor } from "../../src/ui/index.mjs";
|
|
||||||
import { STATES, PROGRESS } from "./consts.mjs";
|
import { STATES, PROGRESS } from "./consts.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +29,7 @@ export function buildPlayerEmbed(bot, msg, player, timeout, state = {}) {
|
|||||||
if (current?.duration && player.startedPlaying) {
|
if (current?.duration && player.startedPlaying) {
|
||||||
const elapsed = Date.now() - player.startedPlaying;
|
const elapsed = Date.now() - player.startedPlaying;
|
||||||
const totalMs = typeof current.duration === "object"
|
const totalMs = typeof current.duration === "object"
|
||||||
? (current.duration.seconds ?? 0) * 1000
|
? (current.duration?.seconds ?? 0) * 1000
|
||||||
: current.duration;
|
: current.duration;
|
||||||
|
|
||||||
const bar = Utils.progressBar(elapsed, totalMs, 20, PROGRESS.filled, PROGRESS.empty, isPlaying ? PROGRESS.indicator : PROGRESS.filled);
|
const bar = Utils.progressBar(elapsed, totalMs, 20, PROGRESS.filled, PROGRESS.empty, isPlaying ? PROGRESS.indicator : PROGRESS.filled);
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ const Serializers = {
|
|||||||
if (!vid) return null;
|
if (!vid) return null;
|
||||||
const durationMs =
|
const durationMs =
|
||||||
typeof vid.duration === "number" ? vid.duration :
|
typeof vid.duration === "number" ? vid.duration :
|
||||||
typeof vid.duration === "object" && vid.duration?.seconds !== null ? vid.duration.seconds * 1000 :
|
(vid.duration?.seconds != null ? vid.duration.seconds * 1000 : 0);
|
||||||
0;
|
|
||||||
return {
|
return {
|
||||||
title: vid.title,
|
title: vid.title,
|
||||||
url: vid.type === "radio" ? vid.author?.url : vid.url,
|
url: vid.type === "radio" ? vid.author?.url : vid.url,
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ const PlayerEventsMixin = {
|
|||||||
const durationMs = (() => {
|
const durationMs = (() => {
|
||||||
const d = song.duration;
|
const d = song.duration;
|
||||||
if (!d) return null;
|
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;
|
if (typeof d === "number") return d;
|
||||||
return null;
|
return null;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const PlaybackMixin = {
|
|||||||
if (track?.info?.length) return track.info.length;
|
if (track?.info?.length) return track.info.length;
|
||||||
if (track?.info?.duration != null) {
|
if (track?.info?.duration != null) {
|
||||||
if (typeof track.info.duration === "number") return track.info.duration;
|
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 track.info.duration.seconds * 1000;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ const SearchMixin = {
|
|||||||
if (ms === 0 && info.duration != null) {
|
if (ms === 0 && info.duration != null) {
|
||||||
if (typeof info.duration === "number") {
|
if (typeof info.duration === "number") {
|
||||||
ms = info.duration;
|
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;
|
ms = info.duration.seconds * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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. */
|
/** @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) {
|
_extractDurationSec(track) {
|
||||||
if (!track.duration) return "";
|
if (!track?.duration) return "";
|
||||||
if (typeof track.duration === "object" && track.duration.seconds) return track.duration.seconds;
|
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 === "number") return Math.round(track.duration / 1000);
|
||||||
if (typeof track.duration === "string") {
|
if (typeof track.duration === "string") {
|
||||||
const m = track.duration.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/);
|
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.
|
* @returns {boolean} True if the track meets the scrobble threshold.
|
||||||
*/
|
*/
|
||||||
shouldScrobble(track, playedMs) {
|
shouldScrobble(track, playedMs) {
|
||||||
const durationMs = typeof track.duration === "object" && track.duration.seconds
|
const durationMs = track?.duration?.seconds != null
|
||||||
? track.duration.seconds * 1000
|
? track.duration.seconds * 1000
|
||||||
: typeof track.duration === "number"
|
: typeof track?.duration === "number"
|
||||||
? track.duration
|
? track.duration
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|||||||
@@ -398,6 +398,19 @@ export class MessageHandler {
|
|||||||
try {
|
try {
|
||||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||||
} catch (err) {
|
} 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) {
|
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}`);
|
logger.warn(`[MessageHandler] Cannot reply in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||||
return null;
|
return null;
|
||||||
@@ -420,6 +433,19 @@ export class MessageHandler {
|
|||||||
try {
|
try {
|
||||||
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
||||||
} catch (err) {
|
} 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) {
|
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}`);
|
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||||
return null;
|
return null;
|
||||||
@@ -442,6 +468,19 @@ export class MessageHandler {
|
|||||||
try {
|
try {
|
||||||
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
||||||
} catch (err) {
|
} 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) {
|
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}`);
|
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+1
-1
@@ -372,7 +372,7 @@ export class Utils {
|
|||||||
if (includeDuration && track.duration) {
|
if (includeDuration && track.duration) {
|
||||||
const duration = typeof track.duration === "number"
|
const duration = typeof track.duration === "number"
|
||||||
? this.prettifyMS(track.duration)
|
? this.prettifyMS(track.duration)
|
||||||
: track.duration.timestamp || track.duration.seconds
|
: (track.duration?.timestamp || track.duration?.seconds)
|
||||||
? this.formatSeconds(track.duration.seconds)
|
? this.formatSeconds(track.duration.seconds)
|
||||||
: "?:??";
|
: "?:??";
|
||||||
return `${title} - ${author} [${duration}]`;
|
return `${title} - ${author} [${duration}]`;
|
||||||
|
|||||||
Reference in new issue
Block a user