format and embed methods

This commit is contained in:
Erik 2020-04-19 22:55:26 +03:00
parent b393478796
commit 6fe39f2bfa

View File

@ -1,5 +1,6 @@
const { Structures } = require('discord.js'); const { Structures } = require('discord.js');
const escapeRegex = require('escape-string-regexp');
const emojis = require('../../util/emojis.json'); const emojis = require('../../util/emojis.json');
const Message = Structures.extend('Message', (Message) => { const Message = Structures.extend('Message', (Message) => {
@ -18,6 +19,20 @@ const Message = Structures.extend('Message', (Message) => {
} }
format(index, parameters = {}) {
let language = this.author._settings.locale || 'en_us';
if(this.guild && this.guild._settings.locale) language = this.guild._settings.locale;
let template = this.client.localeLoader.template(language, index); //.languages[language][index];
for (const [param, val] of Object.entries(parameters)) {
template = template.replace(new RegExp(`{${escapeRegex(param.toLowerCase())}}`, 'gi'), val);
}
return template;
}
async resolve() { async resolve() {
try { try {
@ -33,6 +48,14 @@ const Message = Structures.extend('Message', (Message) => {
} }
async embed(embed, opts = {}) {
let send = { content: opts.reply ? `<@${this.author.id}>` : '', embed };
this._pending = await this.channel.send(send);
return this._pending;
}
async respond(str, opts = {}) { async respond(str, opts = {}) {
if(typeof str === 'string') { if(typeof str === 'string') {