locale/formatting stuff

This commit is contained in:
Erik 2022-01-12 23:41:20 +02:00
parent e5cc109895
commit 5a2cf70479
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589
3 changed files with 21 additions and 5 deletions

View File

@ -40,6 +40,10 @@ class GuildWrapper {
return JSON.parse(JSON.stringify(this.client.defaultConfig())); return JSON.parse(JSON.stringify(this.client.defaultConfig()));
} }
get locale() {
return this._settings?.locale || 'en_us';
}
// Logging // Logging
_storageLog(log) { _storageLog(log) {

View File

@ -23,23 +23,35 @@ class InteractionWrapper {
async reply(options = {}) { async reply(options = {}) {
if (options.emoji) this.emojify(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); this._pending = await this.interaction.reply(options);
return this._pending; return this._pending;
} }
async editReply(options = {}) { async editReply(options = {}) {
if (options.emoji) this.emojify(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); this._pending = await this.interaction.editReply(options);
return this._pending; return this._pending;
} }
format(locale, parameters = {}, code = false) { format(index, parameters = {}, opts = {}) {
const language = 'en_us'; //Default language. 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. //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() { get channel() {

View File

@ -87,7 +87,7 @@ class CommandHandler extends Observer {
const { command, interaction } = thing; const { command, interaction } = thing;
if(!interaction.guild && command.guildOnly) { 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; let error = null;