tweak to prune

This commit is contained in:
Erik 2022-07-18 11:23:53 +03:00
parent dc176fca50
commit f48ba2ea61
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 9 additions and 12 deletions

View File

@ -36,13 +36,14 @@ class PruneInfraction extends Infraction {
async execute() {
const { amount, message } = this.data;
let messages = await this.fetchMessages(message, amount); //Collection, not array.
// +1 to so we can avoid deleting the command interaction
let messages = await this.fetchMessages(message, amount < 100 ? amount + 1 : amount); //Collection, not array.
if (messages.size === 0) return this._fail('C_PRUNE_NOTFETCHED');
const hasOld = messages.some((m) => m.createdTimestamp >= Date.now() + 1209600000); //I hope Node.js can handle these large of numbers.. e_e (2 weeks)
const hasUndeletable = messages.some((m) => m.deletable);
messages = messages.filter((m) => m.deletable);
messages = messages.filter((m) => m.deletable && m.type !== 'APPLICATION_COMMAND');
if (messages.size === 0) return this._fail('C_PRUNE_NOTDELETABLE');
const filtered = await this.filterMessages(messages);

View File

@ -164,18 +164,14 @@ class CommandHandler extends Observer {
if (response instanceof Message) return;
try { // Temporary -- trying to figure out why the bot sometimes errors with unknown interaction
if (response) {
if (response instanceof MessageEmbed) return invoker.reply({ embeds: [response] });
else if (typeof response === 'string') return invoker.reply({ content: response });
else if (typeof response === 'object') return invoker.reply(response);
}
if (!invoker.replied) return invoker.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !invoker.replied });
} catch (err) {
this.logger.error(`Error responding to ${invoker.command.name}:\n${err.stack}`);
if (response) {
if (response instanceof MessageEmbed) return invoker.reply({ embeds: [response] });
else if (typeof response === 'string') return invoker.reply({ content: response });
else if (typeof response === 'object') return invoker.reply(response);
}
if (!invoker.replied) return invoker.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !invoker.replied });
}
async _parseInteraction(interaction, command) {