2020-04-08 18:08:46 +02:00
|
|
|
const { Structures } = require('discord.js');
|
|
|
|
|
2020-04-16 14:37:04 +02:00
|
|
|
const emojis = require('../../util/emojis.json');
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
const Message = Structures.extend('Message', (Message) => {
|
|
|
|
|
|
|
|
class ExtendedMessage extends Message {
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this.command = null; //Will set to command if the message induces a command.
|
2020-04-16 14:37:04 +02:00
|
|
|
this.args = null;
|
|
|
|
this.parameters = null;
|
|
|
|
|
|
|
|
this._pending = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async resolve() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
const resolved = this.command.execute(this, {
|
|
|
|
params: this.parameters,
|
|
|
|
args: this.args
|
|
|
|
});
|
|
|
|
if(resolved instanceof Promise) await resolved;
|
|
|
|
return { error: false };
|
|
|
|
} catch(error) {
|
|
|
|
return { error: true, message: error };
|
|
|
|
}
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-16 14:37:04 +02:00
|
|
|
async respond(str, opts = {}) {
|
|
|
|
|
|
|
|
if(typeof str === 'string') {
|
|
|
|
if(opts.emoji) {
|
|
|
|
const emoji = emojis[opts.emoji];
|
|
|
|
if(!emoji) this.command.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`);
|
|
|
|
str = `${emoji} ${str}`;
|
|
|
|
}
|
|
|
|
if(opts.reply) str = `<@!${this.author.id}> ${str}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._pending = await this.channel.send(str);
|
|
|
|
return this._pending;
|
|
|
|
|
|
|
|
}
|
2020-04-09 23:08:28 +02:00
|
|
|
|
2020-04-16 14:37:04 +02:00
|
|
|
async edit(str, opts) {
|
|
|
|
if(!this.editable) return null;
|
|
|
|
if(typeof str === 'string') {
|
|
|
|
if(opts.emoji) str = `${emojis[opts.emoji]} ${str}`;
|
|
|
|
if(opts.reply) str = `<@!${this.author.id}> ${str}`;
|
|
|
|
}
|
|
|
|
return super.edit(str);
|
2020-04-09 23:08:28 +02:00
|
|
|
}
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ExtendedMessage;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Message;
|