From 5a2cf70479b3768729a3ae2ec95a5d819b900e3c Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 12 Jan 2022 23:41:20 +0200 Subject: [PATCH] locale/formatting stuff --- src/structure/client/wrappers/GuildWrapper.js | 4 ++++ .../client/wrappers/InteractionWrapper.js | 20 +++++++++++++++---- .../components/observers/CommandHandler.js | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index f63bc25..bddb0b8 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -40,6 +40,10 @@ class GuildWrapper { return JSON.parse(JSON.stringify(this.client.defaultConfig())); } + get locale() { + return this._settings?.locale || 'en_us'; + } + // Logging _storageLog(log) { diff --git a/src/structure/client/wrappers/InteractionWrapper.js b/src/structure/client/wrappers/InteractionWrapper.js index 7c9a7ac..b1b1c66 100644 --- a/src/structure/client/wrappers/InteractionWrapper.js +++ b/src/structure/client/wrappers/InteractionWrapper.js @@ -23,23 +23,35 @@ class InteractionWrapper { async reply(options = {}) { if (options.emoji) this.emojify(options); - + if (options.template) { + const { template } = options; + options.content = this.format(template.index, template.params, template.opts); + } this._pending = await this.interaction.reply(options); return this._pending; + } async editReply(options = {}) { if (options.emoji) this.emojify(options); + if (options.template) { + const { template } = options; + options.content = this.format(template.index, template.params, template.opts); + } this._pending = await this.interaction.editReply(options); return this._pending; } - format(locale, parameters = {}, code = false) { - const language = 'en_us'; //Default language. + format(index, parameters = {}, opts = {}) { + const { + code = false, + language = this.user.locale || this.guild?.locale || 'en_us' + } = opts; + //const language = this.guild?.locale || 'en_us'; //Default to en_us //TODO: Fetch guild/user settings and switch localization. - return this.client.localeLoader.format(language, locale, parameters, code); + return this.client.localeLoader.format(language, index, parameters, code); } get channel() { diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 56373d8..42cbb2e 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -87,7 +87,7 @@ class CommandHandler extends Observer { const { command, interaction } = thing; if(!interaction.guild && command.guildOnly) { - return thing.reply({ locale: 'O_COMMANDHANDLER_GUILDONLY', emoji: 'failure', ephemeral: true }); + return thing.reply({ template: { index: 'O_COMMANDHANDLER_GUILDONLY' }, emoji: 'failure', ephemeral: true }); } let error = null;