2020-07-24 20:31:52 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
|
|
|
|
|
|
|
class SnipeCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'snipe',
|
|
|
|
module: 'moderation',
|
|
|
|
usage: "[channel]",
|
2020-07-24 20:49:32 +02:00
|
|
|
memberPermissions: ['MANAGE_MESSAGES'],
|
2020-07-24 20:31:52 +02:00
|
|
|
examples: [
|
|
|
|
"#general"
|
|
|
|
],
|
|
|
|
guildOnly: true,
|
|
|
|
throttling: {
|
|
|
|
usages: 2,
|
|
|
|
duration: 5
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
this._messageCache = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-03 10:32:34 +02:00
|
|
|
async execute(message, { params }) {
|
2020-07-24 20:31:52 +02:00
|
|
|
|
|
|
|
let channel = await this.client.resolver.resolveChannel(params.join(' '), true, message.guild, (channel) => channel.type === 'text');
|
|
|
|
if(!channel) channel = message.channel; //eslint-disable-line prefer-destructuring
|
|
|
|
|
|
|
|
const filter = this.messageCache.messages.filter((m) => {
|
|
|
|
return m.channel === channel.id
|
|
|
|
&& m.deleted;
|
|
|
|
}).sort((a, b) => b.timestamp-a.timestamp);
|
|
|
|
|
|
|
|
const first = filter.first();
|
|
|
|
if(!first) {
|
2020-07-25 08:02:22 +02:00
|
|
|
message.respond("There are no snipes in this channel.", { emoji: 'failure' });
|
2020-07-24 20:31:52 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:22 +02:00
|
|
|
const member = await this.client.resolver.resolveMember(first.author, true, message.guild);
|
|
|
|
|
|
|
|
const embed = {
|
|
|
|
author: {
|
|
|
|
name: `${member.displayName} said...`,
|
|
|
|
icon_url: member.user.displayAvatarURL() //eslint-disable-line camelcase
|
|
|
|
},
|
|
|
|
description: first.content,
|
|
|
|
footer: {
|
|
|
|
text: `Message has been sniped by ${message.author.tag}`
|
|
|
|
},
|
|
|
|
timestamp: first.timestamp
|
|
|
|
};
|
|
|
|
|
|
|
|
message.embed(embed);
|
2020-07-24 20:31:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
get messageCache() {
|
|
|
|
if(!this._messageCache) this._messageCache = this.client.registry.components.get('observer:messageCache');
|
|
|
|
return this._messageCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SnipeCommand;
|