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:
NoLogicAlan committed 2026-05-06 01:07:03 +03:00
1 parent 1ff1f9d78f
commit 6060e6d318
36 files changed
+2752 -689

No files matched your search

+30 -11
View File
@@ -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 })));
}
}
}