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

55 lines
1.5 KiB
JavaScript

const { Command } = require('../../../../interfaces/');
class SnipeCommand extends Command {
constructor(client) {
super(client, {
name: 'snipe',
module: 'moderation',
usage: "[channel]",
memberPermissions: ['KICK_MEMBERS'],
examples: [
"#general"
],
guildOnly: true,
throttling: {
usages: 2,
duration: 5
}
});
this.client = client;
this._messageCache = null;
}
async execute(message, { params, args }) {
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) {
message.respond("Could not find deleted message.", { emoji: 'failure' });
return undefined;
}
message.respond(first.content, { emoji: 'success' });
}
get messageCache() {
if(!this._messageCache) this._messageCache = this.client.registry.components.get('observer:messageCache');
return this._messageCache;
}
}
module.exports = SnipeCommand;