Consolidate cleanup tasks
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
55
timers/cleanupMessages.js
Normal file
55
timers/cleanupMessages.js
Normal file
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user