mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
paginated to debug.mjs
This commit is contained in:
1 parent
3f5c395986
commit
c8a6469025
5 files changed
+239
-50
No files matched your search
+152
-7
@@ -2,6 +2,8 @@ import { CommandBuilder } from "../src/CommandHandler.mjs";
|
|||||||
import { EmbedBuilder } from "@fluxerjs/core";
|
import { EmbedBuilder } from "@fluxerjs/core";
|
||||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||||
|
|
||||||
|
const EMOJI_REMOVE_TIMEOUT = 60_000;
|
||||||
|
|
||||||
export const command = new CommandBuilder()
|
export const command = new CommandBuilder()
|
||||||
.setName("debug")
|
.setName("debug")
|
||||||
.setDescription("A debug command for various purposes.")
|
.setDescription("A debug command for various purposes.")
|
||||||
@@ -13,7 +15,7 @@ export const command = new CommandBuilder()
|
|||||||
.addChoices("voice")
|
.addChoices("voice")
|
||||||
.setRequired(true));
|
.setRequired(true));
|
||||||
|
|
||||||
export function run(msg, data) {
|
export async function run(msg, data) {
|
||||||
switch (data.get("target").value) {
|
switch (data.get("target").value) {
|
||||||
case "voice": {
|
case "voice": {
|
||||||
const servers = [...this.players.playerMap.entries()].map(([cid, s]) => {
|
const servers = [...this.players.playerMap.entries()].map(([cid, s]) => {
|
||||||
@@ -47,12 +49,155 @@ export function run(msg, data) {
|
|||||||
pendingJoins: pending.length,
|
pendingJoins: pending.length,
|
||||||
pendingChannels: pending,
|
pendingChannels: pending,
|
||||||
};
|
};
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setColor(getGlobalColor())
|
const MAX_DESC = 4096;
|
||||||
.setTitle(this.t(msg, "responses.debug.voiceTitle"))
|
const CODE_WRAP = 12; // "```json\n" (8) + "\n```" (4)
|
||||||
.setDescription("```json\n" + JSON.stringify({ summary, servers }, null, 2) + "\n```")
|
|
||||||
;
|
// ── Build pages ────────────────────────────────────────────────────────
|
||||||
msg.reply({ embeds: [embed] });
|
// Page 0: summary + compact server list
|
||||||
|
// Page 1..N: detailed JSON for each server (one per page, or grouped if small)
|
||||||
|
const pages = [];
|
||||||
|
|
||||||
|
// Page 0 — Summary
|
||||||
|
const summaryLines = [
|
||||||
|
`📊 **Summary**`,
|
||||||
|
`Players in map: **${summary.playerMapSize}**`,
|
||||||
|
`Live players: **${summary.livePlayers}**`,
|
||||||
|
`Pending joins: **${summary.pendingJoins}**${summary.pendingChannels.length ? ` (\`${summary.pendingChannels.join("`, `")}\`)` : ""}`,
|
||||||
|
``,
|
||||||
|
`**Players:**`,
|
||||||
|
];
|
||||||
|
for (let i = 0; i < servers.length; i++) {
|
||||||
|
const s = servers[i];
|
||||||
|
const status = s.conn === "yes" && !s.destroyed && !s.leaving ? "🟢" : "🔴";
|
||||||
|
const line = `${status} \`${s.guildname}\` / \`#${s.name}\` — conn:${s.conn} room:${s.roomState} media:${s.mediaPlayer}`;
|
||||||
|
// Guard against overflow even for the summary
|
||||||
|
if (summaryLines.join("\n").length + line.length + 1 > MAX_DESC - 30) {
|
||||||
|
summaryLines.push(`… and ${servers.length - i} more (see next pages)`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
summaryLines.push(line);
|
||||||
|
}
|
||||||
|
pages.push(summaryLines.join("\n"));
|
||||||
|
|
||||||
|
// Pages 1..N — Detailed JSON per-server (group small ones together)
|
||||||
|
{
|
||||||
|
let groupJson = "";
|
||||||
|
let groupStart = 0;
|
||||||
|
|
||||||
|
const flushGroup = () => {
|
||||||
|
if (!groupJson) return;
|
||||||
|
const codeBlock = "```json\n" + groupJson + "\n```";
|
||||||
|
pages.push(codeBlock.slice(0, MAX_DESC));
|
||||||
|
groupJson = "";
|
||||||
|
groupStart = i; // will be set by outer loop
|
||||||
|
};
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
for (i = 0; i < servers.length; i++) {
|
||||||
|
const singleJson = JSON.stringify(servers[i], null, 2);
|
||||||
|
const candidate = groupJson
|
||||||
|
? groupJson.slice(0, -1) + ",\n" + singleJson.slice(1) // merge objects into array-like
|
||||||
|
: singleJson;
|
||||||
|
|
||||||
|
if (("```json\n" + candidate + "\n```").length > MAX_DESC && groupJson) {
|
||||||
|
// Current group is full — flush it, start new group with this server
|
||||||
|
pages.push(("```json\n" + groupJson + "\n```").slice(0, MAX_DESC));
|
||||||
|
groupJson = singleJson;
|
||||||
|
} else if (("```json\n" + candidate + "\n```").length > MAX_DESC) {
|
||||||
|
// Even a single server is too big — truncate it
|
||||||
|
const budget = MAX_DESC - CODE_WRAP;
|
||||||
|
groupJson = singleJson.slice(0, budget);
|
||||||
|
pages.push(("```json\n" + groupJson + "\n```").slice(0, MAX_DESC));
|
||||||
|
groupJson = "";
|
||||||
|
} else {
|
||||||
|
groupJson = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (groupJson) {
|
||||||
|
pages.push(("```json\n" + groupJson + "\n```").slice(0, MAX_DESC));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Single page — no pagination needed ────────────────────────────────
|
||||||
|
if (pages.length === 1) {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(getGlobalColor())
|
||||||
|
.setTitle(this.t(msg, "responses.debug.voiceTitle"))
|
||||||
|
.setDescription(pages[0].slice(0, MAX_DESC))
|
||||||
|
;
|
||||||
|
return msg.reply({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Multi-page with reactions ─────────────────────────────────────────
|
||||||
|
const totalPages = pages.length;
|
||||||
|
let currentPage = 0;
|
||||||
|
|
||||||
|
const buildPage = (pageIdx, expired = false) => {
|
||||||
|
const pageLabel = pageIdx === 0
|
||||||
|
? "Summary"
|
||||||
|
: `Player Detail${pages[pageIdx].includes(",") ? "s" : ""}`;
|
||||||
|
const footerText = expired
|
||||||
|
? "Controls expired"
|
||||||
|
: `Page ${pageIdx + 1}/${totalPages} • Use ⬅️➡️ to navigate`;
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(getGlobalColor())
|
||||||
|
.setTitle(this.t(msg, "responses.debug.voiceTitle") + ` — ${pageLabel}`)
|
||||||
|
.setDescription(pages[pageIdx].slice(0, MAX_DESC))
|
||||||
|
.setFooter({ text: footerText })
|
||||||
|
;
|
||||||
|
return { embeds: [embed] };
|
||||||
|
};
|
||||||
|
|
||||||
|
const replyMsg = await msg.reply(buildPage(0));
|
||||||
|
if (!replyMsg?.message) return;
|
||||||
|
|
||||||
|
const navEmojis = ["⬅️", "➡️", "❌"];
|
||||||
|
for (const emoji of navEmojis) {
|
||||||
|
await replyMsg.message.react(emoji).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearReactions = async () => {
|
||||||
|
try {
|
||||||
|
await replyMsg.message.removeAllReactions();
|
||||||
|
} catch {
|
||||||
|
for (const emoji of navEmojis) {
|
||||||
|
try { await replyMsg.message.removeReaction(emoji); } catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let emojiTimeout;
|
||||||
|
const resetTimer = () => {
|
||||||
|
clearTimeout(emojiTimeout);
|
||||||
|
emojiTimeout = setTimeout(async () => {
|
||||||
|
unobserve?.();
|
||||||
|
await clearReactions();
|
||||||
|
await replyMsg.edit(buildPage(currentPage, true)).catch(() => {});
|
||||||
|
}, EMOJI_REMOVE_TIMEOUT);
|
||||||
|
};
|
||||||
|
|
||||||
|
const unobserve = replyMsg.onReaction(navEmojis, async (e) => {
|
||||||
|
if (e.emoji_id === "❌") {
|
||||||
|
clearTimeout(emojiTimeout);
|
||||||
|
unobserve?.();
|
||||||
|
await replyMsg.message.delete().catch(() => {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resetTimer();
|
||||||
|
|
||||||
|
if (e.emoji_id === "⬅️") {
|
||||||
|
currentPage = currentPage > 0 ? currentPage - 1 : totalPages - 1;
|
||||||
|
} else if (e.emoji_id === "➡️") {
|
||||||
|
currentPage = currentPage < totalPages - 1 ? currentPage + 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
await replyMsg.edit(buildPage(currentPage)).catch(() => {});
|
||||||
|
});
|
||||||
|
|
||||||
|
resetTimer();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -152,7 +152,7 @@ export async function run(msg, data) {
|
|||||||
// Embed description includes the metadata and the codeblock
|
// Embed description includes the metadata and the codeblock
|
||||||
const typeLabel = this.t(msg, "responses.eval.typeLabel");
|
const typeLabel = this.t(msg, "responses.eval.typeLabel");
|
||||||
const timeLabel = this.t(msg, "responses.eval.timeLabel");
|
const timeLabel = this.t(msg, "responses.eval.timeLabel");
|
||||||
const desc = `**${typeLabel}** \`${type}\` • **${timeLabel}** \`${elapsed}ms\`\n\`\`\`js\n${chunks[pageIdx]}\n\`\`\``;
|
const desc = `**${typeLabel}** \`${type}\` • **${timeLabel}** \`${elapsed}ms\`\n\`\`\`js\n${chunks[pageIdx]}\n\`\`\``.slice(0, 4096);
|
||||||
|
|
||||||
// Customize footer based on state
|
// Customize footer based on state
|
||||||
let footerText = this.t(msg, "responses.eval.pageLabel", { page: pageIdx + 1, total: totalPages });
|
let footerText = this.t(msg, "responses.eval.pageLabel", { page: pageIdx + 1, total: totalPages });
|
||||||
|
|||||||
+58
-33
@@ -64,45 +64,74 @@ export async function run(message) {
|
|||||||
const totalLines = lines.length;
|
const totalLines = lines.length;
|
||||||
|
|
||||||
const LINES_PER_PAGE = 25;
|
const LINES_PER_PAGE = 25;
|
||||||
const totalPages = Math.ceil(totalLines / LINES_PER_PAGE);
|
const MAX_DESC = 4096;
|
||||||
|
let totalPages = Math.ceil(totalLines / LINES_PER_PAGE);
|
||||||
|
|
||||||
// Single page — no pagination needed
|
// Build page payloads — each is the raw lyric lines for that page
|
||||||
if (totalPages === 1) {
|
|
||||||
const singleEmbed = new EmbedBuilder()
|
|
||||||
.setColor(getGlobalColor())
|
|
||||||
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
|
||||||
.setDescription([
|
|
||||||
`by *${artist}*${syncIndicator}`,
|
|
||||||
``,
|
|
||||||
"```",
|
|
||||||
lines.join("\n"),
|
|
||||||
"```"
|
|
||||||
].join("\n"))
|
|
||||||
.setFooter({ text: this.t(message, "responses.lyrics.nodeLinkFooter", { lines: totalLines }) });
|
|
||||||
if (current.thumbnail) singleEmbed.setThumbnail(current.thumbnail);
|
|
||||||
return message.reply({ embeds: [singleEmbed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multi-page
|
|
||||||
const pages = [];
|
const pages = [];
|
||||||
for (let i = 0; i < totalLines; i += LINES_PER_PAGE) {
|
for (let i = 0; i < totalLines; i += LINES_PER_PAGE) {
|
||||||
pages.push(lines.slice(i, i + LINES_PER_PAGE).join("\n"));
|
pages.push(lines.slice(i, i + LINES_PER_PAGE).join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Re-check: if a page's content + header + code block exceeds 4096, re-split
|
||||||
|
// into smaller chunks so setDescription never throws RangeError. ──────────
|
||||||
|
const CODE_WRAP = 13; // "```\n" (4) + "\n```" (5) + header-ish overhead
|
||||||
|
{
|
||||||
|
const reshaped = [];
|
||||||
|
for (const pageText of pages) {
|
||||||
|
const headerLine = `by *${artist}*${syncIndicator}`;
|
||||||
|
const overhead = headerLine.length + 1 + 1 + CODE_WRAP; // header + blank + ``` + ```
|
||||||
|
const budget = MAX_DESC - overhead;
|
||||||
|
if (pageText.length <= budget) {
|
||||||
|
reshaped.push(pageText);
|
||||||
|
} else {
|
||||||
|
// Split this page's text into chunks that fit
|
||||||
|
const pageLines = pageText.split("\n");
|
||||||
|
let chunk = "";
|
||||||
|
for (const ln of pageLines) {
|
||||||
|
if (chunk.length + ln.length + 1 > budget) {
|
||||||
|
if (chunk) reshaped.push(chunk);
|
||||||
|
chunk = ln;
|
||||||
|
} else {
|
||||||
|
chunk += (chunk ? "\n" : "") + ln;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chunk) reshaped.push(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pages.length = 0;
|
||||||
|
pages.push(...reshaped);
|
||||||
|
totalPages = pages.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Single page — no pagination needed ────────────────────────────────────
|
||||||
|
if (totalPages === 1) {
|
||||||
|
const headerLine = `by *${artist}*${syncIndicator}`;
|
||||||
|
const descBody = pages[0];
|
||||||
|
const singleDesc = [headerLine, "", "```", descBody, "```"].join("\n");
|
||||||
|
|
||||||
|
const singleEmbed = new EmbedBuilder()
|
||||||
|
.setColor(getGlobalColor())
|
||||||
|
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
||||||
|
.setDescription(singleDesc.slice(0, MAX_DESC))
|
||||||
|
.setFooter({ text: this.t(message, "responses.lyrics.nodeLinkFooter", { lines: totalLines }) });
|
||||||
|
if (current.thumbnail) singleEmbed.setThumbnail(current.thumbnail);
|
||||||
|
return message.reply({ embeds: [singleEmbed] });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Multi-page ────────────────────────────────────────────────────────────
|
||||||
let currentPage = 0;
|
let currentPage = 0;
|
||||||
let emojiRemoveTimeout;
|
let emojiRemoveTimeout;
|
||||||
|
|
||||||
const buildContent = (pageIdx, expired = false) => {
|
const buildContent = (pageIdx, expired = false) => {
|
||||||
|
const headerLine = `by *${artist}*${syncIndicator} • Page ${pageIdx + 1}/${totalPages}`;
|
||||||
|
const descBody = pages[pageIdx];
|
||||||
|
const desc = [headerLine, "", "```", descBody, "```"].join("\n");
|
||||||
|
|
||||||
const b = new EmbedBuilder()
|
const b = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
||||||
.setDescription([
|
.setDescription(desc.slice(0, MAX_DESC))
|
||||||
`by *${artist}*${syncIndicator} • Page ${pageIdx + 1}/${totalPages}`,
|
|
||||||
``,
|
|
||||||
"```",
|
|
||||||
pages[pageIdx],
|
|
||||||
"```"
|
|
||||||
].join("\n"))
|
|
||||||
.setFooter({ text: expired
|
.setFooter({ text: expired
|
||||||
? this.t(message, "responses.lyrics.controlsExpired", { lines: totalLines })
|
? this.t(message, "responses.lyrics.controlsExpired", { lines: totalLines })
|
||||||
: this.t(message, "responses.lyrics.nodeLinkFooter", { lines: totalLines }) });
|
: this.t(message, "responses.lyrics.nodeLinkFooter", { lines: totalLines }) });
|
||||||
@@ -152,16 +181,12 @@ export async function run(message) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearTimeout(emojiRemoveTimeout);
|
clearTimeout(emojiRemoveTimeout);
|
||||||
unobserve();
|
unobserve();
|
||||||
|
const closedHeader = `by *${artist}*${syncIndicator} • Page ${currentPage + 1}/${totalPages}`;
|
||||||
|
const closedDesc = [closedHeader, "", "```", pages[currentPage], "```"].join("\n");
|
||||||
const closedEmbed = new EmbedBuilder()
|
const closedEmbed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
.setTitle(`🎵 ${Utils.truncate(displayTitle, 50)}`)
|
||||||
.setDescription([
|
.setDescription(closedDesc.slice(0, MAX_DESC))
|
||||||
`by *${artist}*${syncIndicator} • Page ${currentPage + 1}/${totalPages}`,
|
|
||||||
``,
|
|
||||||
"```",
|
|
||||||
pages[currentPage],
|
|
||||||
"```"
|
|
||||||
].join("\n"))
|
|
||||||
.setFooter({ text: this.t(message, "responses.lyrics.sessionClosed", { lines: totalLines }) });
|
.setFooter({ text: this.t(message, "responses.lyrics.sessionClosed", { lines: totalLines }) });
|
||||||
if (current.thumbnail) closedEmbed.setThumbnail(current.thumbnail);
|
if (current.thumbnail) closedEmbed.setThumbnail(current.thumbnail);
|
||||||
msg.edit({ embeds: [closedEmbed] }).catch(() => {});
|
msg.edit({ embeds: [closedEmbed] }).catch(() => {});
|
||||||
|
|||||||
+23
-7
@@ -24,16 +24,32 @@ export async function run(msg) {
|
|||||||
return msg.reply({ embeds: [emptyEmbed] });
|
return msg.reply({ embeds: [emptyEmbed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const itemsPerPage = 50;
|
const MAX_DESC = 4096;
|
||||||
const totalPages = Math.ceil(guilds.length / itemsPerPage);
|
|
||||||
const pages = [];
|
const pages = [];
|
||||||
|
|
||||||
// Build the content for each page
|
// Build pages dynamically — each page accumulates lines until it would
|
||||||
for (let i = 0; i < guilds.length; i += itemsPerPage) {
|
// exceed the 4096-char description limit, then starts a new page.
|
||||||
const chunk = guilds.slice(i, i + itemsPerPage);
|
let currentLines = [];
|
||||||
const list = chunk.map((g, index) => `${i + index + 1}. **${g.name}** (\`${g.id}\`)`).join("\n");
|
let currentLen = 0;
|
||||||
pages.push(list);
|
|
||||||
|
for (let i = 0; i < guilds.length; i++) {
|
||||||
|
const g = guilds[i];
|
||||||
|
let name = g.name || "unknown";
|
||||||
|
if (name.length > 40) name = name.slice(0, 37) + "...";
|
||||||
|
const line = `${i + 1}. **${name}** (\`${g.id}\`)`;
|
||||||
|
const addedLen = line.length + (currentLines.length ? 1 : 0); // +1 for \n
|
||||||
|
|
||||||
|
if (currentLen + addedLen > MAX_DESC - 20 && currentLines.length > 0) {
|
||||||
|
pages.push(currentLines.join("\n"));
|
||||||
|
currentLines = [];
|
||||||
|
currentLen = 0;
|
||||||
|
}
|
||||||
|
currentLines.push(line);
|
||||||
|
currentLen += addedLen;
|
||||||
}
|
}
|
||||||
|
if (currentLines.length) pages.push(currentLines.join("\n"));
|
||||||
|
|
||||||
|
const totalPages = pages.length;
|
||||||
|
|
||||||
let currentPage = 0;
|
let currentPage = 0;
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -51,13 +51,16 @@ export async function run(msg, data) {
|
|||||||
let desc = "";
|
let desc = "";
|
||||||
for (const [channelId, total] of channelCounts) {
|
for (const [channelId, total] of channelCounts) {
|
||||||
const name = await getChannelName(channelId);
|
const name = await getChannelName(channelId);
|
||||||
desc += this.t(msg, "responses.test.channelEntry", { name, count: total });
|
const entry = this.t(msg, "responses.test.channelEntry", { name, count: total });
|
||||||
|
// Guard against 4096-char embed description limit
|
||||||
|
if (desc.length + entry.length > 4080) break;
|
||||||
|
desc += entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setTitle(this.t(msg, "responses.test.title"))
|
.setTitle(this.t(msg, "responses.test.title"))
|
||||||
.setDescription(desc.trim())
|
.setDescription(desc.trim().slice(0, 4096))
|
||||||
;
|
;
|
||||||
msg.reply({ embeds: [embed] });
|
msg.reply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user