limitedResponse

This commit is contained in:
Erik 2020-06-20 00:03:09 +03:00
parent 771f7c6875
commit 57fe0be1c8

View File

@ -1,7 +1,6 @@
const { Structures } = require('discord.js'); const { Structures } = require('discord.js');
const escapeRegex = require('escape-string-regexp'); const escapeRegex = require('escape-string-regexp');
const emojis = require('../../util/emojis.json');
const { Util, Emojis } = require('../../util/'); const { Util, Emojis } = require('../../util/');
const { stripIndents } = require('common-tags') const { stripIndents } = require('common-tags')
@ -88,7 +87,7 @@ const Message = Structures.extend('Message', (Message) => {
if(typeof str === 'string') { if(typeof str === 'string') {
if(opts.emoji) { if(opts.emoji) {
const emoji = emojis[opts.emoji]; const emoji = Emojis[opts.emoji];
if(!emoji) this.command.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`); if(!emoji) this.command.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`);
str = `${emoji} ${str}`; str = `${emoji} ${str}`;
} }
@ -101,10 +100,25 @@ const Message = Structures.extend('Message', (Message) => {
} }
async limitedRespond(str, opts = { attachments: [] }) {
if(typeof str === 'string') {
if(opts.emoji) {
const emoji = Emojis[opts.emoji];
if(!emoji) this.client.logger.warn(`Invalid emoji provided to command ${this.command.resolveable}: "${opts.emoji}".`);
str = `${emoji} ${str}`;
}
if(opts.reply) str = `<@!${this.author.id}> ${str}`;
}
return this.client.rateLimiter.limitSend(this.channel, str, opts.limit, opts.utility);
}
async edit(str, opts) { async edit(str, opts) {
if(!this.editable) return null; if(!this.editable) return null;
if(typeof str === 'string') { if(typeof str === 'string') {
if(opts.emoji) str = `${emojis[opts.emoji]} ${str}`; if(opts.emoji) str = `${Emojis[opts.emoji]} ${str}`;
if(opts.reply) str = `<@!${this.author.id}> ${str}`; if(opts.reply) str = `<@!${this.author.id}> ${str}`;
} }
return super.edit(str); return super.edit(str);
@ -112,7 +126,7 @@ const Message = Structures.extend('Message', (Message) => {
async prompt(str, opts) { async prompt(str, opts) {
if(typeof str === 'string') { if(typeof str === 'string') {
if(opts.emoji) str = `${emojis[opts.emoji]} ${str}`; if(opts.emoji) str = `${Emojis[opts.emoji]} ${str}`;
if(opts.reply) str = `<@!${this.author.id}> ${str}`; if(opts.reply) str = `<@!${this.author.id}> ${str}`;
} }
await this.channel.send(str); await this.channel.send(str);