mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
feat: add i18n locale system and fix pagination/help bugs
- 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
This commit is contained in:
1 parent
1ff1f9d78f
commit
6060e6d318
36 files changed
+2752
-689
No files matched your search
+32
-13
@@ -227,10 +227,8 @@ export class HelpHandler {
|
||||
commandsPerPage = 5;
|
||||
|
||||
paginationHandler = (msg, helpHandler, cmds) => {
|
||||
let form = "Available Commands (page $currentPage/$maxPage): \n\n$content";
|
||||
form += "\n\nRun `$prefix$helpCmd <command>` to learn more about it. You can also include subcommands.\n";
|
||||
form += "For example: `$prefix$helpCmd settings get`\n\n";
|
||||
form += "Tip: Use the arrows beneath this message to turn pages, or specify the required page by using `$prefix$helpCmd <page number>`";
|
||||
const guildId = msg.message.guildId;
|
||||
let form = this.commands.t(guildId, "cmdHandler.help.pageStructure");
|
||||
|
||||
const contents = cmds.map((cmd, i) => {
|
||||
return (i + 1) + ". **" + cmd.name + "**: " + (cmd.description || "").split("\n")[0];
|
||||
@@ -373,6 +371,8 @@ export class CommandHandler extends EventEmitter {
|
||||
/** @type {CommandBuilder[]} */
|
||||
commands = [];
|
||||
|
||||
/** @type {import('./constants/Locale.mjs').Locale|null} */
|
||||
locale = null;
|
||||
invalidFlagError = "Invalid flag `$invalidFlag`. It doesn't match any options on this command.\n`$previousCmd $invalidFlag`";
|
||||
textWrapError = "Malformed string `$value`: Missing a closing quote character (`$quote`) after the desired string.";
|
||||
|
||||
@@ -399,6 +399,20 @@ export class CommandHandler extends EventEmitter {
|
||||
setPingPrefix(bool) { this.pingPrefix = bool; }
|
||||
setPrefixManager(manager) { this.prefixes = manager; }
|
||||
setHelpHandler(handler) { this.helpHandler = handler; }
|
||||
/** @param {import('./constants/Locale.mjs').Locale} locale */
|
||||
setLocale(locale) { this.locale = locale; }
|
||||
|
||||
/**
|
||||
* Translate a locale key for a given guild.
|
||||
* @param {string} guildId
|
||||
* @param {string} key
|
||||
* @param {Object} [replacements={}]
|
||||
* @returns {string}
|
||||
*/
|
||||
t(guildId, key, replacements = {}) {
|
||||
if (!this.locale) return key;
|
||||
return this.locale.translate(guildId, key, replacements);
|
||||
}
|
||||
|
||||
format(text, guildId) {
|
||||
const prefix = (!guildId) ? this.prefix : this.getPrefix(guildId);
|
||||
@@ -463,12 +477,14 @@ export class CommandHandler extends EventEmitter {
|
||||
}
|
||||
if (args.length > 1 && Utils.isNumber(args[1])) {
|
||||
const pageNumber = parseInt(args[1]);
|
||||
if (pageNumber < 1 || pageNumber > this.helpHandler.pageNumber()) return this.replyHandler("`" + pageNumber + "` is not a valid page number!", msg);
|
||||
if (pageNumber < 1 || pageNumber > this.helpHandler.pageNumber()) {
|
||||
return this.replyHandler(this.t(guildId, "cmdHandler.page.invalid", { number: pageNumber }), msg);
|
||||
}
|
||||
return this.replyHandler(this.helpHandler.getHelpPage(pageNumber - 1, msg), msg);
|
||||
}
|
||||
if (args.length <= 2) {
|
||||
let idx = this.commands.findIndex(e => e.aliases.some(al => al.toLowerCase() === args[1].toLowerCase()));
|
||||
if (idx === -1) return this.replyHandler("Unknown command `$prefix" + args[1] + "`!", msg);
|
||||
if (idx === -1) return this.replyHandler(this.t(guildId, "cmdHandler.command.invalid", { command: this.format("$prefix" + args[1], guildId) }), msg);
|
||||
return this.replyHandler(this.helpHandler.getCommandHelp(this.commands[idx], msg), msg);
|
||||
}
|
||||
let currCmd = null;
|
||||
@@ -477,7 +493,7 @@ export class CommandHandler extends EventEmitter {
|
||||
let a = args.slice(1)[i];
|
||||
let curr = (currCmd) ? currCmd.subcommands : this.commands;
|
||||
let idx = curr.findIndex(e => e.aliases.some(al => al.toLowerCase() === a.toLowerCase()));
|
||||
if (idx === -1) return this.replyHandler("Unknown command `$prefix" + prefix2 + a + "`!", msg);
|
||||
if (idx === -1) return this.replyHandler(this.t(guildId, "cmdHandler.command.invalid", { command: this.format("$prefix" + prefix2 + a, guildId) }), msg);
|
||||
currCmd = curr[idx];
|
||||
prefix2 += a + " ";
|
||||
}
|
||||
@@ -485,7 +501,7 @@ export class CommandHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
if (!this.commandNames.includes(args[0].toLowerCase())) {
|
||||
this.replyHandler("Unknown Command. Use `$prefix$helpCmd` to view all possible commands.", msg);
|
||||
this.replyHandler(this.t(guildId, "cmdHandler.command.invalid", { command: this.format("$prefix$helpCmd", guildId) }), msg);
|
||||
return;
|
||||
}
|
||||
return this.processCommand(this.commands.find(e => e.aliases.includes(args[0].toLowerCase())), args, msg);
|
||||
@@ -507,7 +523,8 @@ export class CommandHandler extends EventEmitter {
|
||||
});
|
||||
if (idx === -1) {
|
||||
const list = cmd.subcommands.map(s => s.name).join(" | ");
|
||||
const e = "Invalid subcommand. Try one of the following options: `$previousCmd <$cmdlist>`".replace(/\$previousCmd/gi, previous).replace(/\$cmdList/gi, list);
|
||||
const subGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId;
|
||||
const e = this.t(subGuildId, "cmdBuilder.subcommand.invalid").replace(/\$previousCmd/gi, previous).replace(/\$cmdList/gi, list);
|
||||
return (!external) ? this.replyHandler(e, msg) : e;
|
||||
}
|
||||
return this.processCommand(cmd.subcommands[idx], args.slice(1), msg, previous + this.format(" " + cmd.subcommands[idx].name), external);
|
||||
@@ -543,7 +560,8 @@ export class CommandHandler extends EventEmitter {
|
||||
const flagName = args[argIndex].slice(1);
|
||||
const op = cmd.options.find(e => e.aliases.includes(flagName));
|
||||
if (!op) {
|
||||
const error = this.invalidFlagError.replace(/\$previousCmd/gi, previous).replace(/\$invalidFlag/gi, "-" + flagName);
|
||||
const flagGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId;
|
||||
const error = this.t(flagGuildId, "cmdHandler.invalidFlag").replace(/\$previousCmd/gi, previous).replace(/\$invalidFlag/gi, "-" + flagName);
|
||||
return (!external) ? this.replyHandler(error, msg) : error;
|
||||
}
|
||||
previous += " " + args[argIndex];
|
||||
@@ -631,6 +649,7 @@ export class CommandHandler extends EventEmitter {
|
||||
assertRequirements(cmd, msg) {
|
||||
const authorId = msg.message?.author?.id;
|
||||
const isOwner = this.owners.includes(authorId);
|
||||
const permGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId;
|
||||
|
||||
for (let i = 0; i < cmd.requirements.length; i++) {
|
||||
let req = cmd.requirements[i];
|
||||
@@ -644,7 +663,7 @@ export class CommandHandler extends EventEmitter {
|
||||
// cached — check directly
|
||||
const missing = req.permissions.filter(p => !member.permissions.has(PermissionFlags[p] ?? p));
|
||||
if (missing.length > 0) {
|
||||
this.replyHandler(req.permissionError, msg);
|
||||
this.replyHandler(this.t(permGuildId, "cmdBuilder.requirement.permission"), msg);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -659,7 +678,7 @@ export class CommandHandler extends EventEmitter {
|
||||
fetchPromise.then(member => {
|
||||
const missing = req.permissions.filter(p => !member.permissions.has(PermissionFlags[p] ?? p));
|
||||
if (missing.length > 0) {
|
||||
this.replyHandler(req.permissionError, msg);
|
||||
this.replyHandler(this.t(permGuildId, "cmdBuilder.requirement.permission"), msg);
|
||||
} else {
|
||||
// Re-parse args the same way messageHandler does so quoted args survive.
|
||||
const guildId2 = msg.channel?.channel?.guildId ?? msg.message?.guildId;
|
||||
@@ -671,7 +690,7 @@ export class CommandHandler extends EventEmitter {
|
||||
// re-entering the fetch loop if the member is still not cached.
|
||||
this.processCommand(cmd, args, msg, false, true);
|
||||
}
|
||||
}).catch(() => this.replyHandler(req.permissionError, msg));
|
||||
}).catch(() => this.replyHandler(this.t(permGuildId, "cmdBuilder.requirement.permission"), msg));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+46
-8
@@ -27,6 +27,9 @@ export class MessageHandler {
|
||||
observedReactions;
|
||||
/** @type {Map<string, string[]>} */
|
||||
observedChannels;
|
||||
/** @type {import('./constants/Locale.mjs').Locale} */
|
||||
locale;
|
||||
|
||||
/**
|
||||
* @param {Client} client
|
||||
*/
|
||||
@@ -47,6 +50,21 @@ export class MessageHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/** @param {import('./constants/Locale.mjs').Locale} locale */
|
||||
setLocale(locale) { this.locale = locale; }
|
||||
|
||||
/**
|
||||
* Translate a locale key for a given guild.
|
||||
* @param {string} guildId
|
||||
* @param {string} key
|
||||
* @param {Object} [replacements={}]
|
||||
* @returns {string}
|
||||
*/
|
||||
t(guildId, key, replacements = {}) {
|
||||
if (!this.locale) return key;
|
||||
return this.locale.translate(guildId, key, replacements);
|
||||
}
|
||||
|
||||
setupEvents() {
|
||||
const reactionUpdate = (reaction, user) => {
|
||||
// fluxerjs reaction events pass a MessageReaction and a User
|
||||
@@ -99,7 +117,7 @@ export class MessageHandler {
|
||||
try {
|
||||
const dm = await message.author.createDM();
|
||||
dm.send({
|
||||
embeds: [this.#embedify("I am unable to send messages in <#" + message.channelId + ">. Please contact a server administrator and grant me the \"SendMessages\" permission.")]
|
||||
embeds: [this.#embedify(this.t(message.guildId, "pagination.error.perms.messages", { channel: "<#" + message.channelId + ">" }))]
|
||||
});
|
||||
} catch (e) {
|
||||
logger.warn("[MessageHandler] Error sending message in DMs (" + message.author.id + "):", e.message);
|
||||
@@ -255,7 +273,13 @@ export class MessageHandler {
|
||||
*/
|
||||
async reply(replyingTo, message, mention = false) {
|
||||
if (!(await this.assertPermissions(["SendMessages"], replyingTo))) return null;
|
||||
const opts = typeof message === "string" ? { content: message } : { ...message };
|
||||
let opts;
|
||||
if (typeof message === "string") {
|
||||
// Auto-wrap plain text in an embed (matches old replyEmbed behavior)
|
||||
opts = this.#createEmbed(message, replyingTo);
|
||||
} else {
|
||||
opts = { ...message };
|
||||
}
|
||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||
}
|
||||
|
||||
@@ -297,7 +321,14 @@ export class MessageHandler {
|
||||
logger.warn("[MessageHandler] Missing SendMessages permission in channel", channel.id);
|
||||
return;
|
||||
}
|
||||
return new Message(await channel.send(typeof message === "string" ? { content: message } : message), this);
|
||||
let opts;
|
||||
if (typeof message === "string") {
|
||||
// Auto-wrap plain text in an embed (matches old sendEmbed behavior)
|
||||
opts = this.#createEmbed(message, channel);
|
||||
} else {
|
||||
opts = message;
|
||||
}
|
||||
return new Message(await channel.send(opts), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,9 +431,10 @@ export class MessageHandler {
|
||||
});
|
||||
|
||||
// Auto-close after 5 minutes
|
||||
const guildId = msg.message?.guildId ?? null;
|
||||
setTimeout(() => {
|
||||
unobserve();
|
||||
m.edit(send() + "\nSession closed - Changing pages **won't work** from here.").catch(() => {});
|
||||
m.edit(this.t(guildId, "pagination.embed.sclosedContent", { content: send() })).catch(() => {});
|
||||
}, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
@@ -768,6 +800,8 @@ export class RichPaginator {
|
||||
|
||||
if (!rawMsg) return null;
|
||||
|
||||
const guildId = (this._msg.channel?.guildId) ?? (this._msg.guildId) ?? null;
|
||||
|
||||
// Add reactions
|
||||
for (const emoji of allReactions) {
|
||||
await rawMsg.react(emoji).catch(() => {});
|
||||
@@ -820,7 +854,8 @@ export class RichPaginator {
|
||||
unobserve();
|
||||
// Update footer to show session closed
|
||||
const currentEmbed = buildEmbed(state.tab, state.page);
|
||||
currentEmbed.footer.text += " • Session closed";
|
||||
if (!currentEmbed.footer) currentEmbed.footer = { text: "" };
|
||||
currentEmbed.footer.text += " • " + this._handler.t(guildId, "pagination.embed.sclosedTitle");
|
||||
rawMsg.edit({ embeds: [currentEmbed] }).catch(() => {});
|
||||
await clearReactions();
|
||||
};
|
||||
@@ -891,6 +926,8 @@ export class QueuePaginator {
|
||||
|
||||
if (!rawMsg) return null;
|
||||
|
||||
const guildId = (this._msg.channel?.guildId) ?? (this._msg.guildId) ?? null;
|
||||
|
||||
// No arrows needed for single page
|
||||
if (totalPages <= 1) return rawMsg;
|
||||
|
||||
@@ -919,7 +956,7 @@ export class QueuePaginator {
|
||||
const closeSession = async () => {
|
||||
unobserve();
|
||||
const embed = buildEmbed(state.page);
|
||||
embed.footer.text += " • Session closed";
|
||||
embed.footer.text += " • " + this._handler.t(guildId, "pagination.embed.sclosedTitle");
|
||||
rawMsg.edit({ embeds: [embed] }).catch(() => {});
|
||||
await clearReactions();
|
||||
};
|
||||
@@ -1080,7 +1117,7 @@ export class HelpCommand {
|
||||
// that CommandHandler emits when it sees %help but can't find it.
|
||||
const _reply = this._commands.replyHandler.bind(this._commands);
|
||||
this._commands.replyHandler = (message, msg) => {
|
||||
if (typeof message === "string" && message.includes("Unknown Command")) {
|
||||
if (typeof message === "string" && message.toLowerCase().includes("unknown command")) {
|
||||
// Check if the triggering command was a help alias — if so, drop it silently
|
||||
const content = msg?.content ?? msg?.message?.content ?? "";
|
||||
const guildId = msg?.channel?.channel?.guildId ?? msg?.message?.guildId;
|
||||
@@ -1158,7 +1195,8 @@ export class HelpCommand {
|
||||
c.aliases.some(a => a.toLowerCase() === word.toLowerCase())
|
||||
);
|
||||
if (!found) {
|
||||
msg.reply(`❌ Unknown command \`${word}\`. Use \`${prefix}help\` to browse.`);
|
||||
const guildId = msg.channel?.channel?.guildId ?? msg.message?.guildId;
|
||||
msg.reply(this._commands.t(guildId, "cmdHandler.help.unknownCommand", { command: word, prefix }));
|
||||
return;
|
||||
}
|
||||
currCmd = found;
|
||||
|
||||
+30
-11
@@ -367,6 +367,7 @@ export default class Player extends EventEmitter {
|
||||
this.settings = opts.settings ?? null;
|
||||
this.settingsMgr = opts.settingsMgr ?? null;
|
||||
this._observedVoiceUsers = opts.observedVoiceUsers ?? null;
|
||||
this.locale = opts.locale ?? null;
|
||||
|
||||
// Merge NodeLink config (for stream URL building)
|
||||
this._nl = {
|
||||
@@ -1271,12 +1272,16 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
this._recoveryPending = false;
|
||||
this._isRecovering = false;
|
||||
await this._stopMediaPlayer();
|
||||
await Utils.sleep(100);
|
||||
this._streamingStopped = true;
|
||||
|
||||
if (this._mediaPlayer) {
|
||||
this._mediaPlayer.destroy();
|
||||
this._mediaPlayer = null;
|
||||
}
|
||||
await this.connection.disconnect();
|
||||
|
||||
this.queue.reset();
|
||||
this.connection = null;
|
||||
this._mediaPlayer = null;
|
||||
this._paused = false;
|
||||
this._pausedAt = null;
|
||||
this._playingNext = false;
|
||||
@@ -1779,13 +1784,22 @@ export default class Player extends EventEmitter {
|
||||
return this.getDuration(current.duration);
|
||||
}
|
||||
|
||||
/** Translate a locale key for this player's guild, with fallback. */
|
||||
_t(key, replacements = {}) {
|
||||
if (!this.locale) return key;
|
||||
return this.locale.translate(this._guildId, key, replacements);
|
||||
}
|
||||
|
||||
announceSong(s) {
|
||||
if (!s) return;
|
||||
|
||||
const inVC = this._channelId ? ` in <#${this._channelId}>` : "";
|
||||
|
||||
if (s.type === "radio") {
|
||||
this.emit("message", mkEmbed(`📻 Now streaming _${Utils.escapeMarkdown(s.title)}_ by [${s.author?.name || "Unknown"}](${s.author?.url || ""})${inVC}`))
|
||||
this.emit("message", mkEmbed(this._t("responses.radio.nowPlaying", {
|
||||
title: Utils.escapeMarkdown(s.title),
|
||||
author: s.author?.name || "Unknown",
|
||||
url: s.author?.url || "",
|
||||
channel: this._channelId || "",
|
||||
})));
|
||||
return;
|
||||
}
|
||||
const author = s.artists
|
||||
@@ -1793,7 +1807,12 @@ export default class Player extends EventEmitter {
|
||||
: s.author?.url
|
||||
? `[${s.author.name}](${s.author.url})`
|
||||
: s.author?.name || "Unknown";
|
||||
this.emit("message", mkEmbed(`🎵 Now playing [${Utils.escapeMarkdown(s.title)}](${s.spotifyUrl || s.url}) by ${author}${inVC}`))
|
||||
this.emit("message", mkEmbed(this._t("responses.play.nowPlaying", {
|
||||
title: Utils.escapeMarkdown(s.title),
|
||||
url: s.spotifyUrl || s.url,
|
||||
author: author,
|
||||
channel: this._channelId || "",
|
||||
})));
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -2027,7 +2046,7 @@ export default class Player extends EventEmitter {
|
||||
?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
this.emit("message", mkEmbed(`🎵 The queue has ended — nothing left to play. Add more songs with \`${prefix}play\`!`));
|
||||
this.emit("message", mkEmbed(this._t("responses._common.queueEnded", { prefix })));
|
||||
}
|
||||
this._wasRadio = false;
|
||||
return;
|
||||
@@ -2052,7 +2071,7 @@ export default class Player extends EventEmitter {
|
||||
const hasValidPlayer = await this._ensureMediaPlayer();
|
||||
if (!hasValidPlayer) {
|
||||
logger.error("[Player] Failed to create healthy MediaPlayer — cannot play.");
|
||||
this.emit("message", mkEmbed(":x: Voice connection lost. Please rejoin."))
|
||||
this.emit("message", mkEmbed(this._t("responses._common.voiceConnectionLost")));
|
||||
|
||||
if (!this._is247Enabled()) {
|
||||
this._startInactivityTimer();
|
||||
@@ -2111,7 +2130,7 @@ export default class Player extends EventEmitter {
|
||||
|
||||
if (!streamUrl || !Utils.isValidUrl(streamUrl)) {
|
||||
logger.error("[Player] No valid stream URL for:", songData.title);
|
||||
this.emit("message", mkEmbed(`:x: Could not get stream URL for **${songData.title}** — skipping...`))
|
||||
this.emit("message", mkEmbed(this._t("responses._common.couldNotGetStream", { title: songData.title })));
|
||||
this._streamingStopped = false;
|
||||
return this._doPlayNext();
|
||||
}
|
||||
@@ -2136,7 +2155,7 @@ export default class Player extends EventEmitter {
|
||||
this._streamingStopped = true;
|
||||
if (!this._skipping && !this.leaving && !this._paused) {
|
||||
if (songData.type !== "radio") {
|
||||
this.emit("message", mkEmbed(`:x: Error streaming **${songData.title}** — skipping...`))
|
||||
this.emit("message", mkEmbed(this._t("responses._common.errorStreaming", { title: songData.title })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
-21
@@ -66,6 +66,9 @@ export class PlayerManager {
|
||||
/** @type {Object} */
|
||||
playerConfig;
|
||||
|
||||
/** @type {import("./constants/Locale.mjs").Locale|null} */
|
||||
locale = null;
|
||||
|
||||
/** @type {import("./dashboard/Dashboard.mjs").Dashboard|null} */
|
||||
dashboard = null;
|
||||
|
||||
@@ -82,6 +85,7 @@ export class PlayerManager {
|
||||
this.config = config.config;
|
||||
this.playerConfig = config.player;
|
||||
this.dashboard = config.dashboard ?? null;
|
||||
this.locale = config.locale ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,6 +213,19 @@ export class PlayerManager {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a locale key using the message's guild locale.
|
||||
* @param {Object} message
|
||||
* @param {string} key
|
||||
* @param {Object} [replacements={}]
|
||||
* @returns {string}
|
||||
*/
|
||||
_t(message, key, replacements = {}) {
|
||||
if (!this.locale) return key;
|
||||
const guildId = getMessageGuildId(message);
|
||||
return this.locale.translate(guildId, key, replacements);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Voice Channel Detection
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -350,7 +367,7 @@ export class PlayerManager {
|
||||
first[1].textChannel = message.channel;
|
||||
return first[1];
|
||||
}
|
||||
message.reply(mkEmbed(`⚠️ You need to join a voice channel to use this command.`));
|
||||
message.reply(mkEmbed(this._t(message, "responses._common.noVoiceStrict")));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -374,7 +391,7 @@ export class PlayerManager {
|
||||
return this.settings.getServer(guildId)?.get("prefix") ?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
message.reply(mkEmbed(`⚠️ I'm already playing in ${channelList}. Join that channel or use \`${prefix}play\` to start music in your channel.`));
|
||||
message.reply(mkEmbed(this._t(message, "responses._common.alreadyInChannel", { channels: channelList, prefix })));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -383,7 +400,7 @@ export class PlayerManager {
|
||||
// Auto-detect failed — fall back to interactive channel selection prompt
|
||||
return this.promptVC(message);
|
||||
}
|
||||
message.reply(mkEmbed("⚠️ Please join a voice channel first."));
|
||||
message.reply(mkEmbed(this._t(message, "responses._common.noVoiceChannel")));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -427,13 +444,13 @@ export class PlayerManager {
|
||||
|
||||
let channelSelection = "";
|
||||
if (channelArr.length > 0) {
|
||||
channelSelection = "Please select one of the following channels by clicking on the reactions below\n\n";
|
||||
channelSelection = this._t(msg, "responses._common.voiceSelectionPrompt") + "\n\n";
|
||||
channelArr.forEach((c, i) => { channelSelection += `${i + 1}. <#${c._id ?? c.id}>\n`; });
|
||||
}
|
||||
|
||||
const hint = this._t(msg, "responses._common.voiceSelectionHint");
|
||||
const selectionMsg = await msg.reply(mkEmbed(
|
||||
(channelSelection ? channelSelection + "\n**..or**" : "Please") +
|
||||
" send a message with the voice channel! (Mention/Id/Name)\nSend 'x' to cancel."
|
||||
(channelSelection ? channelSelection + "\n**..or** " + hint : "Please " + hint)
|
||||
));
|
||||
|
||||
return new Promise(resolve => {
|
||||
@@ -447,7 +464,7 @@ export class PlayerManager {
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
cleanup();
|
||||
msg.reply(mkEmbed("⏱️ Voice selection timed out."));
|
||||
msg.reply(mkEmbed(this._t(msg, "responses._common.voiceSelectionTimedOut")));
|
||||
resolve(false);
|
||||
}, 30_000);
|
||||
|
||||
@@ -472,12 +489,12 @@ export class PlayerManager {
|
||||
if (content === "x") {
|
||||
clearTimeout(timeout);
|
||||
cleanup();
|
||||
m.reply(mkEmbed("Cancelled!"));
|
||||
m.reply(mkEmbed(this._t(m, "voice.join.cancelled")));
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
if (!this.commands.validateInput("voiceChannel", m.content, m)) {
|
||||
m.reply(mkEmbed("Invalid voice channel. Try again or type `x`."));
|
||||
m.reply(mkEmbed(this._t(m, "responses._common.voiceSelectionInvalid")));
|
||||
return;
|
||||
}
|
||||
const channel = this.commands.formatInput("voiceChannel", m.content, m);
|
||||
@@ -510,12 +527,12 @@ export class PlayerManager {
|
||||
}
|
||||
|
||||
const player = cid ? this.playerMap.get(cid) : null;
|
||||
if (!player) return msg.reply(mkEmbed("I'm not in a voice channel."));
|
||||
if (!player) return msg.reply(mkEmbed(this._t(msg, "responses._common.notInVoice")));
|
||||
|
||||
const activeChannelId = String(player._channelId ?? cid).replace(/\D/g, "") || cid;
|
||||
this.playerMap.delete(activeChannelId);
|
||||
if (activeChannelId !== cid) this.playerMap.delete(cid);
|
||||
await msg.reply(mkEmbed("✅ Successfully Left"));
|
||||
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
||||
await player.leave();
|
||||
player.destroy();
|
||||
}
|
||||
@@ -535,14 +552,14 @@ export class PlayerManager {
|
||||
|
||||
if (!channel) {
|
||||
return message.reply(mkEmbed(
|
||||
`Couldn't find the channel \`${cid}\`\nUse the help command to learn more about this.`
|
||||
this._t(message, "responses.join.channelNotFound", { channel: cid })
|
||||
));
|
||||
}
|
||||
|
||||
const isVoice = channel.type === 2;
|
||||
|
||||
if (!isVoice) {
|
||||
return message.reply(mkEmbed("❌ Please join a **voice channel** first before using this command!"));
|
||||
return message.reply(mkEmbed(this._t(message, "responses._common.voiceChannelRequired")));
|
||||
}
|
||||
|
||||
const cleanChannelId = cleanId(cid);
|
||||
@@ -551,7 +568,7 @@ export class PlayerManager {
|
||||
if (existing) {
|
||||
existing.textChannel = message.channel;
|
||||
cb(existing);
|
||||
return message.reply(mkEmbed(`Already joined <#${cid}>.`));
|
||||
return message.reply(mkEmbed(this._t(message, "responses.join.alreadyJoined", { channel: cid })));
|
||||
}
|
||||
|
||||
const player = new Player(this.config.token, {
|
||||
@@ -562,6 +579,7 @@ export class PlayerManager {
|
||||
moonlink: this.playerConfig?.moonlink ?? null,
|
||||
settingsMgr: this.settings,
|
||||
observedVoiceUsers: this.observedVoiceUsers ?? null,
|
||||
locale: this.locale ?? null,
|
||||
});
|
||||
|
||||
player.textChannel = message.channel;
|
||||
@@ -587,8 +605,8 @@ export class PlayerManager {
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
const desc = is247
|
||||
? `Left channel <#${activeChannelId}> because of inactivity.`
|
||||
: `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
|
||||
? this.locale?.translate(guildId, "responses.join.autoLeaveInactive", { channel: `<#${activeChannelId}>` }) ?? `Left channel <#${activeChannelId}> because of inactivity.`
|
||||
: this.locale?.translate(guildId, "responses.join.autoLeaveInactive247", { channel: `<#${activeChannelId}>`, prefix }) ?? `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
|
||||
ch?.send(mkEmbed(desc));
|
||||
this.playerMap.delete(activeChannelId);
|
||||
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
||||
@@ -611,10 +629,10 @@ export class PlayerManager {
|
||||
this.playerMap.set(cleanChannelId, player);
|
||||
|
||||
(async () => {
|
||||
const statusMsg = await message.reply(mkEmbed("⏳ Joining Channel..."));
|
||||
const statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining")));
|
||||
try {
|
||||
await player.join(cid);
|
||||
await statusMsg.edit(mkEmbed(`✅ Successfully joined <#${cid}>`));
|
||||
await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joined", { channel: cid })));
|
||||
|
||||
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
||||
if (guildId) {
|
||||
@@ -627,7 +645,7 @@ export class PlayerManager {
|
||||
|
||||
cb(player);
|
||||
} catch (err) {
|
||||
await statusMsg.edit(mkEmbed(`❌ Failed to join: ${err.message}`)).catch(() => {});
|
||||
await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joinFailed", { error: err.message }))).catch(() => {});
|
||||
this.playerMap.delete(cleanChannelId);
|
||||
player.destroy();
|
||||
}
|
||||
@@ -650,12 +668,12 @@ export class PlayerManager {
|
||||
? this.playerMap.get(cleanChannelId) ??
|
||||
[...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId)
|
||||
: null;
|
||||
if (!player) return msg.reply(mkEmbed("I'm not in a voice channel."));
|
||||
if (!player) return msg.reply(mkEmbed(this._t(msg, "responses._common.notInVoice")));
|
||||
|
||||
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
|
||||
this.playerMap.delete(activeChannelId);
|
||||
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
||||
await msg.reply(mkEmbed("✅ Successfully Left"));
|
||||
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
||||
await player.leave();
|
||||
player.destroy();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user