galactic-bot/structure/client/components/commands/moderation/Snipe.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

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'],
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
&& 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' });
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);
}
get messageCache() {
if(!this._messageCache) this._messageCache = this.client.registry.components.get('observer:messageCache');
return this._messageCache;
}
}
module.exports = SnipeCommand;