forked from Galactic/galactic-bot
callbacks and formatting method
This commit is contained in:
parent
b355cf4b69
commit
ff657403bf
@ -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._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._permissions = null; //internal cache, should always match database.
|
||||||
this.premium = 0;
|
this.premium = 0;
|
||||||
|
this.callbacks = [];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,15 +107,32 @@ const Guild = Structures.extend('Guild', (Guild) => {
|
|||||||
|
|
||||||
/* Language Formatting */
|
/* 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];
|
parameters.prefix = this.prefix;
|
||||||
for(const [param, val] of Object.entries(parameters)) {
|
let template = this.client.localeLoader.template(language, index);
|
||||||
value = value.replace(new RegExp(`{${escapeRegex(param.toLowerCase())}}`, 'giu'), val);
|
|
||||||
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user