68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class SnipeCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'snipe',
|
|
module: 'moderation',
|
|
usage: "[channel]",
|
|
memberPermissions: ['MANAGE_MESSAGES'],
|
|
examples: [
|
|
"#general"
|
|
],
|
|
guildOnly: true,
|
|
throttling: {
|
|
usages: 2,
|
|
duration: 5
|
|
}
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
this._messageCache = null;
|
|
|
|
}
|
|
|
|
async execute(message, { params }) {
|
|
|
|
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;
|
|
}).sort((a, b) => b.timestamp-a.timestamp);
|
|
|
|
const first = filter.first();
|
|
if(!first) {
|
|
message.respond("There are no snipes in this channel.", { emoji: 'failure' });
|
|
return undefined;
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
get messageCache() {
|
|
if(!this._messageCache) this._messageCache = this.client.registry.components.get('observer:messageCache');
|
|
return this._messageCache;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = SnipeCommand; |