From ff657403bff63fb03d1dc5e44ad347a418b8aef6 Mon Sep 17 00:00:00 2001 From: Navy Date: Mon, 25 May 2020 00:43:47 +0300 Subject: [PATCH] callbacks and formatting method --- structure/extensions/Guild.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/structure/extensions/Guild.js b/structure/extensions/Guild.js index 417173a..f025111 100644 --- a/structure/extensions/Guild.js +++ b/structure/extensions/Guild.js @@ -12,6 +12,7 @@ const Guild = Structures.extend('Guild', (Guild) => { this._settings = null; //internal cache of current guild's settings; should ALWAYS stay the same as database. this._permissions = null; //internal cache, should always match database. this.premium = 0; + this.callbacks = []; } @@ -106,15 +107,32 @@ const Guild = Structures.extend('Guild', (Guild) => { /* Language Formatting */ - format(key, parameters = {}) { + format(index, parameters = {}, code = false) { - const language = this._settings.locale || 'en_us'; //this._settings.language or something idk + let language = 'en_us'; + if (this._settings.locale) language = this._settings.locale; - let value = this.client.localeLoader.languages[language][key]; - for(const [param, val] of Object.entries(parameters)) { - value = value.replace(new RegExp(`{${escapeRegex(param.toLowerCase())}}`, 'giu'), val); + parameters.prefix = this.prefix; + let template = this.client.localeLoader.template(language, index); + + if (!template) { + return `**Missing language index \`${language} [${index}]\` in languages. Contact a bot developer about this.**`; } - return value; + + for (const [param, val] of Object.entries(parameters)) { + template = template.replace(new RegExp(`{${escapeRegex(param.toLowerCase())}}`, 'giu'), val); + } + + if (code) { + try { + // eslint-disable-next-line no-eval + template = eval(template); + } catch (error) { + this.client.logger.error(`Error in locale ${language}:${index} while executing code.\n${error.stack || error}`); + } + } + + return template; }