diff --git a/timers/cleanupMessages-MVM.js b/timers/cleanupMessages-MVM.js deleted file mode 100644 index 08d7169..0000000 --- a/timers/cleanupMessages-MVM.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - timeout: 60000, - immediate: true, - name: 'Cleanup tasks', - async tick(client, timer) { - const channelId = '1101703550070947920'; - const channel = await client.channels.fetch(channelId); - - console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); - channel.messages.fetch({ limit: 100 }).then(messages => { - //Iterate through the messages here with the variable "messages". - messages.forEach(message => { - if(message.attachments.size > 0) { - //Skip messages with attachment - return; - } - - let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); - if(ageInMinutes < 2880) { - //Skip messages posted within last 48 Hours - return; - } - - console.log(`[CLEANUP] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); - message.delete(); - }); - }); - }, -}; \ No newline at end of file diff --git a/timers/cleanupMessages-RP.js b/timers/cleanupMessages-RP.js deleted file mode 100644 index fa1c00f..0000000 --- a/timers/cleanupMessages-RP.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - timeout: 60000, - immediate: true, - name: 'Cleanup tasks', - async tick(client, timer) { - const channelId = '1170190197384814762'; - const channel = await client.channels.fetch(channelId); - - console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); - channel.messages.fetch({ limit: 100 }).then(messages => { - //Iterate through the messages here with the variable "messages". - messages.forEach(message => { - if(message.attachments.size > 0) { - //Skip messages with attachment - return; - } - - let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); - if(ageInMinutes < 2880) { - //Skip messages posted within last 48 Hours - return; - } - - console.log(`[CLEANUP] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); - message.delete(); - }); - }); - }, -}; \ No newline at end of file diff --git a/timers/cleanupMessages-Spam.js b/timers/cleanupMessages-Spam.js deleted file mode 100644 index 27ffbd3..0000000 --- a/timers/cleanupMessages-Spam.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - timeout: 60000, - immediate: true, - name: 'Cleanup tasks', - async tick(client, timer) { - const channelId = '1111054421091155978'; - const channel = await client.channels.fetch(channelId); - - console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); - channel.messages.fetch({ limit: 100 }).then(messages => { - //Iterate through the messages here with the variable "messages". - messages.forEach(message => { - let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); - if(ageInMinutes < 2880) { - //Skip messages posted within last 48 Hours - return; - } - - console.log(`[CLEANUP] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); - message.delete(); - }); - }); - }, -}; \ No newline at end of file diff --git a/timers/cleanupMessages.js b/timers/cleanupMessages.js new file mode 100644 index 0000000..e9c2a95 --- /dev/null +++ b/timers/cleanupMessages.js @@ -0,0 +1,55 @@ +const { MessageActivityType } = require("discord.js"); + +module.exports = { + timeout: 60000, + immediate: true, + name: 'Cleanup tasks', + async tick(client, timer) { + const keepMessageEmoteId = '1214140438265724980'; + const channelConfigs = [ + { channelId: '1214134516247957504', keepTimeMinutes: 2, keepAttachment: true }, //toho-test/mnzbot-test + { channelId: '1111054421091155978', keepTimeMinutes: 2880 }, //cotr/Spam + { channelId: '1170190197384814762', keepTimeMinutes: 2880, keepAttachment: true }, //cotr/Red + { channelId: '1101703550070947920', keepTimeMinutes: 2880, keepAttachment: true }, //cotr/Memes + ]; + function isMessageLocked(message) { + for(const [id, reaction] of message.reactions.cache) { + if(id === keepMessageEmoteId) { + return true; + } + } + + return false; + } + + for (let i = 0; i < channelConfigs.length; i++) { + const config = channelConfigs[i]; + const channel = await client.channels.fetch(config.channelId); + + console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); + channel.messages.fetch({ limit: 100 }).then(messages => { + messages.forEach(message => { + if(isMessageLocked(message)) { + //skip if message has mnzboKeepMessage reaction + console.log(`[LOCKED] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); + return; + } + + if(message.attachments.size > 0 && config.keepAttachment) { + //Skip messages with attachment + return; + } + + let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); + if(ageInMinutes < config.keepTimeMinutes) { + //Skip messages posted within last 48 Hours + return; + } + + console.log(`[CLEANUP] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); + message.delete(); + }); + }); + } + }, +}; \ No newline at end of file