mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
- Add Locale class (src/constants/Locale.mjs) with per-guild translation
support and settings-manager binding
- Wire locale into CommandHandler, MessageHandler, Player, PlayerManager,
and index.mjs via setLocale() / t() helpers
- Replace all hardcoded English strings (help pages, errors, now-playing,
permission messages, session-closed footers) with locale key lookups
- Fix: %help triggering "Unknown command" — replyHandler intercept now
uses case-insensitive check for "unknown command"
- Fix: TypeError crash in closeSession when embed has no footer — guard
with `if (!footer) footer = { text: "" }` before appending
- Fix: media player teardown now calls destroy() and nulls the instance
instead of relying on _stopMediaPlayer(), preventing stale state
- Refactor: reply() and send() auto-wrap plain strings in embeds,
matching old replyEmbed/sendEmbed behaviour
- Refactor: permission errors and invalid-flag errors use t() lookups
- Add top-level t(message, key, data) helper on the bot instance for
command files to resolve guild locale without manual guildId plumbing
115 lines
3.7 KiB
JavaScript
115 lines
3.7 KiB
JavaScript
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
|
import { EmbedBuilder } from "@fluxerjs/core";
|
|
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
|
|
|
export const command = new CommandBuilder()
|
|
.setName("servers")
|
|
.setDescription("Fetch a list of servers the bot is in")
|
|
.setRequirement(r => r.setOwnerOnly(true))
|
|
.setCategory("util");
|
|
|
|
// Auto-remove timer: 1 minute
|
|
const EMOJI_REMOVE_TIMEOUT = 60000;
|
|
|
|
export async function run(msg) {
|
|
const guilds = [...this.client.guilds.values()];
|
|
|
|
// Fallback if the bot is in 0 servers
|
|
if (guilds.length === 0) {
|
|
const emptyEmbed = new EmbedBuilder()
|
|
.setColor(getGlobalColor())
|
|
.setTitle(this.t(msg, "responses.servers.title", { count: 0 }))
|
|
.setDescription(this.t(msg, "responses.servers.noServers"))
|
|
;
|
|
return msg.reply({ embeds: [emptyEmbed] });
|
|
}
|
|
|
|
const itemsPerPage = 50;
|
|
const totalPages = Math.ceil(guilds.length / itemsPerPage);
|
|
const pages = [];
|
|
|
|
// Build the content for each page
|
|
for (let i = 0; i < guilds.length; i += itemsPerPage) {
|
|
const chunk = guilds.slice(i, i + itemsPerPage);
|
|
const list = chunk.map((g, index) => `${i + index + 1}. **${g.name}** (\`${g.id}\`)`).join("\n");
|
|
pages.push(list);
|
|
}
|
|
|
|
let currentPage = 0;
|
|
|
|
// Helper function to generate the embed for a specific page
|
|
const buildPageContent = (pageIdx, expired = false) => {
|
|
const embed = new EmbedBuilder()
|
|
.setColor(getGlobalColor())
|
|
.setTitle(this.t(msg, "responses.servers.pageTitle", { count: guilds.length, page: pageIdx + 1, total: totalPages }))
|
|
.setDescription(pages[pageIdx])
|
|
.setFooter({
|
|
text: expired
|
|
? this.t(msg, "responses._common.controlsExpired")
|
|
: totalPages > 1
|
|
? this.t(msg, "responses._common.navigateHint")
|
|
: this.t(msg, "responses.servers.listComplete")
|
|
})
|
|
;
|
|
|
|
return { embeds: [embed] };
|
|
};
|
|
|
|
// Send the initial message using the framework's wrapper
|
|
const replyMsg = await msg.reply(buildPageContent(0));
|
|
|
|
// Safety check and single-page exit
|
|
if (!replyMsg?.message) return;
|
|
if (totalPages <= 1) return;
|
|
|
|
const navEmojis = ["⬅️", "➡️"];
|
|
let unobserve = null;
|
|
let emojiTimeout = null;
|
|
|
|
// Add reactions
|
|
for (const emoji of navEmojis) {
|
|
await replyMsg.message.react(emoji).catch(() => {});
|
|
}
|
|
|
|
// Helper: Clear all reactions (matches player.mjs fallback logic)
|
|
const clearReactions = async () => {
|
|
try {
|
|
await replyMsg.message.removeAllReactions();
|
|
} catch (e) {
|
|
for (const emoji of navEmojis) {
|
|
try {
|
|
await replyMsg.message.removeReaction(emoji);
|
|
} catch (_) {}
|
|
}
|
|
}
|
|
};
|
|
|
|
// Helper: Reset the expiration timer
|
|
const resetTimer = () => {
|
|
clearTimeout(emojiTimeout);
|
|
emojiTimeout = setTimeout(async () => {
|
|
if (unobserve) unobserve();
|
|
await clearReactions();
|
|
await replyMsg.edit(buildPageContent(currentPage, true)).catch(() => {});
|
|
}, EMOJI_REMOVE_TIMEOUT);
|
|
};
|
|
|
|
// Start listening for reactions using the framework's native listener
|
|
unobserve = replyMsg.onReaction(navEmojis, async (e) => {
|
|
resetTimer(); // Reset the 1-minute timer when interacting
|
|
|
|
if (e.emoji_id === "⬅️") {
|
|
// Go backward (loops to the end if on the first page)
|
|
currentPage = currentPage > 0 ? currentPage - 1 : totalPages - 1;
|
|
} else if (e.emoji_id === "➡️") {
|
|
// Go forward (loops to the beginning if on the last page)
|
|
currentPage = currentPage < totalPages - 1 ? currentPage + 1 : 0;
|
|
}
|
|
|
|
// Update the embed using the framework's native edit method
|
|
await replyMsg.edit(buildPageContent(currentPage)).catch(() => {});
|
|
});
|
|
|
|
// Start the initial countdown
|
|
resetTimer();
|
|
} |