prune debugging

This commit is contained in:
Erik 2022-09-16 18:05:25 +03:00
parent 617576d72e
commit 3b67b4b227
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -40,17 +40,21 @@ class PruneInfraction extends Infraction {
// +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');
this.client.logger.debug(`Pruning ${messages.size} in ${this.guild.name}`);
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);
this.client.logger.debug(`Has old: ${hasOld}, has undeletable: ${hasUndeletable}`);
messages = messages.filter((m) => m.deletable && m.type !== MessageType.ChatInputCommand);
if (messages.size === 0) return this._fail('C_PRUNE_NOTDELETABLE');
const filtered = await this.filterMessages(messages);
this.client.logger.debug(`After filter: ${filtered.size}, pre filter: ${messages.size}`);
if (filtered.size === 0) return this._fail('C_PRUNE_NOFILTERRESULTS');
const deleted = await this.deleteMessages(filtered);
this.client.logger.debug(`Deleted ${deleted} messages`);
if (deleted === 0) return this._fail('C_PRUNE_NODELETE');
await this.handle();
@ -68,7 +72,7 @@ class PruneInfraction extends Infraction {
const bulkDelete = async (messages) => {
try {
const deleteThese = messages.splice(0, 100);
const result = await this.target.bulkDelete(deleteThese, true); //Filtering old just incase, d.js uses Snowflake times instead of our Client's timestamp.
const result = await this.channel.bulkDelete(deleteThese, true); //Filtering old just incase, d.js uses Snowflake times instead of our Client's timestamp.
if (result && result.size > 0) amount += result.size;
} catch (error) {
this.client.logger.error(error.stack);