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

+10 -10
View File
@@ -21,7 +21,7 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
if (!this.client.channels.has(cid)) {
ecb();
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("Couldn't find the channel `" + cid + "`\nUse the help command to learn more about this. (`%help join`)");
.setDescription(this.t(message, "responses.join.channelNotFound", { channel: cid }));
return message.reply({ embeds: [embed] });
}
const cleanChannelId = cleanId(cid);
@@ -30,14 +30,14 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
if (existing) {
cb(existing);
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("Already joined <#" + cid + ">.");
.setDescription(this.t(message, "responses.join.alreadyJoined", { channel: cid }));
return message.reply({ embeds: [embed] });
}
// Guard: moonlink must be ready before we can play anything
if (!this.moonlink) {
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("⚠️ Audio node is still connecting — please try again in a few seconds.");
.setDescription(this.t(message, "responses.join.audioNodeConnecting"));
ecb();
return message.reply({ embeds: [embed] });
}
@@ -68,8 +68,8 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
} 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.t(message, "responses.join.autoLeaveInactive", { channel: activeChannelId })
: this.t(message, "responses.join.autoLeaveInactive247", { channel: activeChannelId, prefix });
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription(desc);
message.channel.send({ embeds: [embed] });
@@ -91,17 +91,17 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
this.players.playerMap.set(cleanChannelId, p);
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription("⏳ Joining Channel...");
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joining"));
const statusMsg = await message.reply({ embeds: [joiningEmbed] });
try {
await p.join(cleanChannelId);
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`✅ Successfully joined <#${cid}>`);
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joined", { channel: cid }));
await statusMsg.edit({ embeds: [okEmbed] });
cb(p);
} catch (e) {
this.players.playerMap.delete(cleanChannelId);
p.destroy();
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`❌ Failed to join: ${e.message}`);
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joinFailed", { error: e.message }));
await statusMsg.edit({ embeds: [errEmbed] });
ecb(e);
}
@@ -150,7 +150,7 @@ export function run(message, data) {
if (!resolvedId) {
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("❌ Couldn't find that voice channel. Try using a mention like `<#channelid>` or the exact channel name.");
.setDescription(this.t(message, "responses.join.voiceChannelNotFound"));
return message.reply({ embeds: [embed] });
}
@@ -163,7 +163,7 @@ export function run(message, data) {
if (!cid) {
const prefix = this._commands?.getPrefix?.(getGuildId(message)) ?? "%";
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription(`❌ You're not in a voice channel. Please join one first, or specify a channel: \`${prefix}join <#channel>\``);
.setDescription(this.t(message, "responses.join.noVoiceChannel", { prefix }));
return message.reply({ embeds: [embed] });
}