CleanupMessages: Handle missing permissions for local testing

This commit is contained in:
2026-01-17 18:15:06 +01:00
parent 00210a03cf
commit 333f3d94bf

View File

@@ -13,8 +13,8 @@ module.exports = {
{ channelId: '1101703550070947920', keepTimeMinutes: 2880, keepAttachment: true }, //cotr/Memes { channelId: '1101703550070947920', keepTimeMinutes: 2880, keepAttachment: true }, //cotr/Memes
]; ];
function isMessageLocked(message) { function isMessageLocked(message) {
for(const [id, reaction] of message.reactions.cache) { for (const [id, reaction] of message.reactions.cache) {
if(id === keepMessageEmoteId) { if (id === keepMessageEmoteId) {
return true; return true;
} }
} }
@@ -22,26 +22,28 @@ module.exports = {
return false; return false;
} }
for (let i = 0; i < channelConfigs.length; i++) { for (let i = 0; i < channelConfigs.length; i++) {
try {
const config = channelConfigs[i]; const config = channelConfigs[i];
const channel = await client.channels.fetch(config.channelId); const channel = await client.channels.fetch(config.channelId);
console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`);
channel.messages.fetch({ limit: 100 }).then(messages => { channel.messages.fetch({ limit: 100 }).then(messages => {
messages.forEach(message => { messages.forEach(message => {
if(isMessageLocked(message)) { if (isMessageLocked(message)) {
//skip if message has mnzboKeepMessage reaction //skip if message has mnzboKeepMessage reaction
console.log(`[LOCKED] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); console.log(`[LOCKED] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`);
return; return;
} }
if(message.attachments.size > 0 && config.keepAttachment) { if (message.attachments.size > 0 && config.keepAttachment) {
//Skip messages with attachment //Skip messages with attachment
return; return;
} }
let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60);
if(ageInMinutes < config.keepTimeMinutes) { if (ageInMinutes < config.keepTimeMinutes) {
//Skip messages posted within last 48 Hours //Skip messages posted within last 48 Hours
return; return;
} }
@@ -50,6 +52,9 @@ module.exports = {
message.delete(); message.delete();
}); });
}); });
} catch (error) {
console.log(`[CLEANUP] Failed for ${channelConfigs[i].channelId}`);
}
} }
}, },
}; };